Repository navigation
changelog #1295
This file contains hidden or 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
| name: Deploy frontend | |
| on: | |
| push: | |
| branches: | |
| - main | |
| - prod | |
| paths: | |
| - 'apps/frontend/**/*' | |
| - 'packages/ui/**/*' | |
| - 'packages/utils/**/*' | |
| - 'packages/assets/**/*' | |
| - 'packages/moderation/**/*' | |
| - '**/wrangler.jsonc' | |
| - '**/pnpm-*.yaml' | |
| - '.github/workflows/frontend-deploy.yml' | |
| workflow_dispatch: | |
| workflow_call: | |
| inputs: | |
| preview: | |
| required: false | |
| type: boolean | |
| description: 'Whether this is a preview deployment' | |
| head_sha: | |
| required: false | |
| type: string | |
| description: 'The commit SHA to deploy (defaults to github.sha)' | |
| head_ref: | |
| required: false | |
| type: string | |
| description: 'The branch name to deploy (defaults to github.ref_name)' | |
| branch_alias: | |
| required: false | |
| type: string | |
| description: 'The persistent preview alias for the branch' | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-${{ inputs.preview && 'preview' || 'push' }} | |
| cancel-in-progress: ${{ github.ref != 'refs/heads/main' && github.ref != 'refs/heads/prod' }} | |
| env: | |
| TURBO_TELEMETRY_DISABLED: 1 | |
| pnpm_config_color: always | |
| jobs: | |
| deploy: | |
| runs-on: namespace-profile-modrinth-frontend | |
| permissions: | |
| contents: read | |
| deployments: write | |
| pull-requests: write | |
| steps: | |
| - name: Checkout code | |
| uses: namespacelabs/nscloud-checkout-action@66f2dc6f6c42a8ac6c4e53473c4840006822831e # v9.0.1 | |
| with: | |
| fetch-depth: 0 | |
| dissociate: true | |
| - name: Configure environment | |
| id: meta | |
| env: | |
| PREVIEW_INPUT: ${{ inputs.preview }} | |
| REF: ${{ github.ref }} | |
| DEPLOY_SHA: ${{ inputs.head_sha || github.sha }} | |
| BRANCH_ALIAS: ${{ inputs.branch_alias }} | |
| run: | | |
| echo "cmd=deploy" >> $GITHUB_OUTPUT | |
| SHA_SHORT="${DEPLOY_SHA::8}" | |
| if [ "$PREVIEW_INPUT" = "true" ]; then | |
| URL="https://git-$SHA_SHORT-frontend.modrinth.workers.dev" | |
| STAGING_URL="https://git-$SHA_SHORT-staging-frontend.modrinth.workers.dev" | |
| echo "env=production" >> $GITHUB_OUTPUT | |
| echo "url=$URL" >> $GITHUB_OUTPUT | |
| echo "staging_url=$STAGING_URL" >> $GITHUB_OUTPUT | |
| echo "cmd=versions upload --preview-alias git-$SHA_SHORT --var PREVIEW:true --var CF_PAGES_URL:$URL" >> $GITHUB_OUTPUT | |
| STAGING_VARS=$(jq -r '.env.staging.vars | to_entries[] | "--var \(.key):\(.value)"' ./apps/frontend/wrangler.jsonc | tr '\n' ' ') | |
| echo "staging_cmd=versions upload --preview-alias git-$SHA_SHORT-staging ${STAGING_VARS}--var PREVIEW:true --var CF_PAGES_URL:$STAGING_URL" >> $GITHUB_OUTPUT | |
| if [ -n "$BRANCH_ALIAS" ]; then | |
| echo "branch_alias_url=https://$BRANCH_ALIAS-frontend.modrinth.workers.dev" >> $GITHUB_OUTPUT | |
| echo "staging_branch_alias_url=https://$BRANCH_ALIAS-staging-frontend.modrinth.workers.dev" >> $GITHUB_OUTPUT | |
| echo "staging_branch_alias_cmd=versions upload --preview-alias $BRANCH_ALIAS-staging ${STAGING_VARS}--var PREVIEW:true --var CF_PAGES_URL:https://$BRANCH_ALIAS-staging-frontend.modrinth.workers.dev" >> $GITHUB_OUTPUT | |
| fi | |
| 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@820762786026740c76f36085b0efc47a31fe5020 # v7.0.0 | |
| with: | |
| node-version-file: .nvmrc | |
| - name: Enable Corepack | |
| run: corepack enable | |
| - name: Set up caches | |
| uses: namespacelabs/nscloud-cache-action@1124a6f3ce44e5cf84cc22111530961f4d2a15f9 # v1.7.0 | |
| with: | |
| cache: | | |
| rust | |
| pnpm | |
| apt | |
| - name: Set up Turborepo caching | |
| uses: namespace-actions/setup-turbocache@a94b84c111f2cc781a4a83c4d07a99f2c63e33d6 # v0.0.3 | |
| - 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 | |
| run: pnpm web:build | |
| env: | |
| CF_PAGES_BRANCH: ${{ inputs.head_ref || github.ref_name }} | |
| CF_PAGES_COMMIT_SHA: ${{ inputs.head_sha || github.sha }} | |
| CF_PAGES_URL: ${{ steps.meta.outputs.url }} | |
| BUILD_ENV: ${{ steps.meta.outputs.env }} | |
| PREVIEW: ${{ inputs.preview && 'true' || 'false' }} | |
| - name: Install Wrangler CLI | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./apps/frontend | |
| packageManager: pnpm | |
| wranglerVersion: '4.112.0' | |
| command: --version | |
| - parallel: | |
| - name: Deploy Cloudflare Worker | |
| id: wrangler | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.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 | |
| command: ${{ steps.meta.outputs.cmd }} | |
| - name: Deploy staging Cloudflare Worker preview | |
| if: ${{ inputs.preview }} | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./apps/frontend | |
| command: ${{ steps.meta.outputs.staging_cmd }} | |
| - name: Deploy persistent Cloudflare Worker preview | |
| if: ${{ inputs.preview && inputs.branch_alias != '' }} | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./apps/frontend | |
| command: versions upload --preview-alias ${{ inputs.branch_alias }} --var PREVIEW:true --var CF_PAGES_URL:${{ steps.meta.outputs.branch_alias_url }} | |
| - name: Deploy persistent staging Cloudflare Worker preview | |
| if: ${{ inputs.preview && inputs.branch_alias != '' }} | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./apps/frontend | |
| command: ${{ steps.meta.outputs.staging_branch_alias_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 URLs to files | |
| if: ${{ inputs.preview }} | |
| run: | | |
| echo "${{ steps.meta.outputs.url }}" > deployment-url-production.txt | |
| echo "${{ steps.meta.outputs.staging_url }}" > deployment-url-staging.txt | |
| - parallel: | |
| - name: Upload production deployment URL | |
| if: ${{ inputs.preview }} | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: deployment-url-production | |
| path: deployment-url-production.txt | |
| - name: Upload staging deployment URL | |
| if: ${{ inputs.preview }} | |
| uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 | |
| with: | |
| name: deployment-url-staging | |
| path: deployment-url-staging.txt |