Skip to content

Commit 2dac890

Browse files
andykenwardCopilot
andcommitted
ci: deploy-fork
Co-authored-by: Copilot <copilot@github.com>
1 parent b4a0c6a commit 2dac890

1 file changed

Lines changed: 50 additions & 0 deletions

File tree

.github/workflows/deploy-fork.yml

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# yaml-language-server: $schema=https://json.schemastore.org/github-workflow.json
2+
3+
name: deploy-fork
4+
on:
5+
workflow_run:
6+
workflows:
7+
- test
8+
types:
9+
- completed
10+
11+
concurrency:
12+
group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }}
13+
14+
jobs:
15+
deploy-fork:
16+
if: ${{ github.event.workflow_run.head_repository.fork && github.event.workflow_run.conclusion == 'success' && github.event.workflow_run.event == 'pull_request' && github.event.workflow_run.head_branch != 'main' }}
17+
permissions:
18+
actions: read
19+
contents: read
20+
deployments: write
21+
pull-requests: write
22+
runs-on: ubuntu-latest
23+
timeout-minutes: 5
24+
steps:
25+
- if: github.event_name == 'workflow_run'
26+
uses: actions/checkout@de0fac2e4500dabe0009e67214ff5f5447ce83dd #v6.0.2
27+
with:
28+
repository: ${{ github.event.workflow_run.head_repository.full_name }}
29+
ref: ${{ github.event.workflow_run.head_sha }}
30+
- id: pr-number
31+
env:
32+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
33+
HEAD_SHA: ${{ github.event.workflow_run.head_sha }}
34+
run: |
35+
pr_number="$(jq -r '.workflow_run.pull_requests[0].number // empty' "$GITHUB_EVENT_PATH")"
36+
37+
if [[ -z "$pr_number" ]]; then
38+
pr_number="$(curl -fsSL \
39+
-H "Authorization: Bearer $GITHUB_TOKEN" \
40+
-H "Accept: application/vnd.github+json" \
41+
"${GITHUB_API_URL}/repos/${GITHUB_REPOSITORY}/commits/${HEAD_SHA}/pulls" \
42+
| jq -r '.[0].number // empty')"
43+
fi
44+
45+
if [[ -z "$pr_number" ]]; then
46+
echo "Unable to resolve PR number for workflow_run head_sha=${HEAD_SHA}" >&2
47+
exit 1
48+
fi
49+
50+
echo "value=$pr_number" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)