Skip to content

Commit

Permalink
πŸ™ Removing the need for multiple branches to sync docs
Browse files Browse the repository at this point in the history
  • Loading branch information
ShafSpecs committed Mar 10, 2024
1 parent ba9849b commit cd437f7
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 4 deletions.
41 changes: 41 additions & 0 deletions .github/workflows/s3-trigger.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: ⏰ Delayed Trigger for S3 Sync

on:
push:
branches:
- main
paths:
- 'posts/**'

permissions: write-all

jobs:
wait-and-trigger:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
with:
ref: main
- name: πŸ”Ÿ Wait for 10 seconds
run: sleep 10

- name: πŸ”€ Check for newer commits
id: check-commits
run: |
LATEST_COMMIT=$(git log -1 --format='%H')
CURRENT_COMMIT=${{ github.sha }}
if [ "$LATEST_COMMIT" != "$CURRENT_COMMIT" ]; then
echo "Newer commit found. Stopping workflow."
echo "::set-output name=abort::true"
fi
- name: ⚑ Trigger main workflow
if: steps.check-commits.outputs.abort != 'true'
run: |
curl -L \
-X POST \
-H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
-H "Accept: application/vnd.github+json" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ github.repository }}/actions/workflows/sync-s3-posts.yml/dispatches \
-d "{\"ref\":\"main\"}"
11 changes: 7 additions & 4 deletions .github/workflows/sync-s3-posts.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
ref: main
fetch-depth: 0

- name: πŸ›‘οΈ Setup Node.js
uses: actions/setup-node@v4
Expand All @@ -29,16 +32,16 @@ jobs:
- name: 🏁 Check for changes
id: git-check
run: |
if git diff HEAD^ HEAD -- posts/; then
if [ -z "$(git diff HEAD^ HEAD -- posts/)" ]; then
echo "No changes detected."
echo "{changes}={false}" >> $GITHUB_OUTPUT
echo "changes=false" >> "$GITHUB_ENV"
else
echo "Changes detected."
echo "{changes}={true}" >> $GITHUB_OUTPUT
echo "changes=true" >> "$GITHUB_ENV"
fi
- name: πŸͺ£ Sync to S3
if: steps.git-check.outputs.changes == 'true'
if: env.changes == 'true'
uses: jakejarvis/s3-sync-action@master
with:
args: --acl public-read --follow-symlinks --delete
Expand Down

0 comments on commit cd437f7

Please sign in to comment.