Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions .github/workflows/deploy-website.yml
Original file line number Diff line number Diff line change
@@ -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: ${{ github.ref_name }}-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
86 changes: 7 additions & 79 deletions .github/workflows/ci-cd.yml → .github/workflows/preview.yml
Original file line number Diff line number Diff line change
@@ -1,72 +1,30 @@
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
environment:
name: sandbox
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Fdawgs this is the core change

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Eomm, this tackles the issues with pull_request_target does it?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes, it does

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:
Expand Down Expand Up @@ -101,50 +59,20 @@ 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:
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:
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' }}

deploy-to-staging:
if: ${{ needs.setup.outputs.current_env == 'staging' }}
needs:
- setup
- build-and-upload
concurrency:
group: ${{ github.ref_name }}-staging
Expand All @@ -155,7 +83,7 @@ jobs:
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 }}
Expand Down
Loading