ci: fix build/deploy workflows #52
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Sample workflow for building and deploying a Gatsby site to GitHub Pages | ||
# | ||
# To get started with Gatsby see: https://www.gatsbyjs.com/docs/quick-start/ | ||
# | ||
name: Deploy Gatsby site to Pages | ||
on: | ||
# Runs on pushes targeting the default branch | ||
push: | ||
branches: ["main"] | ||
pull_request: | ||
branches: ["main"] | ||
# Allows you to run this workflow manually from the Actions tab | ||
workflow_dispatch: | ||
# Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | ||
permissions: | ||
contents: read | ||
pages: write | ||
id-token: write | ||
# Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | ||
# However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | ||
concurrency: | ||
group: "pages" | ||
cancel-in-progress: false | ||
# Default to bash | ||
defaults: | ||
run: | ||
shell: bash | ||
jobs: | ||
e2e_test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@c85c95e3d7251135ab7dc9ce3241c5835cc595a9 # pin@v2 | ||
- name: Install pnpm | ||
uses: pnpm/action-setup@d882d12c64e032187b2edb46d3a0d003b7a43598 # [email protected] | ||
with: | ||
version: latest | ||
- name: Setup node | ||
uses: actions/setup-node@5e21ff4d9bc1a8cf6de233a3057d20ec6b3fb69d # [email protected] | ||
with: | ||
node-version: 18.16 | ||
- name: Set pnpm cache directory | ||
run: pnpm config set store-dir .pnpm-store | ||
continue-on-error: true | ||
- name: Setup cache | ||
uses: actions/cache@88522ab9f39a2ea568f7027eddc7d8d8bc9d59c8 # pin@v2 | ||
with: | ||
path: | | ||
.pnpm-store | ||
node_modules | ||
/home/runner/.cache/Cypress | ||
key: ${{ runner.os }}-pnpm-v1-${{ hashFiles('**/pnpm-lock.yaml') }} | ||
restore-keys: | | ||
${{ runner.os }}-pnpm-v1- | ||
continue-on-error: true | ||
- name: Install dependencies | ||
run: pnpm install --frozen-lockfile --prefer-offline | ||
- name: Install linux deps | ||
run: | | ||
sudo apt-get install --no-install-recommends -y \ | ||
fluxbox \ | ||
xvfb | ||
- name: Run e2e tests (headful) | ||
run: | | ||
Xvfb :0 -screen 0 1024x768x24 -listen tcp -ac & | ||
fluxbox & | ||
pnpm test | ||
env: | ||
CYPRESS_PRIVATE_KEY_WITH_FUNDS: | ||
${{ secrets.CYPRESS_PRIVATE_KEY_WITH_FUNDS }} | ||
DISPLAY: :0.0 | ||
- name: Archive e2e artifacts | ||
uses: actions/upload-artifact@0b7f8abb1508181956e8e162db84b466c27e18ce # pin@v2 | ||
if: always() | ||
with: | ||
name: e2e-artifacts | ||
path: | | ||
tests/e2e/videos | ||
tests/e2e/screenshots | ||
continue-on-error: true | ||
# Build job | ||
build: | ||
needs: e2e_test | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout | ||
uses: actions/checkout@v3 | ||
- name: Detect package manager | ||
id: detect-package-manager | ||
run: | | ||
if [ -f "${{ github.workspace }}/yarn.lock" ]; then | ||
echo "manager=yarn" >> $GITHUB_OUTPUT | ||
echo "command=install" >> $GITHUB_OUTPUT | ||
exit 0 | ||
elif [ -f "${{ github.workspace }}/package.json" ]; then | ||
echo "manager=npm" >> $GITHUB_OUTPUT | ||
echo "command=ci" >> $GITHUB_OUTPUT | ||
exit 0 | ||
else | ||
echo "Unable to determine package manager" | ||
exit 1 | ||
fi | ||
- name: Setup Node | ||
uses: actions/setup-node@v3 | ||
with: | ||
node-version: "18" | ||
cache: ${{ steps.detect-package-manager.outputs.manager }} | ||
- name: Setup Pages | ||
id: pages | ||
uses: actions/configure-pages@v3 | ||
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@v3 | ||
with: | ||
path: | | ||
public | ||
.cache | ||
key: ${{ runner.os }}-gatsby-build-${{ hashFiles('public') }} | ||
restore-keys: | | ||
${{ runner.os }}-gatsby-build- | ||
- name: Install dependencies | ||
run: ${{ steps.detect-package-manager.outputs.manager }} ${{ steps.detect-package-manager.outputs.command }} | ||
- name: Build with Gatsby | ||
env: | ||
PREFIX_PATHS: 'true' | ||
run: ${{ steps.detect-package-manager.outputs.manager }} run build | ||
- name: Upload artifact | ||
uses: actions/upload-pages-artifact@v1 | ||
with: | ||
path: ./public | ||
# Deployment job | ||
deploy: | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
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@v2 |