Skip to content

Build and Release start-cli #28

Build and Release start-cli

Build and Release start-cli #28

Workflow file for this run

name: Cross-Platform CLI Builder
on:
push:
tags:
- "v*"
workflow_dispatch:
permissions:
contents: write
actions: read
jobs:
prepare:
name: Prepare Release
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get-version.outputs.version }}
tag_exists: ${{ steps.check-tag.outputs.exists }}
tag_name: ${{ steps.get-tag.outputs.tag_name }}
steps:
- name: Checkout start-os
uses: actions/checkout@v4
with:
repository: start9labs/start-os
ref: next/major
path: start-os
submodules: recursive
- name: Extract version from Cargo.toml
id: get-version
run: |
VERSION=$(grep -m 1 'version = ' ./start-os/core/startos/Cargo.toml | sed 's/version = "\(.*\)".*/\1/')
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "Extracted version: $VERSION"
- name: Determine tag name
id: get-tag
run: |
TAG_NAME="v${{ steps.get-version.outputs.version }}"
echo "tag_name=$TAG_NAME" >> $GITHUB_OUTPUT
echo "Tag name: $TAG_NAME"
- name: Check if tag exists
id: check-tag
run: |
if [[ "${{ github.event_name }}" == "push" && "${{ github.ref_type }}" == "tag" ]]; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag exists (triggered by tag push)"
else
if git ls-remote --tags https://github.com/${{ github.repository }} | grep -q "refs/tags/${{ steps.get-tag.outputs.tag_name }}"; then
echo "exists=true" >> $GITHUB_OUTPUT
echo "Tag already exists in repository"
else
echo "exists=false" >> $GITHUB_OUTPUT
echo "Tag does not exist yet"
fi
fi
- name: Create tag if needed
if: ${{ github.event_name == 'workflow_dispatch' && steps.check-tag.outputs.exists == 'false' }}
run: |
git config --global user.name "GitHub Actions"
git config --global user.email "actions@github.com"
git clone https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} repo
cd repo
git tag ${{ steps.get-tag.outputs.tag_name }}
git push origin ${{ steps.get-tag.outputs.tag_name }}
echo "Created tag: ${{ steps.get-tag.outputs.tag_name }}"
build:
name: Build ${{ matrix.target }}
needs: prepare
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-apple-darwin
os: macos-13-large
rust_target: x86_64-apple-darwin
- target: aarch64-apple-darwin
os: macos-13-xlarge
rust_target: aarch64-apple-darwin
- target: x86_64-unknown-linux-gnu
os: ubuntu-22.04
rust_target: x86_64-unknown-linux-gnu
- target: aarch64-unknown-linux-gnu
os: ubuntu-22.04-arm
rust_target: aarch64-unknown-linux-gnu
steps:
- name: Checkout start-os
uses: actions/checkout@v4
with:
repository: start9labs/start-os
ref: next/major
path: start-os
submodules: recursive
- name: Setup Rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
toolchain: stable
targets: ${{ matrix.rust_target }}
- name: Cache Rust dependencies
uses: Swatinem/rust-cache@v2
- name: Build CLI
working-directory: ./start-os
env:
ARCH: ${{ matrix.rust_target }}
run: |
make cli
mkdir -p ../artifacts
cp ~/.cargo/bin/start-cli ../artifacts/start-cli-${{ matrix.target }}
- name: Create archive and generate SHA256
working-directory: artifacts
run: |
tar -czf start-cli-${{ matrix.target }}.tar.gz start-cli-${{ matrix.target }}
shasum -a 256 start-cli-${{ matrix.target }}.tar.gz > start-cli-${{ matrix.target }}.tar.gz.sha256
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: cli-binaries-${{ matrix.target }}
path: artifacts/
release:
name: Create Release
runs-on: ubuntu-latest
needs: [prepare, build]
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
pattern: cli-binaries-*
path: release-binaries
merge-multiple: true
- name: Verify artifacts and combine checksums
working-directory: release-binaries
run: |
echo "Downloaded binaries:"
ls -lh *
cat *.sha256 > sha256sums.txt
echo "SHA256 checksums:"
cat sha256sums.txt
- name: Generate release notes
working-directory: release-binaries
run: |
TAG_NAME="${{ needs.prepare.outputs.tag_name }}"
echo "## Start CLI $TAG_NAME" > release-notes.txt
echo "" >> release-notes.txt
echo "### SHA256 Checksums" >> release-notes.txt
echo '```' >> release-notes.txt
cat sha256sums.txt >> release-notes.txt
echo '```' >> release-notes.txt
- name: Create Release
uses: softprops/action-gh-release@v2
with:
files: |
release-binaries/start-cli-*.tar.gz
release-binaries/sha256sums.txt
name: Start CLI ${{ needs.prepare.outputs.tag_name }}
tag_name: ${{ needs.prepare.outputs.tag_name }}
body_path: release-binaries/release-notes.txt
generate_release_notes: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}