diff --git a/.github/workflows/pr-preview-build.yml b/.github/workflows/pr-preview-build.yml new file mode 100644 index 0000000..5608198 --- /dev/null +++ b/.github/workflows/pr-preview-build.yml @@ -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 + path: pr/ \ No newline at end of file diff --git a/.github/workflows/pr-preview-cleanup.yml b/.github/workflows/pr-preview-cleanup.yml new file mode 100644 index 0000000..ba7ced5 --- /dev/null +++ b/.github/workflows/pr-preview-cleanup.yml @@ -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 \ No newline at end of file diff --git a/.github/workflows/pr-preview-release.yml b/.github/workflows/pr-preview-release.yml new file mode 100644 index 0000000..4f20312 --- /dev/null +++ b/.github/workflows/pr-preview-release.yml @@ -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 + + - 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 + 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 + + - 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}` + }); \ No newline at end of file