fix(frontend): trim and validate version number in version modal #4188
Workflow file for this run
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 preview | |
| on: | |
| pull_request: | |
| paths: | |
| - 'apps/frontend/**/*' | |
| - 'packages/ui/**/*' | |
| - 'packages/utils/**/*' | |
| - 'packages/assets/**/*' | |
| - 'packages/moderation/**/*' | |
| - '**/wrangler.jsonc' | |
| - '**/pnpm-*.yaml' | |
| - '.github/workflows/frontend-preview.yml' | |
| jobs: | |
| metadata: | |
| if: github.repository_owner == 'modrinth' && github.event.pull_request.head.repo.full_name == github.repository | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branch-alias: ${{ steps.meta.outputs.branch_alias }} | |
| steps: | |
| - name: Configure branch alias | |
| id: meta | |
| run: echo "branch_alias=pr-${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | |
| deploy: | |
| if: github.repository_owner == 'modrinth' && github.event.pull_request.head.repo.full_name == github.repository | |
| needs: metadata | |
| uses: ./.github/workflows/frontend-deploy.yml | |
| secrets: inherit | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-deploy | |
| cancel-in-progress: true | |
| with: | |
| preview: true | |
| head_sha: ${{ github.event.pull_request.head.sha }} | |
| head_ref: ${{ github.event.pull_request.head.ref }} | |
| branch_alias: ${{ needs.metadata.outputs.branch-alias }} | |
| deploy-storybook: | |
| if: github.repository_owner == 'modrinth' && github.event.pull_request.head.repo.full_name == github.repository | |
| needs: metadata | |
| runs-on: namespace-profile-modrinth-frontend | |
| concurrency: | |
| group: ${{ github.workflow }}-${{ github.ref }}-storybook | |
| cancel-in-progress: true | |
| permissions: | |
| contents: read | |
| deployments: write | |
| steps: | |
| - name: Checkout code | |
| uses: namespacelabs/nscloud-checkout-action@66f2dc6f6c42a8ac6c4e53473c4840006822831e # v9.0.1 | |
| - 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@c5f8dab7560444c4bf8dbc64f1b203431873c547 # v1.6.1 | |
| with: | |
| cache: | | |
| pnpm | |
| - name: Install dependencies | |
| working-directory: ./packages/ui | |
| run: pnpm install | |
| - name: Build Storybook | |
| env: | |
| NODE_OPTIONS: --max-old-space-size=6144 | |
| run: pnpm build-storybook | |
| - name: Configure short SHA | |
| id: meta | |
| env: | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| run: echo "sha_short=${HEAD_SHA::8}" >> $GITHUB_OUTPUT | |
| - name: Install Wrangler CLI | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./packages/ui | |
| packageManager: pnpm | |
| wranglerVersion: '4.112.0' | |
| command: --version | |
| - parallel: | |
| - name: Deploy Storybook preview | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./packages/ui | |
| command: versions upload --preview-alias git-${{ steps.meta.outputs.sha_short }} | |
| - name: Deploy persistent Storybook preview | |
| uses: cloudflare/wrangler-action@ebbaa1584979971c8614a24965b4405ff95890e0 # v4.0.0 | |
| env: | |
| NODE_OPTIONS: --max-old-space-size=6144 | |
| with: | |
| apiToken: ${{ secrets.CF_API_TOKEN }} | |
| accountId: ${{ secrets.CF_ACCOUNT_ID }} | |
| workingDirectory: ./packages/ui | |
| command: versions upload --preview-alias ${{ needs.metadata.outputs.branch-alias }} | |
| comment: | |
| if: | | |
| !cancelled() | |
| && github.repository_owner == 'modrinth' | |
| && github.event.pull_request.head.repo.full_name == github.repository | |
| && needs.deploy.result == 'success' | |
| runs-on: ubuntu-latest | |
| needs: [metadata, deploy, deploy-storybook] | |
| permissions: | |
| pull-requests: write | |
| steps: | |
| - name: Download deployment URLs | |
| uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 | |
| with: | |
| pattern: deployment-url-* | |
| merge-multiple: true | |
| - name: Read deployment URLs | |
| id: urls | |
| env: | |
| HEAD_SHA: ${{ github.event.pull_request.head.sha }} | |
| BRANCH_ALIAS: ${{ needs.metadata.outputs.branch-alias }} | |
| STORYBOOK_RESULT: ${{ needs.deploy-storybook.result }} | |
| RUN_URL: ${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }} | |
| run: | | |
| STAGING_SHA_URL=$(cat deployment-url-staging.txt) | |
| PRODUCTION_SHA_URL=$(cat deployment-url-production.txt) | |
| STAGING_BRANCH_URL="https://$BRANCH_ALIAS-staging-frontend.modrinth.workers.dev" | |
| PRODUCTION_BRANCH_URL="https://$BRANCH_ALIAS-frontend.modrinth.workers.dev" | |
| if [ "$STORYBOOK_RESULT" = "success" ]; then | |
| STORYBOOK_SHA_URL="https://git-${HEAD_SHA::8}-storybook.modrinth.workers.dev" | |
| STORYBOOK_BRANCH_URL="https://$BRANCH_ALIAS-storybook.modrinth.workers.dev" | |
| else | |
| STORYBOOK_SHA_URL="⚠️ Deployment $STORYBOOK_RESULT ([logs]($RUN_URL))" | |
| STORYBOOK_BRANCH_URL="⚠️ Deployment $STORYBOOK_RESULT ([logs]($RUN_URL))" | |
| fi | |
| echo "staging-sha-url=$STAGING_SHA_URL" >> $GITHUB_OUTPUT | |
| echo "production-sha-url=$PRODUCTION_SHA_URL" >> $GITHUB_OUTPUT | |
| echo "storybook-sha-url=$STORYBOOK_SHA_URL" >> $GITHUB_OUTPUT | |
| echo "staging-branch-url=$STAGING_BRANCH_URL" >> $GITHUB_OUTPUT | |
| echo "production-branch-url=$PRODUCTION_BRANCH_URL" >> $GITHUB_OUTPUT | |
| echo "storybook-branch-url=$STORYBOOK_BRANCH_URL" >> $GITHUB_OUTPUT | |
| - name: Find comment | |
| if: github.event_name == 'pull_request' | |
| uses: peter-evans/find-comment@b30e6a3c0ed37e7c023ccd3f1db5c6c0b0c23aad # v4.0.0 | |
| id: fc | |
| with: | |
| token: ${{ github.token }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| body-includes: Frontend previews | |
| - name: Comment deploy URL on PR | |
| if: github.event_name == 'pull_request' | |
| uses: peter-evans/create-or-update-comment@e8674b075228eee787fea43ef493e45ece1004c9 # v5.0.0 | |
| with: | |
| token: ${{ github.token }} | |
| issue-number: ${{ github.event.pull_request.number }} | |
| comment-id: ${{ steps.fc.outputs.comment-id }} | |
| body: | | |
| ## Frontend previews | |
| Last deployed commit is [${{ github.event.pull_request.head.sha }}](${{ github.event.pull_request.head.repo.html_url }}/commit/${{ github.event.pull_request.head.sha }}) | |
| ### Persistent | |
| | Environment | URL | | |
| |-------------|-----| | |
| | staging | ${{ steps.urls.outputs.staging-branch-url }} | | |
| | production | ${{ steps.urls.outputs.production-branch-url }} | | |
| | storybook | ${{ steps.urls.outputs.storybook-branch-url }} | | |
| ### Latest commit | |
| | Environment | URL | | |
| |-------------|-----| | |
| | staging | ${{ steps.urls.outputs.staging-sha-url }} | | |
| | production | ${{ steps.urls.outputs.production-sha-url }} | | |
| | storybook | ${{ steps.urls.outputs.storybook-sha-url }} | | |
| edit-mode: replace |