From c9bb522890330eda88458dd99128ff94e9019ca8 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Tue, 3 Feb 2026 20:05:31 +0100 Subject: [PATCH 1/4] chore: splits the workflows into 2 --- .github/workflows/deploy-website.yml | 97 ++++++++++++++++++++ .github/workflows/{ci-cd.yml => preview.yml} | 94 ++----------------- 2 files changed, 107 insertions(+), 84 deletions(-) create mode 100644 .github/workflows/deploy-website.yml rename .github/workflows/{ci-cd.yml => preview.yml} (52%) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml new file mode 100644 index 00000000..a3c57f8f --- /dev/null +++ b/.github/workflows/deploy-website.yml @@ -0,0 +1,97 @@ +name: Deploy Website + +on: + push: + branches: + - main + - next + - "v*" + paths-ignore: + - ".github/**" + - ".vscode/**" + # workflow_dispatch means to manual deploy production + workflow_dispatch: + # workflow_call means to deploy production from external workflow + # it would be useful to trigger from fastify main repo instead of + # daily schedule + workflow_call: + +permissions: + contents: read + +jobs: + build-and-upload: + runs-on: ubuntu-latest + permissions: + contents: read + env: + BASE_URL: "/" + steps: + - name: Checkout + uses: actions/checkout@v6 + with: + persist-credentials: false + + - name: Use Node.js + uses: actions/setup-node@v6 + with: + cache: npm + check-latest: true + node-version: 22 + node-version-file: ".nvmrc" + + - name: Install Packages + run: npm ci --ignore-scripts + + - name: Setup Pages + uses: actions/configure-pages@v5 + + - name: Get latest Fastify tag + id: latest-fastify + uses: oprypin/find-latest-tag@dd2729fe78b0bb55523ae2b2a310c6773a652bd1 # v1.1.2 + with: + repository: fastify/fastify + releases-only: true + - run: echo "Fastify is at version ${{ steps.latest-fastify.outputs.tag }}" + + - name: Cache Fastify documentation + id: release-cache + uses: actions/cache@v5 + with: + path: | + scripts/releases + scripts/releases.tag + key: ${{ steps.latest-fastify.outputs.tag }}-release-cache + + - name: Build website + run: npm run build:website + env: + GH_TOKEN: ${{ github.token }} + SKIP_DOWNLOADS: ${{ steps.release-cache.outputs.cache-hit }} + + - name: Upload artifact + uses: actions/upload-pages-artifact@v4 + with: + path: "./build" + + deploy-to-production: + needs: + - build-and-upload + concurrency: + group: main-production + cancel-in-progress: true + env: + BASE_URL: "" + permissions: + pages: write + id-token: write + environment: + name: production + url: ${{ steps.deployment.outputs.page_url }} + outputs: + deployment_url: ${{ steps.deployment.outputs.page_url }} + runs-on: ubuntu-latest + steps: + - name: Deploy to GitHub Pages + id: deployment + uses: actions/deploy-pages@v4 diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/preview.yml similarity index 52% rename from .github/workflows/ci-cd.yml rename to .github/workflows/preview.yml index e9e971b2..53e1ef3e 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/preview.yml @@ -1,79 +1,35 @@ -name: CI-CD +name: Preview on: - push: - branches: - - main - - next - - 'v*' - paths-ignore: - - '.github/**' - - '.vscode/**' # pull-request means to deploy preview + # we need to access the environment secrets pull_request_target: - # workflow_dispatch means to manual deploy production - workflow_dispatch: - # workflow_call means to deploy production from external workflow - # it would be useful to trigger from fastify main repo instead of - # daily schedule - workflow_call: permissions: contents: read jobs: - setup: - runs-on: ubuntu-latest - permissions: - contents: read - steps: - - name: Select environment - id: env-selector - run: | - echo "current_env=${{ github.event_name == 'pull_request_target' && 'staging' || 'production' }}" >> $GITHUB_OUTPUT - echo "website_url=${{ github.event_name == 'pull_request_target' && '/' || '/' }}" >> $GITHUB_OUTPUT - - name: Get latest Fastify tag - id: latest-fastify - uses: oprypin/find-latest-tag@dd2729fe78b0bb55523ae2b2a310c6773a652bd1 # v1.1.2 - with: - repository: fastify/fastify - releases-only: true - outputs: - website_url: ${{ steps.env-selector.outputs.website_url }} - current_env: ${{ steps.env-selector.outputs.current_env }} - latest_fastify: ${{ steps.latest-fastify.outputs.tag }} - build-and-upload: - needs: setup runs-on: ubuntu-latest permissions: contents: read env: - BASE_URL: ${{ needs.setup.outputs.website_url }} + BASE_URL: "/" steps: # we set the correct repository and reference sha for PR preview - name: Checkout PR - if: ${{ github.event_name == 'pull_request_target' }} uses: actions/checkout@v6 with: ref: ${{ github.event.pull_request.head.ref }} repository: ${{ github.event.pull_request.head.repo.full_name }} - # we set the correct reference sha for production - - name: Checkout - if: ${{ github.event_name != 'pull_request_target' }} - uses: actions/checkout@v6 - with: - persist-credentials: false - ref: main - - name: Use Node.js uses: actions/setup-node@v6 with: cache: npm check-latest: true node-version: 22 - node-version-file: '.nvmrc' + node-version-file: ".nvmrc" - name: Install Packages run: npm ci --ignore-scripts @@ -101,7 +57,7 @@ jobs: scripts/releases.tag key: ${{ steps.latest-fastify.outputs.tag }}-release-cache - # build website + # Here we need the token to download the `gh` archive - name: Build website run: npm run build:website env: @@ -109,53 +65,23 @@ jobs: SKIP_DOWNLOADS: ${{ steps.release-cache.outputs.cache-hit }} - name: Upload artifact - uses: actions/upload-pages-artifact@v4 with: - path: './build' - - deploy-to-production: - if: ${{ needs.setup.outputs.current_env == 'production' }} - needs: - - setup - - build-and-upload - concurrency: - group: ${{ github.ref_name }}-production - cancel-in-progress: true - env: - BASE_URL: '' - permissions: - pages: write - id-token: write - environment: - name: ${{ needs.setup.outputs.current_env }} - url: ${{ steps.deployment.outputs.page_url }} - outputs: - deployment_url: ${{ steps.deployment.outputs.page_url }} - runs-on: ubuntu-latest - steps: - - name: Deploy to GitHub Pages - id: deployment - uses: actions/deploy-pages@v4 - # with: - # enable preview when PR - # preview: ${{ github.event_name == 'pull_request_target' }} + path: "./build" deploy-to-staging: - if: ${{ needs.setup.outputs.current_env == 'staging' }} needs: - - setup - build-and-upload concurrency: group: ${{ github.ref_name }}-staging cancel-in-progress: true env: - BASE_URL: '' + BASE_URL: "" permissions: pull-requests: write contents: write environment: - name: ${{ needs.setup.outputs.current_env }} + name: staging url: ${{ steps.deployment.outputs.NETLIFY_URL }} outputs: deployment_url: ${{ steps.deployment.outputs.NETLIFY_URL }} @@ -170,12 +96,12 @@ jobs: - name: Extract artifact run: tar -xvf artifact.tar working-directory: website - shell: 'bash' + shell: "bash" - name: Clean up before deploy run: rm artifact.tar working-directory: website - shell: 'bash' + shell: "bash" - name: Display structure of downloaded files run: ls -R From bf0f27b4dfc9ce480afb2ca4356f588b13ebb3d3 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Wed, 4 Feb 2026 08:41:57 +0100 Subject: [PATCH 2/4] chore: add sandbox env --- .github/workflows/preview.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index 53e1ef3e..bb023bd8 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -13,6 +13,8 @@ jobs: runs-on: ubuntu-latest permissions: contents: read + environment: + name: sandbox env: BASE_URL: "/" steps: From 03bb85d15f90d712f59309d8b12d0cfbad1ff3ad Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Wed, 4 Feb 2026 08:44:15 +0100 Subject: [PATCH 3/4] chore: lint --- .github/workflows/deploy-website.yml | 14 +++++++------- .github/workflows/preview.yml | 12 ++++++------ 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index a3c57f8f..3ba4f3f0 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -5,10 +5,10 @@ on: branches: - main - next - - "v*" + - 'v*' paths-ignore: - - ".github/**" - - ".vscode/**" + - '.github/**' + - '.vscode/**' # workflow_dispatch means to manual deploy production workflow_dispatch: # workflow_call means to deploy production from external workflow @@ -25,7 +25,7 @@ jobs: permissions: contents: read env: - BASE_URL: "/" + BASE_URL: '/' steps: - name: Checkout uses: actions/checkout@v6 @@ -38,7 +38,7 @@ jobs: cache: npm check-latest: true node-version: 22 - node-version-file: ".nvmrc" + node-version-file: '.nvmrc' - name: Install Packages run: npm ci --ignore-scripts @@ -72,7 +72,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v4 with: - path: "./build" + path: './build' deploy-to-production: needs: @@ -81,7 +81,7 @@ jobs: group: main-production cancel-in-progress: true env: - BASE_URL: "" + BASE_URL: '' permissions: pages: write id-token: write diff --git a/.github/workflows/preview.yml b/.github/workflows/preview.yml index bb023bd8..627c325b 100644 --- a/.github/workflows/preview.yml +++ b/.github/workflows/preview.yml @@ -16,7 +16,7 @@ jobs: environment: name: sandbox env: - BASE_URL: "/" + BASE_URL: '/' steps: # we set the correct repository and reference sha for PR preview - name: Checkout PR @@ -31,7 +31,7 @@ jobs: cache: npm check-latest: true node-version: 22 - node-version-file: ".nvmrc" + node-version-file: '.nvmrc' - name: Install Packages run: npm ci --ignore-scripts @@ -69,7 +69,7 @@ jobs: - name: Upload artifact uses: actions/upload-pages-artifact@v4 with: - path: "./build" + path: './build' deploy-to-staging: needs: @@ -78,7 +78,7 @@ jobs: group: ${{ github.ref_name }}-staging cancel-in-progress: true env: - BASE_URL: "" + BASE_URL: '' permissions: pull-requests: write contents: write @@ -98,12 +98,12 @@ jobs: - name: Extract artifact run: tar -xvf artifact.tar working-directory: website - shell: "bash" + shell: 'bash' - name: Clean up before deploy run: rm artifact.tar working-directory: website - shell: "bash" + shell: 'bash' - name: Display structure of downloaded files run: ls -R From 7e26001e4ebd41d21d6562af04d4415fe55cbbe0 Mon Sep 17 00:00:00 2001 From: Manuel Spigolon Date: Wed, 4 Feb 2026 15:48:12 +0100 Subject: [PATCH 4/4] Update .github/workflows/deploy-website.yml Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com> Signed-off-by: Manuel Spigolon --- .github/workflows/deploy-website.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/deploy-website.yml b/.github/workflows/deploy-website.yml index 3ba4f3f0..2b68b776 100644 --- a/.github/workflows/deploy-website.yml +++ b/.github/workflows/deploy-website.yml @@ -78,7 +78,7 @@ jobs: needs: - build-and-upload concurrency: - group: main-production + group: ${{ github.ref_name }}-production cancel-in-progress: true env: BASE_URL: ''