Skip to content

fix: normalize version #10

fix: normalize version

fix: normalize version #10

name: Build and Release CLI
on:
push:
branches: [main]
paths:
- 'apps/cli/**'
tags:
- 'cli/v*'
pull_request:
branches: [main]
paths:
- 'apps/cli/**'
workflow_dispatch:
inputs:
version:
description: 'Release version (e.g., v1.0.0)'
required: false
default: ''
env:
GO_VERSION: '1.24'
jobs:
build:
name: Build CLI
runs-on: ubuntu-latest
strategy:
matrix:
include:
- goos: linux
goarch: amd64
suffix: linux-amd64
- goos: linux
goarch: arm64
suffix: linux-arm64
- goos: darwin
goarch: amd64
suffix: darwin-amd64
- goos: darwin
goarch: arm64
suffix: darwin-arm64
- goos: windows
goarch: amd64
suffix: windows-amd64
extension: .exe
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: apps/cli/go.sum
- name: Cache Go modules
uses: actions/cache@v4
with:
path: |
~/.cache/go-build
~/go/pkg/mod
key: ${{ runner.os }}-go-${{ hashFiles('apps/cli/go.sum') }}
restore-keys: |
${{ runner.os }}-go-
- name: Get version info
id: version
run: |
cd apps/cli
# Get git commit info
GIT_COMMIT=$(git rev-parse --short HEAD)
BUILD_TIME=$(date -u '+%Y-%m-%d_%H:%M:%S')
# Determine version
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.version }}" != "" ]]; then
VERSION="${{ github.event.inputs.version }}"
elif [[ "${{ github.ref }}" == refs/tags/cli/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/cli/}
else
VERSION="${GIT_COMMIT}"
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "git_commit=${GIT_COMMIT}" >> $GITHUB_OUTPUT
echo "build_time=${BUILD_TIME}" >> $GITHUB_OUTPUT
echo "Building version: ${VERSION}"
echo "Git commit: ${GIT_COMMIT}"
echo "Build time: ${BUILD_TIME}"
- name: Build binary
run: |
cd apps/cli
BINARY_NAME="asyncstatus${{ matrix.extension }}"
OUTPUT_NAME="asyncstatus-${{ matrix.suffix }}${{ matrix.extension }}"
echo "Building ${OUTPUT_NAME} for ${{ matrix.goos }}/${{ matrix.goarch }}"
CGO_ENABLED=0 GOOS=${{ matrix.goos }} GOARCH=${{ matrix.goarch }} go build \
-ldflags "-s -w -X asyncstatus.com/cli/cmd.Version=${{ steps.version.outputs.version }} -X asyncstatus.com/cli/cmd.BuildTime=${{ steps.version.outputs.build_time }} -X asyncstatus.com/cli/cmd.GitCommit=${{ steps.version.outputs.git_commit }}" \
-o "bin/${OUTPUT_NAME}" \
.
# Verify the binary was created
ls -la bin/
file "bin/${OUTPUT_NAME}" || true
- name: Test binary (Linux only)
if: matrix.goos == 'linux' && matrix.goarch == 'amd64'
run: |
cd apps/cli
chmod +x "bin/asyncstatus-${{ matrix.suffix }}"
./bin/asyncstatus-${{ matrix.suffix }} --version
- name: Upload build artifacts
uses: actions/upload-artifact@v4
with:
name: asyncstatus-${{ matrix.suffix }}
path: apps/cli/bin/asyncstatus-${{ matrix.suffix }}${{ matrix.extension }}
retention-days: 7
test:
name: Test CLI
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: ${{ env.GO_VERSION }}
cache-dependency-path: apps/cli/go.sum
- name: Run tests
run: |
cd apps/cli
go test -v ./...
- name: Run go vet
run: |
cd apps/cli
go vet ./...
- name: Run staticcheck
uses: dominikh/staticcheck-action@v1
with:
working-directory: apps/cli
version: "latest"
release:
name: Create Release
runs-on: ubuntu-latest
needs: [build, test]
if: >
github.event_name == 'workflow_dispatch' ||
(github.event_name == 'push' && startsWith(github.ref, 'refs/tags/cli/v'))
permissions:
contents: write
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Get version info
id: version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.version }}" != "" ]]; then
VERSION="${{ github.event.inputs.version }}"
TAG_NAME="cli/${VERSION}"
elif [[ "${{ github.ref }}" == refs/tags/cli/v* ]]; then
VERSION=${GITHUB_REF#refs/tags/cli/}
TAG_NAME="cli/${VERSION}"
else
echo "No version found for release"
exit 1
fi
echo "version=${VERSION}" >> $GITHUB_OUTPUT
echo "tag_name=${TAG_NAME}" >> $GITHUB_OUTPUT
echo "Release version: ${VERSION}"
echo "Tag name: ${TAG_NAME}"
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Prepare release assets
run: |
mkdir -p ./release
# Copy and rename artifacts
for artifact_dir in ./artifacts/asyncstatus-*; do
if [ -d "$artifact_dir" ]; then
cp "$artifact_dir"/* ./release/
fi
done
# List what we have
echo "Release assets:"
ls -la ./release/
- name: Generate checksums
run: |
cd ./release
sha256sum * > checksums.txt
echo "Checksums:"
cat checksums.txt
- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ steps.version.outputs.tag_name }}
name: "CLI ${{ steps.version.outputs.version }}"
draft: false
prerelease: ${{ contains(steps.version.outputs.version, '-') }}
files: |
./release/*
body: |
# AsyncStatus CLI ${{ steps.version.outputs.version }}
## Installation
### Quick Install (Linux/macOS)
```bash
curl -fsSL https://raw.githubusercontent.com/AsyncStatus/asyncstatus/main/apps/cli/install.sh | bash
```
### Manual Installation
1. Download the appropriate binary for your platform
2. Make it executable: `chmod +x asyncstatus-*`
3. Move to your PATH: `mv asyncstatus-* /usr/local/bin/asyncstatus`
### Supported Platforms
- Linux (amd64, arm64)
- macOS (amd64, arm64)
- Windows (amd64)
## Usage
```bash
# Show current status
asyncstatus
# Add status updates
asyncstatus "completed something"
asyncstatus progress "working on something"
asyncstatus blocker "blocked by something"
# View and manage
asyncstatus show
asyncstatus list
asyncstatus undo
```
## Verification
Verify the download using the checksums:
```bash
sha256sum -c checksums.txt
```
## Full Changelog
**Full Changelog**: https://github.com/AsyncStatus/asyncstatus/compare/cli/${{ steps.version.outputs.version }}...cli/${{ steps.version.outputs.version }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}