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
+ - name : Create or Update PR Release
40
+ env :
41
+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
42
+ RELEASE_TAG : " agentapi_${{ steps.pr.outputs.number }}"
43
+ PR_NUMBER : ${{ steps.pr.outputs.number }}
44
+ run : |
45
+ # Check if release exists
46
+ if gh release view "$RELEASE_TAG" --repo ${{ github.repository }} &>/dev/null; then
47
+ echo "Updating release $RELEASE_TAG"
48
+ gh release upload "$RELEASE_TAG" ./out/* --clobber --repo ${{ github.repository }}
49
+ else
50
+ echo "Creating release $RELEASE_TAG"
51
+ gh release create "$RELEASE_TAG" ./out/* \
52
+ --title "$RELEASE_TAG" \
53
+ --notes "Preview release for PR #${PR_NUMBER}" \
54
+ --repo ${{ github.repository }} \
55
+ --latest=false \
56
+ --prerelease
57
+ fi
58
+
59
+ - name : Comment on PR
60
+ uses : actions/github-script@v7
61
+ with :
62
+ script : |
63
+ const prNumber = ${{ steps.pr.outputs.number }};
64
+ const releaseTag = `agentapi_${prNumber}`;
65
+ const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`;
66
+ github.rest.issues.createComment({
67
+ issue_number: prNumber,
68
+ owner: context.repo.owner,
69
+ repo: context.repo.repo,
70
+ body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi_version = "agentapi_${prNumber}"\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}`
71
+ });
0 commit comments