Skip to content

Update cover image in a blog post #31

Update cover image in a blog post

Update cover image in a blog post #31

Workflow file for this run

name: Update cover image in a blog post
on:
workflow_dispatch:
inputs:
date_slug_combo:
type: string
description: Date slug combo to use for this content build step
required: true
commit_message:
type: string
description: Commit message to use for this content build step
required: false
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
fetch-images:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Fetch image from R2
uses: cloudflare/wrangler-action@v3
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }}
command: r2 object get ${{ secrets.R2_BUCKET_NAME }}/blog/cover/${{ inputs.date_slug_combo }}/image.webp --file src/content/blog/${{ inputs.date_slug_combo }}/image.webp
- name: Upload image as artifact
uses: actions/upload-artifact@v4
with:
name: cover-image
path: src/content/blog/${{ inputs.date_slug_combo }}/image.webp
commit-changes:
needs: fetch-images
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '18'
cache: yarn
cache-dependency-path: 'yarn.lock'
- name: Install dependencies
run: yarn install --frozen-lockfile
- name: Download artifact
uses: actions/download-artifact@v4
with:
name: cover-image
path: src/content/blog/${{ inputs.date_slug_combo }}
- name: Fix Formatting
run: yarn format:write
- name: Check for changes
id: stage
run: |
git add .
git diff --staged --quiet || echo "CHANGES_EXIST=true" >> $GITHUB_OUTPUT
- name: Commit Changes
if: steps.stage.outputs.CHANGES_EXIST == 'true'
uses: planetscale/ghcommit-action@v0.1.33
with:
commit_message: ${{ github.event.inputs.commit_message || 'Update cover image in blog post' }}
repo: ${{ github.repository }}
branch: ${{ github.head_ref || github.ref_name }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
report-status:
needs: [fetch-images, commit-changes]
if: failure()
runs-on: ubuntu-latest
steps:
- name: Report failure
run: |
echo "Some MDX files are missing coverImage frontmatter and images could not be fetched"
exit 1