-
Notifications
You must be signed in to change notification settings - Fork 79
feat: PR preview build release #101
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
089f623
fdc55ed
6f9a633
2ebfede
2d9743f
1122e81
58a9543
6c04c8b
6b7b739
4f5d8bd
45ae559
cd656aa
c01d334
ea282cb
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
name: PR Preview Release Binaries | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
build: | ||
name: Build Release Binaries | ||
runs-on: depot-ubuntu-22.04-4 | ||
permissions: | ||
contents: write | ||
|
||
steps: | ||
- uses: actions/checkout@v4 | ||
|
||
- name: Set up Go | ||
uses: actions/setup-go@v5 | ||
with: | ||
go-version: 'stable' | ||
|
||
- name: Set up Bun | ||
uses: oven-sh/setup-bun@v2 | ||
|
||
- name: Install Chat Dependencies | ||
run: cd chat && bun install | ||
|
||
- name: Run make gen and check for unstaged changes | ||
run: | | ||
make gen | ||
./check_unstaged.sh | ||
|
||
- name: Build | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
shell: bash | ||
run: | | ||
build_variants=( | ||
"linux amd64 agentapi-linux-amd64" | ||
"linux arm64 agentapi-linux-arm64" | ||
"darwin amd64 agentapi-darwin-amd64" | ||
"darwin arm64 agentapi-darwin-arm64" | ||
"windows amd64 agentapi-windows-amd64.exe" | ||
) | ||
|
||
for variant in "${build_variants[@]}"; do | ||
read -r goos goarch artifact_name <<< "$variant" | ||
|
||
echo "Building for GOOS=$goos GOARCH=$goarch..." | ||
CGO_ENABLED=0 GOOS=$goos GOARCH=$goarch BINPATH="out/$artifact_name" make build | ||
done | ||
|
||
- name: Upload Build Artifact | ||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 # v4.6.2 | ||
with: | ||
name: agentapi-preview-build | ||
path: ${{ github.workspace }}/out | ||
retention-days: 7 | ||
|
||
- name: Save PR number | ||
run: | | ||
mkdir -p ./pr | ||
echo ${{ github.event.pull_request.number }} > ./pr/number | ||
|
||
- name: Upload PR number | ||
uses: actions/upload-artifact@ea165f8d65b6e75b540449e92b4886f43607fa02 | ||
with: | ||
name: pr-number | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can't you use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. No, in the |
||
path: pr/ |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
name: PR Preview Cleanup | ||
|
||
on: | ||
pull_request: | ||
types: [closed] | ||
|
||
permissions: | ||
contents: write | ||
|
||
jobs: | ||
cleanup: | ||
name: Delete PR Release | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- name: Delete PR Release | ||
env: | ||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}' | ||
run: | | ||
gh release delete "$RELEASE_TAG" --cleanup-tag --yes --repo ${{ github.repository }} || true |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,69 @@ | ||||||
name: PR Preview Release | ||||||
|
||||||
on: | ||||||
workflow_run: | ||||||
workflows: ["PR Preview Build"] | ||||||
types: | ||||||
- completed | ||||||
|
||||||
permissions: | ||||||
contents: write | ||||||
pull-requests: write | ||||||
|
||||||
jobs: | ||||||
release: | ||||||
name: Create Release | ||||||
runs-on: ubuntu-latest | ||||||
if: ${{ github.event.workflow_run.conclusion == 'success' }} | ||||||
|
||||||
steps: | ||||||
- name: Download PR number | ||||||
uses: actions/download-artifact@v4 | ||||||
with: | ||||||
name: pr-number | ||||||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||
run-id: ${{ github.event.workflow_run.id }} | ||||||
|
||||||
- name: Read PR number | ||||||
id: pr | ||||||
run: echo "number=$(cat number)" >> $GITHUB_OUTPUT | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Also, where does There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @johnstcn the number comes from the downloaded artifact (that is uploaded by |
||||||
|
||||||
- name: Download Build Artifacts | ||||||
uses: actions/download-artifact@v4 | ||||||
with: | ||||||
name: agentapi-build-${{ steps.pr.outputs.number }} | ||||||
path: ./out | ||||||
github-token: ${{ secrets.GITHUB_TOKEN }} | ||||||
run-id: ${{ github.event.workflow_run.id }} | ||||||
|
||||||
|
||||||
- name: Create or Update PR Release | ||||||
env: | ||||||
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||||||
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}' | ||||||
|
||||||
run: | | ||||||
# Check if release exists | ||||||
if gh release view "$RELEASE_TAG" &>/dev/null; then | ||||||
echo "Updating release $RELEASE_TAG" | ||||||
gh release upload "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* --clobber | ||||||
else | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You can just There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The else contains the logic for the first release
|
||||||
echo "Creating release $RELEASE_TAG" | ||||||
gh release create "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* \ | ||||||
--title "$RELEASE_TAG" \ | ||||||
--notes "Preview release for PR #${PR_NUMBER}" \ | ||||||
--draft --latest=false | ||||||
fi | ||||||
Comment on lines
+46
to
+56
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We should validate the release tag before performing any actions e.g. it should start with |
||||||
|
||||||
- name: Comment on PR | ||||||
uses: actions/github-script@v7 | ||||||
with: | ||||||
script: | | ||||||
const prNumber = ${{ steps.pr.outputs.number }}; | ||||||
const releaseTag = `agentapi_${prNumber}`; | ||||||
github.rest.issues.createComment({ | ||||||
issue_number: prNumber, | ||||||
owner: context.repo.owner, | ||||||
repo: context.repo.repo, | ||||||
body: `✅ Preview binaries are ready!\n\nTo test with modules: \`\`\`agentapi: ${prNumber}\`\`\` or download from: ${repoUrl}/releases/tag/${releaseTag}` | ||||||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we not build for arm64 windows?