Skip to content

Get rid of useless Wranglers worker #5

Get rid of useless Wranglers worker

Get rid of useless Wranglers worker #5

Workflow file for this run

name: Deploy frontend
on:
push:
paths:
- 'apps/frontend/**/*'
- 'packages/ui/**/*'
- 'packages/utils/**/*'
- 'packages/assets/**/*'
- '**/wrangler.jsonc'
- '**/pnpm-*.yaml'
pull_request:
workflow_dispatch:
jobs:
deploy:
if: github.repository_owner == 'modrinth'
runs-on: ubuntu-latest
permissions:
contents: read
deployments: write
environment:
name: ${{ github.ref == 'refs/heads/prod' && 'production' || 'staging' }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 2
- name: Configure environment
id: meta
run: |
echo "cmd=deploy" >> $GITHUB_OUTPUT
if [ "${{ github.ref }}" == "refs/heads/main" ]; then
echo "env=staging" >> $GITHUB_OUTPUT
echo "url=https://staging.modrinth.com" >> $GITHUB_OUTPUT
elif [ "${{ github.ref }}" != "refs/heads/prod" ] && [ "${{ github.ref }}" != "refs/heads/main" ]; then
echo "env=development" >> $GITHUB_OUTPUT
echo "url=https://${GITHUB_SHA::8}-frontend-staging.modrinth.workers.dev" >> $GITHUB_OUTPUT
echo "cmd=versions upload --preview-alias ${GITHUB_SHA::8} --var PREVIEW=true" >> $GITHUB_OUTPUT
else
# Production env should be empty
echo "url=https://modrinth.com" >> $GITHUB_OUTPUT
fi
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node
uses: actions/setup-node@v4
with:
node-version-file: .nvmrc
cache: pnpm
- 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 }}
- name: Deploy Cloudflare Worker
id: wrangler
working-directory: ./apps/frontend
run: |
echo "RATE_LIMIT_IGNORE_KEY=${{ secrets.RATE_LIMIT_IGNORE_KEY }}" > .dev.vars
npx wrangler secret bulk --env="${{ steps.meta.outputs.env }}" .dev.vars
rm .dev.vars
npx wrangler ${{ steps.meta.outputs.cmd }} --env="${{ steps.meta.outputs.env }}"
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CF_API_TOKEN }}
- 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