Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
68 changes: 68 additions & 0 deletions .github/workflows/pr-preview-build.yml
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"
Copy link
Member

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?

)

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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can't you use github.event.pull_request.number here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, in the pr-preview-release until i don't download this artifact I won't be knowing about the pr number that triggered pr-preview-build.

path: pr/
21 changes: 21 additions & 0 deletions .github/workflows/pr-preview-cleanup.yml
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
69 changes: 69 additions & 0 deletions .github/workflows/pr-preview-release.yml
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
run: echo "number=$(cat number)" >> $GITHUB_OUTPUT
run: echo "number=${number}" >> $GITHUB_OUTPUT

Also, where does number come from? Should this be pr-number?

Copy link
Collaborator Author

@35C4n0r 35C4n0r Sep 29, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@johnstcn the number comes from the downloaded artifact (that is uploaded by pr-preview-build)


- 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can just exit 0 here if there's nothing else to do, then you don't need the else.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The 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

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
Copy link
Member

Choose a reason for hiding this comment

The 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 preview- or similar.


- 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}`
});