feat: user authentication flow #11
Workflow file for this run
This file contains 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: Vercel Preview Deployment | |
env: | |
VERCEL_ORG_ID: ${{ secrets.VERCEL_ORG_ID }} | |
VERCEL_PROJECT_ID: ${{ secrets.VERCEL_PROJECT_ID }} | |
on: | |
pull_request_target: | |
branches: [ master ] | |
types: [opened, synchronize] | |
workflow_dispatch: | |
concurrency: | |
group: preview-${{ github.event.number || github.ref }} | |
cancel-in-progress: true | |
jobs: | |
Deploy-Preview: | |
runs-on: ubuntu-latest | |
permissions: | |
contents: read # For repository checkout | |
pull-requests: write # For preview URL comments | |
steps: | |
- name: Verify Pull Request Author Access | |
uses: 'deriv-com/shared-actions/.github/actions/verify_user_in_organization@v3' | |
with: | |
username: ${{github.event.pull_request.user.login}} | |
token: ${{ secrets.ORG_READ_PAT }} | |
# Checkout PR code only after verification | |
- name: Checkout Repository | |
uses: actions/checkout@v4 | |
with: | |
ref: ${{ github.event.pull_request.head.sha }} | |
- name: Install Vercel Command Line Tools | |
run: npm install --global vercel@latest | |
- name: Fetch Preview Environment Configuration | |
run: vercel pull --yes --environment=preview --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Build Application for Preview Deployment | |
run: vercel build --token=${{ secrets.VERCEL_TOKEN }} | |
- name: Deploy Preview Build to Vercel | |
id: deploy | |
run: | | |
DEPLOYMENT_URL=$(vercel deploy --prebuilt --token=${{ secrets.VERCEL_TOKEN }}) || exit 1 | |
echo "url=$DEPLOYMENT_URL" >> $GITHUB_OUTPUT | |
- name: Add Preview URL to Pull Request Comments | |
if: success() | |
uses: actions/github-script@v7 | |
with: | |
script: | | |
const deploymentUrl = '${{ steps.deploy.outputs.url }}'; | |
const body = `🚀 Preview: ${deploymentUrl}`; | |
const comments = await github.rest.issues.listComments({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
}); | |
const botComment = comments.data.find(comment => | |
comment.user.type === 'Bot' && | |
comment.body.includes('Preview:') | |
); | |
if (botComment) { | |
await github.rest.issues.updateComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
comment_id: botComment.id, | |
body | |
}); | |
} else { | |
await github.rest.issues.createComment({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: context.issue.number, | |
body | |
}); | |
} |