Skip to content

Deploying adev preview #9

Deploying adev preview

Deploying adev preview #9

# 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
id: pr-number
run: |
PR_NUMBER=$(cat __metadata__pull_number.txt)
echo "value=$PR_NUMBER" >> $GITHUB_OUTPUT
- name: Extract commit hash
id: commit-hash
run: |
COMMIT_HASH=$(cat __metadata__commit_hash.txt)
echo "value=$COMMIT_HASH" >> $GITHUB_OUTPUT
- run: echo ${{ steps.pr-number.outputs.value }} ${{ steps.commit-hash.outputs.value }}
- name: Deploy to cloudflare pages
run: npx wrangler pages deploy ./ --project-name $CLOUDFLARE_PAGES_PROJECT --branch pr-$PR_NUMBER --commit-hash $COMMIT_HASH
env:
PR_NUMBER: ${{ steps.pr-number.outputs.value }}
COMMIT_HASH: ${{ steps.commit-hash.outputs.value }}
CLOUDFLARE_API_TOKEN: ${{ secrets.CLOUDFLARE_API_TOKEN }}
CLOUDFLARE_ACCOUNT_ID: ${{ vars.CLOUDFLARE_ACCOUNT_ID }}
CLOUDFLARE_PAGES_PROJECT: ${{ vars.CLOUDFLARE_PAGES_PROJECT }}
- name: Find Comment
uses: peter-evans/find-comment@v3
id: find-comment
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.pr-number.outputs.value }}
comment-author: 'github-actions[bot]'
body-includes: 'Preview deployed'
- name: Comment on pull request
uses: peter-evans/create-or-update-comment@v4
with:
token: ${{ secrets.GITHUB_TOKEN }}
issue-number: ${{ steps.pr-number.outputs.value }}
comment-id: ${{ steps.find-comment.outputs.comment-id }}
edit-mode: replace
body: |
Preview deployed to https://pr-${{ steps.pr-number.outputs.value }}.dev-angular-jp.pages.dev (commit: ${{ steps.commit-hash.outputs.value }})