Skip to content

feat: PR preview build release #8

feat: PR preview build release

feat: PR preview build release #8

name: PR Preview Build Release Binaries
on:
pull_request:
permissions:
contents: write
jobs:
build:
name: Build Release Binaries
runs-on: depot-ubuntu-22.04-4
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 and Upload
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-build
path: ${{ github.workspace }}/out
retention-days: 7
- name: Create or Update PR Release
if: ${{ github.event.action != 'closed' }}
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
echo "Creating release $RELEASE_TAG"
gh release create "$RELEASE_TAG" "$GITHUB_WORKSPACE"/out/* \
--title "$RELEASE_TAG" \
--notes "Preview release for PR #${PR_NUMBER}"
fi
- name: Delete PR Release on Close
if: ${{ github.event.action == 'closed' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
RELEASE_TAG: 'agentapi_${{ github.event.pull_request.number }}'
run: gh release delete "$RELEASE_TAG" --cleanup-tag --yes