Skip to content

Commit

Permalink
Pass new commit to deploy action when sync commits
Browse files Browse the repository at this point in the history
Without this, the deploy action will run with the same commit ID that started the sync action.
That results in deploying the site without the sync'd changes.
This attempts to avoid deploying when there is no new commit, and it passes the new commit to the deploy action when there is one.
  • Loading branch information
shakuzen committed Sep 18, 2023
1 parent 15ba3cd commit 9202746
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
10 changes: 10 additions & 0 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ on:
branches:
- main
workflow_call:
inputs:
new-commit:
required: false
type: string
# Review gh actions docs if you want to further define triggers, paths, etc
# https://docs.github.com/en/actions/using-workflows/workflow-syntax-for-github-actions#on

Expand All @@ -14,6 +18,12 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
if: "${{ inputs.new-commit == '' }}"
- uses: actions/checkout@v3
if: "${{ inputs.new-commit != '' }}"
with:
# deploy a specific commit
ref: ${{ inputs.new-commit }}
- uses: actions/setup-node@v3
with:
node-version: 18
Expand Down
10 changes: 9 additions & 1 deletion .github/workflows/sync-from-reddit.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ jobs:
sync-from-reddit:
name: Sync from Reddit
runs-on: ubuntu-22.04
outputs:
new-commit: ${{ steps.push.outputs.commit }}
permissions:
contents: write
steps:
Expand All @@ -24,13 +26,19 @@ jobs:
run: ./download-wiki.sh

- name: Push changes (if any)
run: git push
id: push
run: |
git push
[ "$GITHUB_SHA" != "$(git rev-parse HEAD)"] && echo "commit=$(git rev-parse HEAD)" >> "$GITHUB_OUTPUT"
# Pushes from GitHub Actions do not trigger further actions; manually call deploy
deploy:
name: Deploy site
needs: sync-from-reddit
if: "${{ needs.sync-from-reddit.outputs.new-commit != '' }}"
permissions:
pages: write
id-token: write
uses: ./.github/workflows/deploy.yml
with:
new-commit: ${{ needs.sync-from-reddit.outputs.new-commit }}

0 comments on commit 9202746

Please sign in to comment.