From e79eb9090c279e5eeb83acb40ed6b3db1d8c3ec6 Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 24 Feb 2025 16:15:00 -0600 Subject: [PATCH 1/2] Refactor the Pages workflow via reusable workflows --- .github/workflows/deploy-to-pages_job.yml | 55 ++++++++++++++++++++ .github/workflows/github-pages.yml | 61 +++++++---------------- 2 files changed, 73 insertions(+), 43 deletions(-) create mode 100644 .github/workflows/deploy-to-pages_job.yml diff --git a/.github/workflows/deploy-to-pages_job.yml b/.github/workflows/deploy-to-pages_job.yml new file mode 100644 index 000000000..d56192b65 --- /dev/null +++ b/.github/workflows/deploy-to-pages_job.yml @@ -0,0 +1,55 @@ +name: Deploy Gatsby site to Pages + +on: workflow_call + +jobs: + # Build job + build: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v4 + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version-file: '.nvmrc' + cache: yarn + - name: Setup Pages + id: pages + uses: actions/configure-pages@v5 + with: + # Automatically inject pathPrefix in your Gatsby configuration file. + # + # You may remove this line if you want to manage the configuration yourself. + static_site_generator: gatsby + - name: Restore cache + uses: actions/cache@v4 + with: + path: | + public + .cache + key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }} + restore-keys: | + ${{ runner.os }}-gatsby-build- + - name: Install dependencies + run: yarn install + - name: Build with Gatsby + env: + PREFIX_PATHS: 'true' + run: yarn run build + - name: Upload artifact + uses: actions/upload-pages-artifact@v3 + with: + path: ./public + + # Deployment job + deploy: + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + needs: build + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 051a76a7c..0f0c8ba48 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -1,45 +1,20 @@ ---- -name: Github Pages +name: Deploy Gatsby site to Pages + on: workflow_dispatch -permissions: {} -jobs: - build-and-deploy: - runs-on: ubuntu-latest - permissions: - actions: read - contents: write - steps: - - uses: actions/checkout@v4 - - name: Use Setup Node and Install Dependencies Action - uses: commerce-docs/devsite-install-action@main - with: - node-version-file: '.nvmrc' - cache-dependency-path: 'yarn.lock' - - name: Build site - run: yarn build - env: - NODE_OPTIONS: "--max-old-space-size=8192" - PREFIX_PATHS: true # works like --prefix-paths flag for 'gatsby build' - PATH_PREFIX: ${{ github.event.repository.name }} - ADOBE_LAUNCH_SRC: ${{ secrets.AIO_ADOBE_LAUNCH_SRC }} - ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT: ${{ secrets.ADOBE_LAUNCH_SRC_INCLUDE_IN_DEVELOPMENT }} - REPO_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - REPO_OWNER: ${{ github.event.repository.owner.login }} - REPO_NAME: ${{ github.event.repository.name }} - REPO_BRANCH: ${{ github.ref_name }} - GOOGLE_OAUTH_CLIENT_ID: ${{ secrets.GOOGLE_OAUTH_CLIENT_ID }} - GOOGLE_OAUTH_CLIENT_SECRET: ${{ secrets.GOOGLE_OAUTH_CLIENT_SECRET }} - GOOGLE_DOCS_TOKEN: ${{ secrets.GOOGLE_DOCS_TOKEN }} - GOOGLE_DOCS_FOLDER_ID: ${{ secrets.GOOGLE_DOCS_FOLDER_ID }} - - name: Deploy to GH Pages - uses: JamesIves/github-pages-deploy-action@v4 - with: - token: ${{ secrets.GITHUB_TOKEN }} - branch: gh-pages # The branch the action should deploy to. - folder: public # The folder the action should deploy. - clean: true # Automatically remove deleted files from deploy branch - - name: GH Pages URL - id: gh-pages-url - run: | - echo "View GH-Pages: $(https://${{ github.repository_owner }}.github.io/${{ github.event.repository.name }})" +permissions: + contents: read + pages: write + id-token: write + +concurrency: + group: "pages" + cancel-in-progress: false + +defaults: + run: + shell: bash + +jobs: + call-workflow-deploy-to-pages: + uses: AdobeDocs/commerce-php/.github/workflows/deploy-to-pages_job.yml@ds_pages From 086879086e00559b48e1e681bfdc5ec85c315c5a Mon Sep 17 00:00:00 2001 From: Dima Shevtsov Date: Mon, 24 Feb 2025 16:40:16 -0600 Subject: [PATCH 2/2] Use the main branch for the reusable workflow --- .github/workflows/github-pages.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/github-pages.yml b/.github/workflows/github-pages.yml index 0f0c8ba48..2ea6fe55b 100644 --- a/.github/workflows/github-pages.yml +++ b/.github/workflows/github-pages.yml @@ -17,4 +17,4 @@ defaults: jobs: call-workflow-deploy-to-pages: - uses: AdobeDocs/commerce-php/.github/workflows/deploy-to-pages_job.yml@ds_pages + uses: AdobeDocs/commerce-php/.github/workflows/deploy-to-pages_job.yml@main