# Package builds run without publishing credentials. Releases and cleanup use # REMIX_PREVIEWS_PAT, scoped to remix-run/previews. # The destination must be public, initialized, and have release immutability disabled. name: Preview Build on: push: branches: [main] pull_request: types: [opened, synchronize, reopened, closed] paths: - 'packages/**' - '!**/*.md' - '!**/*.mdx' - '!**/*.test.*' - '!**/*.demo.*' - '!packages/**/demos/**' - '!packages/**/demo/**' - '!packages/**/bench/**' - '!packages/*/**/test/**' schedule: - cron: '23 4 * * *' workflow_dispatch: inputs: baseBranch: description: Source branch or SHA required: true permissions: contents: read jobs: build: if: >- github.repository == 'remix-run/remix' && (github.event_name == 'push' || github.event_name == 'workflow_dispatch' || (github.event_name == 'pull_request' && github.event.pull_request.state == 'open' && github.event.pull_request.head.repo.full_name == github.repository)) runs-on: ubuntu-latest permissions: contents: read pull-requests: read concurrency: group: preview-build-${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.run_id }} cancel-in-progress: ${{ github.event_name == 'pull_request' }} outputs: channel: ${{ steps.metadata.outputs.channel }} tag: ${{ steps.metadata.outputs.tag }} sha: ${{ steps.metadata.outputs.sha }} env: PREVIEW_CHANNEL: ${{ github.event_name == 'pull_request' && format('pr-{0}', github.event.pull_request.number) || github.event_name == 'push' && 'main' || 'experimental' }} steps: - name: Checkout source uses: actions/checkout@v6 with: ref: ${{ github.event.pull_request.head.sha || inputs.baseBranch || github.sha }} persist-credentials: false - uses: pnpm/action-setup@v6 - uses: actions/setup-node@v6 with: node-version-file: package.json package-manager-cache: false - name: Get pnpm store path id: pnpm-store continue-on-error: true run: echo "path=$(pnpm store path --silent)" >> "$GITHUB_OUTPUT" - uses: actions/cache@v5 if: steps.pnpm-store.outputs.path != '' continue-on-error: true with: path: ${{ steps.pnpm-store.outputs.path }} key: pnpm-store-${{ runner.os }}-${{ hashFiles('pnpm-lock.yaml') }} - run: pnpm install --frozen-lockfile - name: Build tarballs id: metadata env: GITHUB_TOKEN: ${{ github.token }} run: node scripts/preview.ts build "$PREVIEW_CHANNEL" --output "$RUNNER_TEMP/preview" - uses: actions/upload-artifact@v7 with: name: preview-${{ github.run_id }} path: ${{ runner.temp }}/preview/*.tgz if-no-files-found: error overwrite: true retention-days: 3 compression-level: 0 publish: needs: build runs-on: ubuntu-latest permissions: contents: write pull-requests: write concurrency: group: preview-${{ needs.build.outputs.channel }} queue: max env: PREVIEW_TAG: ${{ needs.build.outputs.tag }} PREVIEW_SHA: ${{ needs.build.outputs.sha }} steps: - uses: actions/checkout@v6 with: ref: ${{ needs.build.outputs.sha }} persist-credentials: false - uses: actions/setup-node@v6 with: node-version-file: package.json package-manager-cache: false - uses: actions/download-artifact@v8 with: name: preview-${{ github.run_id }} path: .preview - name: Publish release assets id: publish env: REMIX_PREVIEWS_PAT: ${{ secrets.REMIX_PREVIEWS_PAT }} GITHUB_TOKEN: ${{ github.token }} run: node scripts/preview.ts publish "$PREVIEW_TAG" "$PREVIEW_SHA" - name: Update PR installation instructions if: github.event_name == 'pull_request' && steps.publish.outputs.published == 'true' env: GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: node scripts/preview-pr.ts comment "$PR_NUMBER" "$PREVIEW_TAG" "$PREVIEW_SHA" - name: Delete legacy PR preview branch if: github.event_name == 'pull_request' && steps.publish.outputs.published == 'true' env: GITHUB_TOKEN: ${{ github.token }} PREVIEW_CHANNEL: ${{ needs.build.outputs.channel }} run: node scripts/preview.ts cleanup-branch "$PREVIEW_CHANNEL" # PR path filters can skip close events; the nightly sweep cleans PRs closed for 24 hours. cleanup-stale-prs: if: github.repository == 'remix-run/remix' && github.event_name == 'schedule' runs-on: ubuntu-latest permissions: contents: write pull-requests: write concurrency: group: preview-cleanup-stale-prs queue: max steps: - uses: actions/checkout@v6 with: ref: ${{ github.event.repository.default_branch }} persist-credentials: false - uses: actions/setup-node@v6 with: node-version-file: package.json package-manager-cache: false - name: Clean up stranded PR previews env: REMIX_PREVIEWS_PAT: ${{ secrets.REMIX_PREVIEWS_PAT }} GITHUB_TOKEN: ${{ github.token }} run: node scripts/preview.ts cleanup-stale-prs cleanup: if: >- github.repository == 'remix-run/remix' && (github.event_name == 'schedule' || (github.event_name == 'pull_request' && github.event.action == 'closed' && github.event.pull_request.head.repo.full_name == github.repository)) runs-on: ubuntu-latest permissions: contents: write pull-requests: write strategy: fail-fast: false matrix: channel: ${{ github.event_name == 'schedule' && fromJSON('["main", "experimental"]') || fromJSON(format('["pr-{0}"]', github.event.pull_request.number)) }} concurrency: group: preview-${{ matrix.channel }} queue: max env: PREVIEW_CHANNEL: ${{ matrix.channel }} steps: - uses: actions/checkout@v6 with: persist-credentials: false - uses: actions/setup-node@v6 with: node-version-file: package.json package-manager-cache: false - name: Delete legacy PR preview branch if: github.event_name == 'pull_request' env: GITHUB_TOKEN: ${{ github.token }} run: node scripts/preview.ts cleanup-branch "$PREVIEW_CHANNEL" - name: Delete expired releases and tags env: REMIX_PREVIEWS_PAT: ${{ secrets.REMIX_PREVIEWS_PAT }} GITHUB_TOKEN: ${{ github.token }} run: node scripts/preview.ts cleanup "$PREVIEW_CHANNEL" - name: Update closed PR preview comment if: github.event_name == 'pull_request' env: GITHUB_TOKEN: ${{ github.token }} PR_NUMBER: ${{ github.event.pull_request.number }} run: node scripts/preview-pr.ts cleanup "$PR_NUMBER"