From cd437f7c9a7ce533a8965e428f378ca75a8c8b24 Mon Sep 17 00:00:00 2001 From: Abdur-Rahman Fashola Date: Sun, 10 Mar 2024 17:55:02 +0100 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=99=20Removing=20the=20need=20for=20mu?= =?UTF-8?q?ltiple=20branches=20to=20sync=20docs?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/s3-trigger.yml | 41 +++++++++++++++++++++++++++++ .github/workflows/sync-s3-posts.yml | 11 +++++--- 2 files changed, 48 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/s3-trigger.yml diff --git a/.github/workflows/s3-trigger.yml b/.github/workflows/s3-trigger.yml new file mode 100644 index 0000000..404cc10 --- /dev/null +++ b/.github/workflows/s3-trigger.yml @@ -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\"}" diff --git a/.github/workflows/sync-s3-posts.yml b/.github/workflows/sync-s3-posts.yml index 54715be..2033bbe 100644 --- a/.github/workflows/sync-s3-posts.yml +++ b/.github/workflows/sync-s3-posts.yml @@ -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 @@ -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