Skip to content

Commit

Permalink
chore: attempt to allow deploys on forked repo prs
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Apr 8, 2024
1 parent cdffd53 commit 2d78bd3
Showing 1 changed file with 48 additions and 4 deletions.
52 changes: 48 additions & 4 deletions .github/workflows/smoketest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,27 @@ on:
branches:
- main
- deploy
# Triggers the workflow on pull request event, but only for pull request from not forked repo
pull_request:
types:
- opened
- synchronize
# Triggers the workflow on pull request event, but only for pull request opened or pull request labeled with "🚀request-deploy" (from forked repo)
# pull_request is not allowed to use secrets, so we use pull_request_target instead (in forked repos)
pull_request_target:
types:
# When a labeled '🚀request-deploy' pull request from forked repo, it will be deploy to Cloudflare Pages
- labeled
workflow_dispatch:

permissions:
# default contents: read & write (in forked repos, only read)
contents: write
# default deployments: read & write (in forked repos, only read)
deployments: write
# default pull-requests: read & write (in forked repos, only read)
pull-requests: write

env:
NODE_VERSION: 20.x
CF_PAGES_PROJECT_NAME: rail-announcements
Expand All @@ -17,14 +35,20 @@ jobs:
runs-on: ubuntu-latest
name: Test, build and deploy

concurrency:
group: ${{ github.workflow }}-${{ github.event.pull_request.head.ref || github.ref }}
cancel-in-progress: true

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Find existing build status comment
continue-on-error: true
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
if:
${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀 request
deploy') }}
id: find_status_comment
with:
issue-number: ${{ github.event.pull_request.number }}
Expand All @@ -34,7 +58,9 @@ jobs:
- name: Create or update comment
continue-on-error: true
uses: peter-evans/create-or-update-comment@v4
if: github.event_name == 'pull_request'
if:
${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀 request
deploy') }}
with:
issue-number: ${{ github.event.pull_request.number }}
comment-id: ${{ steps.find_status_comment.outputs.comment-id }}
Expand Down Expand Up @@ -113,6 +139,7 @@ jobs:

- name: Publish to Cloudflare Pages
uses: cloudflare/pages-action@1
if: ${{ github.event_name != 'pull_request_target' || contains(github.event.label.name, '🚀 request deploy') }}
id: cf-pages-upload
with:
apiToken: ${{ secrets.CLOUDFLARE_API_TOKEN }}
Expand All @@ -124,10 +151,25 @@ jobs:
# Use PR head branch if available, otherwise use the current branch
branch: ${{ github.event_name == 'pull_request' && github.event.pull_request.head.ref || github.ref_name }}

- name: Remove deploy label
if: ${{ github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀 request deploy') }}
uses: actions/github-script@v6
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: ['🚀request-deploy']
})
- name: Find existing build status comment
continue-on-error: true
uses: peter-evans/find-comment@v3
if: github.event_name == 'pull_request'
if:
${{ github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀 request
deploy') }}
id: find_current_status_comment
with:
issue-number: ${{ github.event.pull_request.number }}
Expand All @@ -136,7 +178,9 @@ jobs:

- name: Update comment
continue-on-error: true
if: github.event_name == 'pull_request' && steps.find_current_status_comment.outputs.comment-id != ''
if:
${{ (github.event_name == 'pull_request' || github.event_name == 'pull_request_target' && contains(github.event.label.name, '🚀 request
deploy')) && steps.find_current_status_comment.outputs.comment-id != '' }}
uses: peter-evans/create-or-update-comment@v4
with:
comment-id: ${{ steps.find_current_status_comment.outputs.comment-id }}
Expand Down

0 comments on commit 2d78bd3

Please sign in to comment.