* chore: bump actions and pin versions * build: switch to blacksmith * fix: use rust-toolchain stable * build: improve pnpm store caching * chore: remove emoji from workflows * fix: run prepare job on blacksmith * chore: kebab case id * build: add concurrency groups to limit duplicate jobs * build: switch around node setup and pnpm setup task * chore: bump to nodejs 24, fix pnpm caching * fix: enable corepack * fix: concurrency deadlock in frontend preview * fix: approve build scripts * fix: just don't cancel concurrent previews * build: remove pnpm setup action everywhere * build: cache apt packages * build: yet another attempt at fixing concurrency * build: lower runner type for frontend deploy * fix: eslint not existing * build: add sccache to turbo-ci * fix: correct nextest pkg * fix: turbo ignoring sccache * revert me: test labrinth tests * Revert "revert me: test labrinth tests" This reverts commit def5cc19183d5c0fe3b6f3c03635d73bb59bd312. * build: compile app before docker build * build: lower runner types * build: remove docker inline caching * build: try mold on labrinth * build: tweak labrinth prod build profile * fix: app windows builds and caching * fix: tombi format cargo.toml * fix: swap ping test to cubecraft to avoid CI flakiness * typos fix --------- Co-authored-by: aecsocket <aecsocket@tutanota.com>
159 lines
5.8 KiB
YAML
159 lines
5.8 KiB
YAML
name: Deploy frontend
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- main
|
|
- prod
|
|
paths:
|
|
- 'apps/frontend/**/*'
|
|
- 'packages/ui/**/*'
|
|
- 'packages/utils/**/*'
|
|
- 'packages/assets/**/*'
|
|
- '**/wrangler.jsonc'
|
|
- '**/pnpm-*.yaml'
|
|
- '.github/workflows/frontend-deploy.yml'
|
|
workflow_dispatch:
|
|
workflow_call:
|
|
inputs:
|
|
environment:
|
|
required: true
|
|
type: string
|
|
description: 'The environment to deploy to (staging-preview or production-preview)'
|
|
|
|
concurrency:
|
|
group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.environment || 'push' }}
|
|
cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/prod' }}
|
|
|
|
jobs:
|
|
deploy:
|
|
runs-on: blacksmith-2vcpu-ubuntu-2404
|
|
permissions:
|
|
contents: read
|
|
deployments: write
|
|
pull-requests: write
|
|
steps:
|
|
- name: Checkout code
|
|
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd # v6.0.2
|
|
with:
|
|
fetch-depth: 0
|
|
|
|
- name: Configure environment
|
|
id: meta
|
|
run: |
|
|
echo "cmd=deploy" >> $GITHUB_OUTPUT
|
|
|
|
ENV_INPUT="${{ inputs.environment }}"
|
|
REF="${{ github.ref }}"
|
|
SHA_SHORT="${GITHUB_SHA::8}"
|
|
|
|
if [ "$ENV_INPUT" = "staging-preview" ]; then
|
|
echo "env=staging" >> $GITHUB_OUTPUT
|
|
echo "url=https://git-$SHA_SHORT-frontend-staging.modrinth.workers.dev" >> $GITHUB_OUTPUT
|
|
echo "cmd=versions upload --preview-alias git-$SHA_SHORT --var PREVIEW:true" >> $GITHUB_OUTPUT
|
|
|
|
elif [ "$ENV_INPUT" = "production-preview" ]; then
|
|
echo "env=production" >> $GITHUB_OUTPUT
|
|
echo "url=https://git-$SHA_SHORT-frontend.modrinth.workers.dev" >> $GITHUB_OUTPUT
|
|
echo "cmd=versions upload --preview-alias git-$SHA_SHORT --var PREVIEW:true" >> $GITHUB_OUTPUT
|
|
|
|
elif [ "$REF" = "refs/heads/main" ]; then
|
|
echo "env=staging" >> $GITHUB_OUTPUT
|
|
echo "url=https://staging.modrinth.com" >> $GITHUB_OUTPUT
|
|
|
|
else
|
|
# Production env (no preview)
|
|
echo "env=production" >> $GITHUB_OUTPUT
|
|
echo "url=https://modrinth.com" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Setup Node
|
|
uses: actions/setup-node@48b55a011bda9f5d6aeb4c2d9c7362e8dae4041e # v6.4.0
|
|
with:
|
|
node-version-file: .nvmrc
|
|
|
|
- name: Enable Corepack
|
|
run: corepack enable
|
|
|
|
- name: Get pnpm store path
|
|
id: pnpm-store
|
|
run: echo "store-path=$(pnpm store path --silent)" >> $GITHUB_OUTPUT
|
|
|
|
- name: Restore pnpm cache
|
|
uses: actions/cache/restore@27d5ce7f107fe9357f9df03efb73ab90386fccae # v5.0.5
|
|
with:
|
|
path: ${{ steps.pnpm-store.outputs.store-path }}
|
|
key: pnpm-cache-${{ runner.os }}-${{ runner.arch }}-${{ hashFiles('**/pnpm-lock.yaml') }}
|
|
restore-keys: |
|
|
pnpm-cache-
|
|
|
|
- name: Inject build variables
|
|
working-directory: ./apps/frontend
|
|
run: |
|
|
if [ "${{ steps.meta.outputs.env }}" == "staging" ]; then
|
|
echo "Injecting staging variables from wrangler.jsonc..."
|
|
jq -r '.env.staging.vars | to_entries[] | "\(.key)=\(.value)"' wrangler.jsonc >> $GITHUB_ENV
|
|
else
|
|
echo "Injecting production variables from wrangler.jsonc..."
|
|
jq -r '.vars | to_entries[] | "\(.key)=\(.value)"' wrangler.jsonc >> $GITHUB_ENV
|
|
fi
|
|
|
|
- name: Install dependencies
|
|
working-directory: ./apps/frontend
|
|
run: pnpm install
|
|
|
|
- name: Build frontend
|
|
working-directory: ./apps/frontend
|
|
run: pnpm build
|
|
env:
|
|
CF_PAGES_BRANCH: ${{ github.ref_name }}
|
|
CF_PAGES_COMMIT_SHA: ${{ github.sha }}
|
|
CF_PAGES_URL: ${{ steps.meta.outputs.url }}
|
|
BUILD_ENV: ${{ steps.meta.outputs.env }}
|
|
PREVIEW: ${{ inputs.environment != '' && 'true' || 'false' }}
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
|
|
- name: Create Sentry release and upload sourcemaps
|
|
uses: getsentry/action-release@5657c9e888b4e2cc85f4d29143ea4131fde4a73a # v3.6.0
|
|
env:
|
|
SENTRY_AUTH_TOKEN: ${{ secrets.SENTRY_AUTH_TOKEN }}
|
|
SENTRY_ORG: modrinth
|
|
SENTRY_PROJECT: knossos-server
|
|
with:
|
|
environment: ${{ steps.meta.outputs.env }}
|
|
sourcemaps: ./apps/frontend/.output/server
|
|
url_prefix: '~/'
|
|
|
|
- name: Deploy Cloudflare Worker
|
|
id: wrangler
|
|
uses: cloudflare/wrangler-action@9acf94ace14e7dc412b076f2c5c20b8ce93c79cd # v3.15.0
|
|
with:
|
|
apiToken: ${{ secrets.CF_API_TOKEN }}
|
|
accountId: ${{ secrets.CF_ACCOUNT_ID }}
|
|
environment: ${{ steps.meta.outputs.env != 'production' && steps.meta.outputs.env || '' }}
|
|
workingDirectory: ./apps/frontend
|
|
packageManager: pnpm
|
|
wranglerVersion: '4.54.0'
|
|
command: ${{ steps.meta.outputs.cmd }}
|
|
|
|
- name: Purge cache
|
|
if: github.ref == 'refs/heads/prod'
|
|
run: |
|
|
curl -X POST \
|
|
-H "Authorization: Bearer ${{ secrets.CF_API_TOKEN }}" \
|
|
-H "Content-Type: application/json" \
|
|
--data '{"hosts": ["modrinth.com", "www.modrinth.com", "staging.modrinth.com"]}' \
|
|
https://api.cloudflare.com/client/v4/zones/e39df17b9c4ef44cbce2646346ee6d33/purge_cache
|
|
|
|
- name: Write deployment URL to file
|
|
if: ${{ inputs.environment != '' }}
|
|
run: |
|
|
echo "${{ steps.meta.outputs.url }}" > deployment-url-${{ inputs.environment }}.txt
|
|
|
|
- name: Upload deployment URL
|
|
if: ${{ inputs.environment != '' }}
|
|
uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1
|
|
with:
|
|
name: deployment-url-${{ inputs.environment }}
|
|
path: deployment-url-${{ inputs.environment }}.txt
|