Skip to content

Build Code

Build Code #1

Workflow file for this run

name: Build
run-name: Build Code
on:
push:
branches: ['main']
permissions:
contents: write
concurrency:
group: 'build-deploy'
cancel-in-progress: true
# You should only need to touch these two variables
env:
buildCommand: |
npm ci
npm run build
buildOutput: dist # optionally "dist" if build step is needed
jobs:
build-main:
environment: github-pages
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Build App
run: ${{ env.buildCommand }}
- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true
- name: Upload Artifact
uses: actions/upload-artifact@v4
with:
name: main
path: ${{ env.buildOutput }}
getPRs:
runs-on: ubuntu-latest
outputs:
prData: ${{ steps.data.outputs.pullRequestData }}
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Setup Deno
uses: denoland/setup-deno@v1
- name: Get PR Data
id: data
run: |
data=$(deno run --allow-net .github/workflows/getPRs.ts ${{ github.repository }} ${{ secrets.GITHUB_TOKEN }}) # output: pullRequestData: {ref: string, number: number}[]
echo "pullRequestData=$data" >> "$GITHUB_OUTPUT"
build-pr:
runs-on: ubuntu-latest
needs: getPRs
# GH Actions outputs are strings, so we can just compare this to an empty array string. `.length` does not seem to work when parsing the array.
if: needs.getPRs.outputs.prData != '[]'
strategy:
matrix:
data: ${{ fromJSON(needs.getPRs.outputs.prData) }}
steps:
- name: Checkout PR branch
uses: actions/checkout@v4
with:
ref: ${{ matrix.data.ref }}
- name: Add Base Path to Vite Config
run: echo 'VITE_BASE_PATH=/pr/${{ matrix.data.number }}/' > .env
- name: Build App
run: ${{ env.buildCommand }}
- name: Minify Code
uses: Lenni009/minify-js@main
with:
directory: ${{ env.buildOutput }}
overwrite: true
- name: Upload App
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.data.number }}
path: ${{ env.buildOutput }}
deploy:
runs-on: ubuntu-latest
if: ${{ !cancelled() && !failure() }}
needs: ['build-main', 'build-pr']
steps:
- name: Checkout Repo
uses: actions/checkout@v4
- name: Download App
uses: actions/download-artifact@v4
with:
path: dist/pr
- name: Move Main Deployment
run: |
cd dist
cp -r pr/main/* .
rm -rf pr/main
touch .nojekyll
- name: Deploy
uses: JamesIves/github-pages-deploy-action@v4
with:
folder: dist