From c10e0df57e69ff1db752fd2fb7ae69011dc1a6fa Mon Sep 17 00:00:00 2001 From: plansmash-test Date: Wed, 6 Nov 2024 17:48:09 +0000 Subject: [PATCH] refactor: consolidate GitHub Actions workflow for analytics update and deploy - Merged `update-analytics` and `deploy` jobs into a single consolidated job - Updated workflow to run on schedule, manual dispatch, or after a PR is merged to `main` - Simplified deployment logic to ensure analytics updates and deployment occur together post-merge - Adjusted conditions to prevent deployment from running on every push, relying on Netlify for PR previews --- .github/workflows/gh-pages.yml | 51 +++++++--------------------------- package.json | 2 +- 2 files changed, 11 insertions(+), 42 deletions(-) diff --git a/.github/workflows/gh-pages.yml b/.github/workflows/gh-pages.yml index a00b78bb3..adbc2284f 100644 --- a/.github/workflows/gh-pages.yml +++ b/.github/workflows/gh-pages.yml @@ -1,16 +1,17 @@ name: Deploy and Update Analytics on: - push: - branches: - - main schedule: - cron: '0 0 * * *' # Runs every day at midnight UTC workflow_dispatch: # Allows manual triggering + pull_request: + types: [closed] + branches: + - main jobs: - update-analytics: - if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' + update-analytics-and-deploy: + if: github.event_name == 'schedule' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.merged == true && github.ref == 'refs/heads/main') runs-on: ubuntu-latest environment: github-pages # Specify the environment here steps: @@ -31,46 +32,14 @@ jobs: GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }} PROPERTY_ID: ${{ secrets.PROPERTY_ID }} - deploy: - if: github.event_name == 'push' - runs-on: ubuntu-latest - environment: github-pages # Specify the environment here - steps: - - uses: actions/checkout@v4 - with: - ref: 'main' - fetch-depth: '0' - - - name: Setup Node - uses: actions/setup-node@v2.1.2 - with: - node-version: '20.x' - - - name: Reconfigure git to use HTTP authentication - run: > - git config --global url."https://github.com/".insteadOf - ssh://git@github.com/ - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: ~/.npm - key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }} - restore-keys: | - ${{ runner.os }}-node- - - - run: npm ci - - run: npm run build - env: - GOOGLE_CLIENT_ID: ${{ secrets.GOOGLE_CLIENT_ID }} - GOOGLE_CLIENT_SECRET: ${{ secrets.GOOGLE_CLIENT_SECRET }} - GOOGLE_REFRESH_TOKEN: ${{ secrets.GOOGLE_REFRESH_TOKEN }} - PROPERTY_ID: ${{ secrets.PROPERTY_ID }} + - name: Build site + run: npm run build - - name: Deploy + - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./_site user_name: 'github-actions[bot]' user_email: 'github-actions[bot]@users.noreply.github.com' + publish_branch: gh-pages diff --git a/package.json b/package.json index 3dc313223..f33d92332 100644 --- a/package.json +++ b/package.json @@ -21,7 +21,7 @@ "start-prod": "cross-env ELEVENTY_WATCH=true ELEVENTY_ENV=prod npm-run-all sass-start serve:port --parallel watch:*", "dev": "cross-env ELEVENTY_ENV=dev npm-run-all analytics sass-build --parallel eleventy", "debug": "DEBUG=Eleventy* npx @11ty/eleventy", - "build": "npm-run-all analytics sass-build eleventy" + "build": "npm-run-all sass-build eleventy" }, "repository": { "type": "git",