Preview deployments on labeled pull requests #6
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: Deploy Preview Site | |
on: | |
pull_request: | |
types: | |
- labeled | |
permissions: | |
contents: read | |
pull-requests: write | |
jobs: | |
deploy: | |
name: Deploy to Cloudflare Pages | |
if: github.event.label.name == 'request-preview-deployment' | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
submodules: recursive | |
fetch-depth: 0 | |
- name: Setup Hugo | |
uses: peaceiris/actions-hugo@v3 | |
with: | |
hugo-version: '0.117.0' | |
- name: Build site | |
run: hugo | |
- name: Deploy to Cloudflare Pages | |
id: deploy | |
uses: cloudflare/pages-action@v1 | |
with: | |
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }} | |
accountId: ${{ secrets.CLOUDFLARE_ACCOUNT_ID }} | |
projectName: ${{ vars.CLOUDFLARE_PROJECT_NAME }} | |
directory: 'public/' | |
branch: ${{ github.event.pull_request.head.ref }} | |
- name: Echo all outputs of cloudflare/pages-action | |
run: echo "${{ toJson(steps.deploy.outputs) }}" | |
- name: Find Comment | |
uses: peter-evans/find-comment@v3 | |
id: fc | |
with: | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-author: 'github-actions[bot]' | |
body-includes: preview environment | |
- name: Create comment | |
if: steps.fc.outputs.comment-id == '' | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
body: | | |
### :eyes: Preview Environment :eyes: | |
Your changes have been successfully deployed to a preview environment! :tada: | |
:heavy_check_mark: We kindly ask you to visit this **[LINK](${{ steps.deploy.outputs.alias }})** to verify that everything looks as expected. :heavy_check_mark: | |
_Your contribution is greatly appreciated! :rocket:_ | |
reactions: rocket | |
- name: Update comment | |
if: steps.fc.outputs.comment-id != '' | |
uses: peter-evans/create-or-update-comment@v4 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
issue-number: ${{ github.event.pull_request.number }} | |
comment-id: ${{ steps.fc.outputs.comment-id }} | |
body: | | |
### :eyes: Preview Environment :eyes: | |
Your changes have been successfully deployed to a preview environment! :tada: | |
:heavy_check_mark: We kindly ask you to visit this **[LINK](${{ steps.deploy.outputs.alias }})** to verify that everything looks as expected. :heavy_check_mark: | |
_Your contribution is greatly appreciated! :rocket:_ | |
reactions: hooray | |
edit-mode: 'replace' | |
- name: Remove Label | |
uses: actions/github-script@v5 | |
with: | |
github-token: ${{ secrets.GITHUB_TOKEN }} | |
script: | | |
const issue_number = context.issue.number; | |
const labelToRemove = 'request-preview-deployment'; | |
github.rest.issues.removeLabel({ | |
owner: context.repo.owner, | |
repo: context.repo.repo, | |
issue_number: issue_number, | |
name: labelToRemove | |
}); |