Skip to content

Go Build and Release #65

Go Build and Release

Go Build and Release #65

name: Go Build and Release
on:
workflow_dispatch:
inputs:
version:
description: 'Version number for release'
required: true
push:
tags:
- v*
env:
VERSION: ${{ github.event.inputs.version || github.ref }}
jobs:
build:
permissions: write-all
runs-on: ubuntu-latest
strategy:
matrix:
goos:
- windows
- linux
- darwin
goarch:
- amd64
- arm64
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
EXECUTABLE_NAME: ai${{ (matrix.goos == 'windows') && '.exe' || '' }}
ARTIFACT_NAME: ai-${{ (matrix.goos == 'darwin') && 'macos' || matrix.goos }}-${{ matrix.goarch }}
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.1'
- name: Build AI binary
run: |
go build -o $EXECUTABLE_NAME -v -x
if [[ "${GOOS}" == "darwin" || "${GOOS}" == "linux" ]]; then
chmod +x $EXECUTABLE_NAME
fi
- name: Create Artifact
id: artifacts
run: |
mkdir -p release/${ARTIFACT_NAME}
mv ${EXECUTABLE_NAME} prompts.yaml release/${ARTIFACT_NAME}
- name: Upload artifact as a build artifact
uses: actions/upload-artifact@v3
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./release/${{ env.ARTIFACT_NAME }}
release:
permissions: write-all
needs: build
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v3
with:
path: release/
- name: List all files
run: |
find . -not -path '*/\.*' -type f
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: '1.23.1'
- name: generate release zips
run: |
cd release/
for f in *; do
zip -r "${f}.zip" "$f"
done
- name: List all files
run: |
find . -not -path '*/\.*' -type f
- name: Build AI binary
run: go build -o ai
- name: Generate Release Notes
run: |
VERSION=${VERSION#refs/tags/}
echo "VERSION=${VERSION}" >> $GITHUB_ENV
LAST_RELEASE=$(git describe --tags --match "v*" --exclude "*-rc*" --exclude "$VERSION" --abbrev=0)
git log --pretty=format:"%s" $LAST_RELEASE.. | ./ai --text \
"Generate release notes for AI terminal assistant ${VERSION}, a developer-oriented cli tool that lets users enter shell commands using natural language, powered by ai.
Write the release notes in a user-friendly way, with some emojis but don't go overboard with marketing, keep it fun but to the point. Use markdown. Add a features, fixes, other section. Don't explain what the tool is, just provide updates. Skip technical details that don't matter to a user. Ignore fixes within github workflow files, unless they matter to the user." > release_notes.txt
env:
OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}
- name: Publish Release
uses: softprops/action-gh-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: ${{ env.VERSION }}
files: |
./release/*.zip
body_path: release_notes.txt
fail_on_unmatched_files: true
draft: ${{ contains(env.VERSION, 'rc') }}