Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
222 changes: 222 additions & 0 deletions .github/workflows/build-cli.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,222 @@
name: Build CLI Binaries

on:
workflow_call:
inputs:
version:
description: 'Version string (without leading v), e.g. 0.3.0 or dev-<sha>'
type: string
required: true
commit:
description: 'Short commit SHA'
type: string
required: true
upload-to-release:
description: 'Whether to attach archives to a GitHub release'
type: boolean
required: false
default: false
release-tag:
description: 'Release tag to attach archives to (when upload-to-release is true)'
type: string
required: false
default: ''
prerelease:
description: 'Mark the release as a prerelease'
type: boolean
required: false
default: false

jobs:
build-cli:
runs-on: ${{ matrix.runner }}
permissions:
contents: write
strategy:
matrix:
include:
# Linux builds
- goos: linux
goarch: amd64
runner: ubuntu-latest
cc: zig cc -target x86_64-linux-musl
- goos: linux
goarch: arm64
runner: ubuntu-latest
cc: zig cc -target aarch64-linux-musl
# macOS builds
- goos: darwin
goarch: amd64
runner: macos-latest
cc: ''
- goos: darwin
goarch: arm64
runner: macos-latest
cc: ''
# Windows builds
- goos: windows
goarch: amd64
runner: ubuntu-latest
cc: zig cc -target x86_64-windows-gnu
steps:
- uses: mlugg/setup-zig@v2
if: matrix.cc != ''

- uses: actions/setup-go@v6
with:
go-version: 1.26.0

- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download frontend build
uses: actions/download-artifact@v8
with:
name: frontend-build
path: frontend/dist/

- name: Install macFUSE
if: matrix.goos == 'darwin'
run: brew install --cask macfuse

- name: Compute timestamp
id: ts
run: echo "timestamp=$(date -u '+%Y-%m-%dT%H:%M:%SZ')" >> $GITHUB_OUTPUT

- name: Build ${{ matrix.goos }}-${{ matrix.goarch }} binary
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
CGO_ENABLED: 1
CC: ${{ matrix.cc }}
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then
EXT=".exe"
fi

go build \
-trimpath \
-tags=cli \
-ldflags="-s -w -X 'github.com/javi11/altmount/internal/version.Version=${{ inputs.version }}' -X 'github.com/javi11/altmount/internal/version.GitCommit=${{ inputs.commit }}' -X 'github.com/javi11/altmount/internal/version.Timestamp=${{ steps.ts.outputs.timestamp }}'" \
-o "altmount-cli-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}" \
./cmd/altmount/main.go

- name: Create archive
run: |
EXT=""
if [ "${{ matrix.goos }}" = "windows" ]; then
EXT=".exe"
fi

BINARY_NAME="altmount-cli-${{ matrix.goos }}-${{ matrix.goarch }}${EXT}"
ARCHIVE_NAME="altmount-cli_v${{ inputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}"

if [ "${{ matrix.goos }}" = "windows" ]; then
zip "${ARCHIVE_NAME}.zip" "$BINARY_NAME"
else
tar -czf "${ARCHIVE_NAME}.tar.gz" "$BINARY_NAME"
fi

- name: Upload ${{ matrix.goos }}-${{ matrix.goarch }} artifacts
uses: actions/upload-artifact@v6
with:
name: cli-${{ matrix.goos }}-${{ matrix.goarch }}
path: |
altmount-cli_v${{ inputs.version }}_${{ matrix.goos }}_${{ matrix.goarch }}.*
retention-days: 1

create-universal-darwin:
runs-on: macos-latest
needs: build-cli
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download darwin-amd64 binary
uses: actions/download-artifact@v8
with:
name: cli-darwin-amd64
path: ./artifacts/

- name: Download darwin-arm64 binary
uses: actions/download-artifact@v8
with:
name: cli-darwin-arm64
path: ./artifacts/

- name: Extract binaries
run: |
cd artifacts
tar -xzf altmount-cli_v${{ inputs.version }}_darwin_amd64.tar.gz
tar -xzf altmount-cli_v${{ inputs.version }}_darwin_arm64.tar.gz

- name: Create universal binary
run: |
lipo -create \
artifacts/altmount-cli-darwin-amd64 \
artifacts/altmount-cli-darwin-arm64 \
-output altmount-cli-darwin-universal

tar -czf "altmount-cli_v${{ inputs.version }}_darwin_universal.tar.gz" altmount-cli-darwin-universal

- name: Upload universal darwin artifact
uses: actions/upload-artifact@v6
with:
name: cli-darwin-universal
path: altmount-cli_v${{ inputs.version }}_darwin_universal.tar.gz
retention-days: 1

publish:
runs-on: ubuntu-latest
needs: [build-cli, create-universal-darwin]
permissions:
contents: write
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Download all CLI artifacts
uses: actions/download-artifact@v8
with:
pattern: cli-*
path: ./artifacts/
merge-multiple: true

- name: Create checksums
run: |
cd artifacts
sha512sum altmount-cli_v${{ inputs.version }}_*.* > checksums-cli.txt
cat checksums-cli.txt

- name: Upload combined artifacts (when not publishing to release)
if: ${{ !inputs.upload-to-release }}
uses: actions/upload-artifact@v6
with:
name: cli-release-bundle
path: |
artifacts/altmount-cli_v${{ inputs.version }}_*.*
artifacts/checksums-cli.txt
retention-days: 7

- name: Attach assets to GitHub Release
if: ${{ inputs.upload-to-release }}
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ inputs.release-tag }}
files: |
artifacts/altmount-cli_v${{ inputs.version }}_*.*
artifacts/checksums-cli.txt
draft: false
prerelease: ${{ inputs.prerelease }}
make_latest: ${{ !inputs.prerelease }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
61 changes: 61 additions & 0 deletions .github/workflows/dev-image.yml
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,67 @@ jobs:
path: frontend/dist
retention-days: 1

prepare-dev-release:
name: Ensure Dev Prerelease Exists
runs-on: ubuntu-latest
needs: build-frontend
permissions:
contents: write
outputs:
short_sha: ${{ steps.sha.outputs.short_sha }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Compute short SHA
id: sha
run: echo "short_sha=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT

- name: Ensure rolling dev prerelease
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create dev \
--prerelease \
--title "Dev Build" \
--notes "Rolling development build from main branch" \
--target main 2>/dev/null \
|| gh release edit dev \
--prerelease \
--target main \
--title "Dev Build" \
--notes "Rolling development build from main branch (commit ${{ github.sha }})"

- name: Delete previous dev assets
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
assets=$(gh release view dev --json assets -q '.assets[].name' || true)
if [ -n "$assets" ]; then
echo "$assets" | while read -r asset; do
[ -z "$asset" ] && continue
echo "Deleting asset: $asset"
gh release delete-asset dev "$asset" --yes || true
done
else
echo "No existing assets on dev release"
fi

publish-dev-binaries:
name: Publish Dev CLI Binaries
needs: prepare-dev-release
permissions:
contents: write
uses: ./.github/workflows/build-cli.yml
with:
version: dev-${{ github.sha }}
commit: ${{ needs.prepare-dev-release.outputs.short_sha }}
upload-to-release: true
release-tag: dev
prerelease: true

build-dev-amd64:
name: Build Dev Image (AMD64)
runs-on: ubuntu-latest
Expand Down
Loading
Loading