Skip to content

Deploying adev preview #6

Deploying adev preview

Deploying adev preview #6

# This workflow runs whenever the ADEV build workflow has completed. Deployment happens
# as part of a dedicated second workflow to avoid security issues where the building would
# otherwise occur in an authorized context where secrets could be leaked.
#
# More details can be found here:
# https://securitylab.github.com/research/github-actions-preventing-pwn-requests/.
name: Deploying adev preview
on:
workflow_run:
workflows: ['Build adev for preview deployment']
types: [completed]
permissions:
# Needed in order to be able to comment on the pull request.
pull-requests: write
# Needed in order to checkout the repository
contents: read
# Needed in order to retrieve the artifacts from the previous job
actions: read
jobs:
deploy:
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- name: Download adev preview artifact from previous workflow run
uses: actions/download-artifact@v4
with:
name: adev-preview
github-token: '${{secrets.GITHUB_TOKEN}}'
run-id: ${{ github.event.workflow_run.id }}
- run: ls -R
- name: Extract pull request number
run: |
PR_NUMBER=$(cat __metadata__pull_number.txt)
echo "PR_NUMBER=$PR_NUMBER" >> $GITHUB_ENV
- name: Extract commit hash
run: |
COMMIT_HASH=$(cat __metadata__commit_hash.txt)
echo "COMMIT_HASH=$COMMIT_HASH" >> $GITHUB_ENV
- run: echo $PR_NUMBER $COMMIT_HASH
- name: Deploy to cloudflare pages
run: npx wrangler pages deploy ./ --project-name $CLOUDFLARE_PAGES_PROJECT --branch pr-$PR_NUMBER --commit-hash $COMMIT_HASH
env:
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }}
- name: Comment on pull request
uses: actions/github-script@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
const prNumber = process.env.PR_NUMBER;
github.issues.createComment({
issue_number: Number(prNumber),
owner: context.repo.owner,
repo: context.repo.repo,
body: `Preview deployed to https://pr-${prNumber}.dev-angular-jp.pages.dev`
})