Skip to content

Commit 816aa09

Browse files
infra: make workflow data passing secure
1 parent 6f078a1 commit 816aa09

2 files changed

Lines changed: 4 additions & 49 deletions

File tree

.github/workflows/deploy-pages.yml

Lines changed: 4 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -35,37 +35,12 @@ jobs:
3535
pull-requests: write
3636
runs-on: ubuntu-latest
3737
steps:
38-
- name: Download build metadata
39-
uses: actions/download-artifact@v8.0.1
40-
with:
41-
name: build-metadata
42-
run-id: ${{ github.event.workflow_run.id }}
43-
github-token: ${{ github.token }}
44-
45-
- name: Parse build metadata
38+
- name: Resolve build metadata
4639
id: metadata
4740
run: |
48-
EVENT_NAME=$(jq -r '.event_name' build-info.json)
49-
PR_NUMBER=$(jq -r '.pr_number // empty' build-info.json)
50-
REF_NAME=$(jq -r '.ref_name' build-info.json)
51-
52-
case "$EVENT_NAME" in
53-
pull_request|push|merge_group|release) ;;
54-
*)
55-
echo "::error::Unexpected event_name: $EVENT_NAME"
56-
exit 1
57-
;;
58-
esac
59-
60-
if [[ -n "$PR_NUMBER" && ! "$PR_NUMBER" =~ ^[0-9]+$ ]]; then
61-
echo "::error::Invalid pr_number: $PR_NUMBER"
62-
exit 1
63-
fi
64-
65-
if [[ ! "$REF_NAME" =~ ^[a-zA-Z0-9._/-]+$ ]]; then
66-
echo "::error::Invalid ref_name: $REF_NAME"
67-
exit 1
68-
fi
41+
EVENT_NAME="${{ github.event.workflow_run.event }}"
42+
PR_NUMBER="${{ github.event.workflow_run.pull_requests[0].number }}"
43+
REF_NAME="${{ github.event.workflow_run.head_branch }}"
6944
7045
if [[ "$EVENT_NAME" == "merge_group" ]]; then
7146
echo "should_deploy=false" >> "$GITHUB_OUTPUT"

.github/workflows/pr.yml

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -49,23 +49,3 @@ jobs:
4949
path: _build
5050
retention-days: 1
5151
if-no-files-found: error
52-
53-
- name: Create build metadata
54-
# FIXME: temp for development
55-
# "ref_name": "${{ github.ref_name }}",
56-
run: |
57-
cat > build-info.json <<'EOF'
58-
{
59-
"event_name": "${{ github.event_name }}",
60-
"pr_number": "${{ github.event.pull_request.number }}",
61-
"ref_name": "main",
62-
"head_sha": "${{ github.sha }}"
63-
}
64-
EOF
65-
66-
- name: Upload build metadata
67-
uses: actions/upload-artifact@v7.0.1
68-
with:
69-
name: build-metadata
70-
path: build-info.json
71-
retention-days: 1

0 commit comments

Comments
 (0)