Skip to content

Commit 686dbee

Browse files
authored
ci: fix pr-tarball for fork PRs using pull_request_target (aws#586)
1 parent ac2b562 commit 686dbee

2 files changed

Lines changed: 71 additions & 57 deletions

File tree

.github/workflows/build-and-test.yml

Lines changed: 0 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -80,60 +80,3 @@ jobs:
8080
vite-config-path: vitest.unit.config.ts
8181
file-coverage-mode: none
8282
coverage-thresholds: '{ "lines": 50, "branches": 50, "functions": 50, "statements": 50 }'
83-
84-
pr-tarball:
85-
needs: build
86-
runs-on: ubuntu-latest
87-
if: github.event_name == 'pull_request'
88-
permissions:
89-
contents: write
90-
pull-requests: write
91-
92-
steps:
93-
- uses: actions/checkout@v6
94-
- name: Download tarball artifact
95-
uses: actions/download-artifact@v8
96-
with:
97-
name: tarball
98-
path: tarball/
99-
- name: Get tarball info
100-
id: tarball
101-
run: |
102-
TARBALL_NAME=$(ls tarball/*.tgz | head -1 | xargs basename)
103-
echo "name=$TARBALL_NAME" >> $GITHUB_OUTPUT
104-
- name: Create or update PR release
105-
id: release
106-
env:
107-
GH_TOKEN: ${{ github.token }}
108-
PR_NUMBER: ${{ github.event.pull_request.number }}
109-
TARBALL_NAME: ${{ steps.tarball.outputs.name }}
110-
run: |
111-
TAG="pr-${PR_NUMBER}-tarball"
112-
113-
# Delete existing release if it exists (to update the tarball)
114-
gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true
115-
116-
# Create a new pre-release with the tarball
117-
gh release create "$TAG" \
118-
"tarball/${TARBALL_NAME}" \
119-
--title "PR #${PR_NUMBER} Tarball" \
120-
--notes "Auto-generated tarball for PR #${PR_NUMBER}." \
121-
--prerelease \
122-
--target "${{ github.event.pull_request.head.sha }}"
123-
124-
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${TARBALL_NAME}"
125-
echo "url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
126-
- name: Comment on PR
127-
uses: marocchino/sticky-pull-request-comment@v3
128-
with:
129-
header: tarball
130-
message: |
131-
## Package Tarball
132-
133-
**[${{ steps.tarball.outputs.name }}](${{ steps.release.outputs.url }})**
134-
135-
### How to install
136-
137-
```bash
138-
npm install ${{ steps.release.outputs.url }}
139-
```

.github/workflows/pr-tarball.yml

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
name: PR Tarball
2+
on:
3+
pull_request_target:
4+
branches: [main]
5+
6+
permissions:
7+
contents: write
8+
pull-requests: write
9+
10+
jobs:
11+
pr-tarball:
12+
runs-on: ubuntu-latest
13+
if: >-
14+
contains(fromJSON('["OWNER","MEMBER","COLLABORATOR"]'), github.event.pull_request.author_association)
15+
steps:
16+
- uses: actions/checkout@v6
17+
with:
18+
ref: ${{ github.event.pull_request.head.sha }}
19+
- uses: actions/setup-node@v6
20+
with:
21+
node-version: '20.x'
22+
cache: 'npm'
23+
- name: Configure git
24+
run: |
25+
git config --global user.email "bedrock-agentcore-npm+ci@amazon.com"
26+
git config --global user.name "CI"
27+
- uses: astral-sh/setup-uv@v7
28+
- run: npm ci
29+
- run: npm run build --if-present
30+
- run: npm pack
31+
- name: Get tarball info
32+
id: tarball
33+
run: |
34+
TARBALL_NAME=$(ls *.tgz | head -1 | xargs basename)
35+
echo "name=$TARBALL_NAME" >> $GITHUB_OUTPUT
36+
- name: Create or update PR release
37+
id: release
38+
env:
39+
GH_TOKEN: ${{ github.token }}
40+
PR_NUMBER: ${{ github.event.pull_request.number }}
41+
TARBALL_NAME: ${{ steps.tarball.outputs.name }}
42+
run: |
43+
TAG="pr-${PR_NUMBER}-tarball"
44+
45+
# Delete existing release if it exists (to update the tarball)
46+
gh release delete "$TAG" --yes --cleanup-tag 2>/dev/null || true
47+
48+
# Create a new pre-release with the tarball
49+
gh release create "$TAG" \
50+
"${TARBALL_NAME}" \
51+
--title "PR #${PR_NUMBER} Tarball" \
52+
--notes "Auto-generated tarball for PR #${PR_NUMBER}." \
53+
--prerelease \
54+
--target "${{ github.event.pull_request.head.sha }}"
55+
56+
DOWNLOAD_URL="https://github.com/${{ github.repository }}/releases/download/${TAG}/${TARBALL_NAME}"
57+
echo "url=$DOWNLOAD_URL" >> $GITHUB_OUTPUT
58+
- name: Comment on PR
59+
uses: marocchino/sticky-pull-request-comment@v3
60+
with:
61+
header: tarball
62+
message: |
63+
## Package Tarball
64+
65+
**[${{ steps.tarball.outputs.name }}](${{ steps.release.outputs.url }})**
66+
67+
### How to install
68+
69+
```bash
70+
npm install ${{ steps.release.outputs.url }}
71+
```

0 commit comments

Comments
 (0)