Skip to content

Commit 45ae559

Browse files
committed
feat: breakdown
1 parent 4f5d8bd commit 45ae559

File tree

3 files changed

+99
-24
lines changed

3 files changed

+99
-24
lines changed

.github/workflows/pr-preview-build.yml

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
name: PR Preview Build Release Binaries
22

33
on:
4-
pull_request_target:
5-
types: [opened, synchronize, reopened, closed]
4+
pull_request:
65

76
jobs:
87
build:
@@ -57,27 +56,13 @@ jobs:
5756
path: ${{ github.workspace }}/out
5857
retention-days: 7
5958

60-
- name: Create or Update PR Release
61-
if: ${{ github.event.action != 'closed' }}
62-
env:
63-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
64-
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
65-
59+
- name: Save PR number
6660
run: |
67-
# Check if release exists
68-
if gh release view "$RELEASE_TAG" &>/dev/null; then
69-
echo "Updating release $RELEASE_TAG"
70-
gh release upload "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* --clobber
71-
else
72-
echo "Creating release $RELEASE_TAG"
73-
gh release create "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* \
74-
--title "$RELEASE_TAG" \
75-
--notes "Preview release for PR #${PR_NUMBER}"
76-
fi
61+
mkdir -p ./pr
62+
echo ${{ github.event.pull_request.number }} > ./pr/number
7763
78-
- name: Delete PR Release on Close
79-
if: ${{ github.event.action == 'closed' }}
80-
env:
81-
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
82-
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
83-
run: gh release delete "$RELEASE_TAG" --cleanup-tag --yes
64+
- name: Upload PR number
65+
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02
66+
with:
67+
name: pr-number
68+
path: pr/
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
name: PR Preview Cleanup
2+
3+
on:
4+
pull_request:
5+
types: [closed]
6+
7+
permissions:
8+
contents: write
9+
10+
jobs:
11+
cleanup:
12+
name: Delete PR Release
13+
runs-on: ubuntu-latest
14+
15+
steps:
16+
- name: Delete PR Release
17+
env:
18+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
19+
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
20+
run: |
21+
gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} || true
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
name: PR Preview Release
2+
3+
on:
4+
workflow_run:
5+
workflows: ["PR Preview Build"]
6+
types:
7+
- completed
8+
9+
permissions:
10+
contents: write
11+
pull-requests: write
12+
13+
jobs:
14+
release:
15+
name: Create Release
16+
runs-on: ubuntu-latest
17+
if: ${{ github.event.workflow_run.conclusion == 'success' }}
18+
19+
steps:
20+
- name: Download PR number
21+
uses: actions/download-artifact@v4
22+
with:
23+
name: pr-number
24+
github-token: ${{ secrets.GITHUB_TOKEN }}
25+
run-id: ${{ github.event.workflow_run.id }}
26+
27+
- name: Read PR number
28+
id: pr
29+
run: echo "number=$(cat number)" >> $GITHUB_OUTPUT
30+
31+
- name: Download Build Artifacts
32+
uses: actions/download-artifact@v4
33+
with:
34+
name: agentapi-build-${{ steps.pr.outputs.number }}
35+
path: ./out
36+
github-token: ${{ secrets.GITHUB_TOKEN }}
37+
run-id: ${{ github.event.workflow_run.id }}
38+
39+
40+
- name: Create or Update PR Release
41+
if: ${{ github.event.action != 'closed' }}
42+
env:
43+
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
44+
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
45+
46+
run: |
47+
# Check if release exists
48+
if gh release view "$RELEASE_TAG" &>/dev/null; then
49+
echo "Updating release $RELEASE_TAG"
50+
gh release upload "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* --clobber
51+
else
52+
echo "Creating release $RELEASE_TAG"
53+
gh release create "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* \
54+
--title "$RELEASE_TAG" \
55+
--notes "Preview release for PR #${PR_NUMBER}"
56+
fi
57+
58+
- name: Comment on PR
59+
uses: actions/github-script@v7
60+
with:
61+
script: |
62+
const prNumber = ${{ steps.pr.outputs.number }};
63+
const releaseTag = `agentapi_${prNumber}`;
64+
github.rest.issues.createComment({
65+
issue_number: prNumber,
66+
owner: context.repo.owner,
67+
repo: context.repo.repo,
68+
body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi: ${prNumber}\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}`
69+
});

0 commit comments

Comments
 (0)