Skip to content

Commit 070348b

Browse files
committed
feat: automatically update latest tag for cli releases
1 parent 85b7ddf commit 070348b

File tree

2 files changed

+153
-2
lines changed

2 files changed

+153
-2
lines changed

.github/workflows/build-cli-binaries.yml

Lines changed: 151 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,16 @@ name: Build CLI Binaries
1818

1919
on:
2020
workflow_dispatch:
21+
inputs:
22+
version:
23+
description: 'Version tag to build (e.g., v1.0.0)'
24+
required: true
25+
type: string
26+
upload_to_release:
27+
description: 'Upload binaries to GitHub release and update latest tag'
28+
required: false
29+
type: boolean
30+
default: false
2131

2232
jobs:
2333
build:
@@ -46,6 +56,15 @@ jobs:
4656
- name: Checkout code
4757
uses: actions/checkout@v4
4858

59+
- name: Validate version format
60+
run: |
61+
VERSION="${{ inputs.version }}"
62+
if [[ ! "$VERSION" =~ ^v[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?(\+[a-zA-Z0-9.-]+)?$ ]]; then
63+
echo "Error: Version '$VERSION' does not follow semantic versioning format (e.g., v1.0.0, v1.0.0-beta.1)"
64+
exit 1
65+
fi
66+
echo "✓ Version format is valid: $VERSION"
67+
4968
- name: Setup Bun
5069
uses: oven-sh/setup-bun@v2
5170
with:
@@ -253,4 +272,135 @@ jobs:
253272
}
254273
255274
# Clean up any remaining genkit processes
256-
Get-Process | Where-Object { $_.ProcessName -match "genkit" } | Stop-Process -Force -ErrorAction SilentlyContinue
275+
Get-Process | Where-Object { $_.ProcessName -match "genkit" } | Stop-Process -Force -ErrorAction SilentlyContinue
276+
277+
create-release:
278+
needs: [build, test]
279+
runs-on: ubuntu-latest
280+
if: inputs.upload_to_release == 'true'
281+
282+
steps:
283+
- name: Checkout code
284+
uses: actions/checkout@v4
285+
286+
- name: Generate changelog
287+
id: changelog
288+
run: |
289+
# Get the previous release tag
290+
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD~1 2>/dev/null || echo "")
291+
292+
if [[ -n "$PREVIOUS_TAG" ]]; then
293+
# Generate changelog from previous tag to current
294+
CHANGELOG=$(git log --pretty=format:"- %s" $PREVIOUS_TAG..HEAD | head -20)
295+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
296+
echo "$CHANGELOG" >> $GITHUB_OUTPUT
297+
echo "EOF" >> $GITHUB_OUTPUT
298+
else
299+
# First release
300+
echo "changelog<<EOF" >> $GITHUB_OUTPUT
301+
echo "- Initial release" >> $GITHUB_OUTPUT
302+
echo "EOF" >> $GITHUB_OUTPUT
303+
fi
304+
305+
- name: Create Release
306+
id: create_release
307+
uses: actions/create-release@v1
308+
env:
309+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
310+
with:
311+
tag_name: ${{ inputs.version }}
312+
release_name: Genkit CLI ${{ inputs.version }}
313+
body: |
314+
# Genkit CLI ${{ inputs.version }}
315+
316+
## Downloads
317+
318+
- [Linux x64](https://github.com/firebase/genkit/releases/download/${{ inputs.version }}/genkit-linux-x64)
319+
- [Linux ARM64](https://github.com/firebase/genkit/releases/download/${{ inputs.version }}/genkit-linux-arm64)
320+
- [macOS x64](https://github.com/firebase/genkit/releases/download/${{ inputs.version }}/genkit-darwin-x64)
321+
- [macOS ARM64](https://github.com/firebase/genkit/releases/download/${{ inputs.version }}/genkit-darwin-arm64)
322+
- [Windows x64](https://github.com/firebase/genkit/releases/download/${{ inputs.version }}/genkit-win32-x64.exe)
323+
324+
## Changes
325+
326+
${{ steps.changelog.outputs.changelog }}
327+
328+
## Installation
329+
330+
```bash
331+
TODO: Add installation instructions
332+
```
333+
draft: false
334+
prerelease: false
335+
336+
upload-assets:
337+
needs: [build, test, create-release]
338+
runs-on: ubuntu-latest
339+
if: inputs.upload_to_release == 'true'
340+
strategy:
341+
matrix:
342+
include:
343+
- target: linux-x64
344+
- target: linux-arm64
345+
- target: darwin-x64
346+
- target: darwin-arm64
347+
- target: win32-x64
348+
349+
steps:
350+
- name: Set binary extension
351+
id: binary
352+
shell: bash
353+
run: |
354+
if [[ "${{ matrix.target }}" == win32-* ]]; then
355+
echo "ext=.exe" >> $GITHUB_OUTPUT
356+
else
357+
echo "ext=" >> $GITHUB_OUTPUT
358+
fi
359+
360+
- name: Download binary artifact
361+
uses: actions/download-artifact@v4
362+
with:
363+
name: genkit-${{ matrix.target }}
364+
path: ./
365+
366+
- name: Upload to GitHub Release
367+
uses: actions/upload-release-asset@v1
368+
env:
369+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
370+
with:
371+
upload_url: ${{ needs.create-release.outputs.upload_url }}
372+
asset_path: ./genkit-${{ matrix.target }}${{ steps.binary.outputs.ext }}
373+
asset_name: genkit-${{ matrix.target }}
374+
asset_content_type: application/octet-stream
375+
376+
update-latest-tag:
377+
needs: [create-release, upload-assets]
378+
runs-on: ubuntu-latest
379+
if: inputs.upload_to_release == 'true'
380+
381+
steps:
382+
- name: Checkout code
383+
uses: actions/checkout@v4
384+
with:
385+
token: ${{ secrets.GITHUB_TOKEN }}
386+
387+
- name: Update latest tag
388+
run: |
389+
# Check if latest tag already points to the correct version
390+
CURRENT_LATEST=$(git rev-parse latest 2>/dev/null || echo "")
391+
TARGET_COMMIT=$(git rev-parse ${{ inputs.version }} 2>/dev/null || echo "")
392+
393+
if [[ "$CURRENT_LATEST" == "$TARGET_COMMIT" ]]; then
394+
echo "Latest tag already points to ${{ inputs.version }}"
395+
exit 0
396+
fi
397+
398+
# Delete the existing "latest" tag if it exists
399+
git tag -d latest 2>/dev/null || true
400+
git push origin :refs/tags/latest 2>/dev/null || true
401+
402+
# Create new "latest" tag pointing to the release tag
403+
git tag latest ${{ inputs.version }}
404+
git push origin latest
405+
406+
echo "Updated 'latest' tag to point to ${{ inputs.version }}"

bin/install_cli

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,8 @@ if [[ -z "$MACHINE" ]]; then
250250
fi
251251

252252
# We have enough information to generate the binary's download URL.
253-
DOWNLOAD_URL="https://$DOMAIN/bin/$MACHINE/latest"
253+
# Use GitHub releases with "latest" tag that gets updated by the workflow
254+
DOWNLOAD_URL="https://github.com/firebase/genkit/releases/download/latest/genkit-$MACHINE"
254255
echo "-- Downloading binary from $DOWNLOAD_URL"
255256

256257
# We use "curl" to download the binary with a flag set to follow redirects

0 commit comments

Comments
 (0)