-
Notifications
You must be signed in to change notification settings - Fork 52
feat: preview deploy workflow for external contributors #872
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
3aa3a33
add preview deploy workflow for forked repos
jkbktl 40b8b1e
simplify workflow, remove /deploy comment
jkbktl 5031ebb
Create thick-humans-impress.md
jkbktl 0eb13fb
add trim()
jkbktl f9d83e2
set success state based on deployments
jkbktl 33bfc9d
Merge branch 'main' into feat/preview-deploy-external
jkbktl 083909b
address feedback
jkbktl a2e8414
Merge branch 'main' into feat/preview-deploy-external
jkbktl d6ad349
Merge branch 'main' into feat/preview-deploy-external
jkbktl c45983c
add stauts-components to deployables
jkbktl e7217c2
Merge branch 'main' into feat/preview-deploy-external
jkbktl 84c74ab
Merge branch 'main' into feat/preview-deploy-external
jkbktl File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Some comments aren't visible on the classic Files Changed page.
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| --- | ||
|
|
||
| --- | ||
|
|
||
| feat: preview deploy workflow for external contributors | ||
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,268 @@ | ||
| name: Preview Deploy (External Contributors) | ||
|
|
||
| on: | ||
| pull_request_target: | ||
| types: [opened, synchronize, reopened] | ||
|
|
||
| permissions: | ||
| contents: read | ||
| pull-requests: write | ||
| statuses: write | ||
|
|
||
| env: | ||
| VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| jobs: | ||
| deploy-preview: | ||
| name: Deploy Preview | ||
| if: github.event.pull_request.head.repo.fork == true | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| runs-on: ubuntu-latest | ||
| environment: preview-deploy-approval | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| steps: | ||
| - name: Set PR info | ||
| id: pr | ||
| run: | | ||
| echo "head_sha=${{ github.event.pull_request.head.sha }}" >> $GITHUB_OUTPUT | ||
| echo "pr_number=${{ github.event.pull_request.number }}" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Set pending status | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| sha: '${{ steps.pr.outputs.head_sha }}', | ||
| state: 'pending', | ||
| context: 'Preview Deploy', | ||
| description: 'Detecting changes and deploying...' | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| }); | ||
|
|
||
| - name: Checkout PR head | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| ref: ${{ github.event.pull_request.head.sha }} | ||
| fetch-depth: 0 | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| persist-credentials: false | ||
|
|
||
| - name: Fetch base commit | ||
| run: | | ||
| git fetch origin ${{ github.event.pull_request.base.sha }} | ||
| git branch base-sha FETCH_HEAD | ||
|
|
||
| - name: Setup pnpm | ||
| uses: pnpm/action-setup@v4 | ||
| with: | ||
| version: 9.12.3 | ||
|
|
||
| - name: Setup Node.js | ||
| uses: actions/setup-node@v4 | ||
| with: | ||
| node-version: 22.17.0 | ||
| cache: 'pnpm' | ||
|
|
||
| - name: Install dependencies | ||
| run: pnpm install --frozen-lockfile --ignore-scripts | ||
|
|
||
| - name: Detect changed apps with Turbo | ||
jkbktl marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
|
||
| id: changes | ||
| run: | | ||
| # Get affected packages using turbo's change detection | ||
| # Use immutable base SHA reference instead of mutable branch name | ||
| BASE_REF="base-sha" | ||
|
|
||
| echo "Detecting changes between $BASE_REF and HEAD..." | ||
|
|
||
| # Use turbo to find affected packages with build task | ||
| # Capture stderr separately to avoid hiding real errors | ||
| set +e | ||
| affected=$(pnpm turbo build --filter="...[$BASE_REF]" --dry-run=json 2>&1) | ||
| turbo_exit=$? | ||
| set -e | ||
|
|
||
| echo "Turbo output:" | ||
| echo "$affected" | head -50 | ||
|
|
||
| # Check if turbo failed | ||
| if [ $turbo_exit -ne 0 ]; then | ||
| echo "::error::Turbo failed with exit code $turbo_exit" | ||
| exit 1 | ||
| fi | ||
|
|
||
| # Extract package names from turbo output | ||
| packages=$(echo "$affected" | jq -r '.packages[]' 2>/dev/null || echo "") | ||
|
|
||
| echo "Affected packages:" | ||
| echo "$packages" | ||
|
|
||
| # Filter to only deployable apps | ||
| apps_to_deploy="" | ||
| while IFS= read -r pkg; do | ||
| case "$pkg" in | ||
| "status.app"|"hub"|"portfolio"|"api"|"status.network"|"@status-im/components") | ||
| apps_to_deploy="$apps_to_deploy $pkg" | ||
| ;; | ||
| esac | ||
| done <<< "$packages" | ||
|
|
||
| apps_to_deploy=$(echo "$apps_to_deploy" | xargs) | ||
| echo "Apps to deploy: $apps_to_deploy" | ||
| echo "apps=$apps_to_deploy" >> $GITHUB_OUTPUT | ||
|
|
||
| - name: Install Vercel CLI | ||
| run: npm install -g vercel@latest | ||
|
|
||
| - name: Deploy status.app | ||
jkbktl marked this conversation as resolved.
Fixed
Show fixed
Hide fixed
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| id: deploy-status-app | ||
| if: contains(steps.changes.outputs.apps, 'status.app') | ||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: apps/status.app | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_STATUS_APP }} | ||
|
|
||
| - name: Deploy hub | ||
| id: deploy-hub | ||
| if: contains(steps.changes.outputs.apps, 'hub') | ||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: apps/hub | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_HUB }} | ||
|
|
||
| - name: Deploy portfolio | ||
| id: deploy-portfolio | ||
| if: contains(steps.changes.outputs.apps, 'portfolio') | ||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: apps/portfolio | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_PORTFOLIO }} | ||
|
|
||
| - name: Deploy api | ||
| id: deploy-api | ||
| if: contains(steps.changes.outputs.apps, 'api') | ||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: apps/api | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_API }} | ||
|
|
||
| - name: Deploy status.network | ||
| id: deploy-status-network | ||
| if: contains(steps.changes.outputs.apps, 'status.network') | ||
jkbktl marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: apps/status.network | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_STATUS_NETWORK }} | ||
|
|
||
| - name: Deploy components (Storybook) | ||
| id: deploy-components | ||
| if: contains(steps.changes.outputs.apps, '@status-im/components') | ||
| run: | | ||
| vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | ||
| vercel build --token=${{ secrets.VERCEL_TOKEN }} | ||
| url=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) | ||
| echo "url=$url" >> $GITHUB_OUTPUT | ||
| working-directory: packages/components | ||
| env: | ||
| VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID_COMPONENTS }} | ||
|
|
||
| - name: Set status and comment PR | ||
| if: success() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| const deployments = []; | ||
|
|
||
| if ('${{ steps.deploy-status-app.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'status.app', url: '${{ steps.deploy-status-app.outputs.url }}' }); | ||
| } | ||
| if ('${{ steps.deploy-hub.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'hub', url: '${{ steps.deploy-hub.outputs.url }}' }); | ||
| } | ||
| if ('${{ steps.deploy-portfolio.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'portfolio', url: '${{ steps.deploy-portfolio.outputs.url }}' }); | ||
| } | ||
| if ('${{ steps.deploy-api.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'api', url: '${{ steps.deploy-api.outputs.url }}' }); | ||
| } | ||
| if ('${{ steps.deploy-status-network.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'status.network', url: '${{ steps.deploy-status-network.outputs.url }}' }); | ||
| } | ||
| if ('${{ steps.deploy-components.outputs.url }}'.trim()) { | ||
| deployments.push({ name: 'components', url: '${{ steps.deploy-components.outputs.url }}' }); | ||
| } | ||
|
|
||
| if (deployments.length === 0) { | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| sha: '${{ steps.pr.outputs.head_sha }}', | ||
| state: 'success', | ||
| context: 'Preview Deploy', | ||
| description: 'No deployable app changes detected' | ||
| }); | ||
| await github.rest.issues.createComment({ | ||
| issue_number: ${{ steps.pr.outputs.pr_number }}, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: `⚠️ **No apps to deploy**\n\nNo changes detected in deployable apps.` | ||
| }); | ||
| return; | ||
| } | ||
|
|
||
| await github.rest.repos.createCommitStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| sha: '${{ steps.pr.outputs.head_sha }}', | ||
| state: 'success', | ||
| context: 'Preview Deploy', | ||
| description: `Deployed ${deployments.length} app(s) successfully` | ||
| }); | ||
|
|
||
| let table = '| Project | Status | Preview |\n'; | ||
| table += '|---------|--------|----------|\n'; | ||
| for (const dep of deployments) { | ||
| table += `| ${dep.name} | ✅ Ready | [Preview](${dep.url}) |\n`; | ||
| } | ||
|
|
||
| const body = `**Preview deployments are ready!**\n\n${table}\n\n---\n*Deployed via GitHub Actions*`; | ||
|
|
||
| await github.rest.issues.createComment({ | ||
| issue_number: ${{ steps.pr.outputs.pr_number }}, | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| body: body | ||
| }); | ||
|
|
||
| - name: Set failure status | ||
| if: failure() | ||
| uses: actions/github-script@v7 | ||
| with: | ||
| script: | | ||
| await github.rest.repos.createCommitStatus({ | ||
| owner: context.repo.owner, | ||
| repo: context.repo.repo, | ||
| sha: '${{ steps.pr.outputs.head_sha }}', | ||
| state: 'failure', | ||
| context: 'Preview Deploy', | ||
| description: 'Deployment failed - check Actions logs' | ||
| }); | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.