Update cover image in a blog post #63
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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-and-commit-image: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
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: Check for changes | |
id: check_changes | |
run: | | |
git add . | |
git diff --staged --quiet || echo "CHANGES_EXIST=true" >> $GITHUB_OUTPUT | |
- name: Commit Changes | |
if: steps.check_changes.outputs.CHANGES_EXIST == 'true' | |
uses: planetscale/[email protected] | |
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-and-commit-image | |
if: failure() | |
runs-on: ubuntu-latest | |
steps: | |
- name: Report failure | |
run: | | |
echo "Failed to update cover image in blog post" | |
exit 1 |