Skip to content

Merge pull request #7 from bordeux/hotfix/fix-ci-cd #6

Merge pull request #7 from bordeux/hotfix/fix-ci-cd

Merge pull request #7 from bordeux/hotfix/fix-ci-cd #6

Workflow file for this run

name: Release
on:
push:
branches:
- master
- main
permissions:
contents: write
packages: write
jobs:
semantic-release:
name: Semantic Release
runs-on: ubuntu-latest
outputs:
new_release_published: ${{ steps.semantic.outputs.new_release_published }}
new_release_version: ${{ steps.semantic.outputs.new_release_version }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
persist-credentials: false
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
- name: Install dependencies
run: npm ci
- name: Run semantic-release
id: semantic
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
HUSKY: 0
run: |
# Get current tags
BEFORE_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
# Run semantic-release
npx semantic-release 2>&1 | tee release-output.log
# Check if a new tag was created
AFTER_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "none")
if [ "$BEFORE_TAG" != "$AFTER_TAG" ] && [ "$AFTER_TAG" != "none" ]; then
echo "new_release_published=true" >> $GITHUB_OUTPUT
VERSION=$(echo "$AFTER_TAG" | sed 's/^v//')
echo "new_release_version=$VERSION" >> $GITHUB_OUTPUT
echo "✅ Release published: $VERSION"
else
echo "new_release_published=false" >> $GITHUB_OUTPUT
echo "ℹ️ No release published"
fi
- name: Output release info
run: |
echo "New release published: ${{ steps.semantic.outputs.new_release_published }}"
echo "New release version: ${{ steps.semantic.outputs.new_release_version }}"
build:
name: Build ${{ matrix.target }}
needs: semantic-release
if: needs.semantic-release.outputs.new_release_published == 'true'
runs-on: ${{ matrix.os }}
strategy:
matrix:
include:
- target: x86_64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-x86_64
- target: x86_64-unknown-linux-musl
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-x86_64-musl
- target: aarch64-unknown-linux-gnu
os: ubuntu-latest
artifact_name: tmpltool
asset_name: tmpltool-linux-aarch64
- target: x86_64-apple-darwin
os: macos-latest
artifact_name: tmpltool
asset_name: tmpltool-macos-x86_64
- target: aarch64-apple-darwin
os: macos-latest
artifact_name: tmpltool
asset_name: tmpltool-macos-aarch64
- target: x86_64-pc-windows-msvc
os: windows-latest
artifact_name: tmpltool.exe
asset_name: tmpltool-windows-x86_64.exe
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.semantic-release.outputs.new_release_version }}
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: ${{ matrix.target }}
- name: Install cross (Linux ARM)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cargo install cross --git https://github.com/cross-rs/cross
- name: Install musl tools (Linux musl)
if: matrix.target == 'x86_64-unknown-linux-musl'
run: |
sudo apt-get update
sudo apt-get install -y musl-tools
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-${{ matrix.target }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-${{ matrix.target }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-${{ matrix.target }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }}
- name: Build (cross)
if: matrix.target == 'aarch64-unknown-linux-gnu'
run: cross build --release --target ${{ matrix.target }}
- name: Build (cargo)
if: matrix.target != 'aarch64-unknown-linux-gnu'
run: cargo build --release --target ${{ matrix.target }}
- name: Strip binary (Linux/macOS)
if: matrix.os != 'windows-latest'
run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} || true
- name: Create archive (Linux/macOS)
if: matrix.os != 'windows-latest'
run: |
cd target/${{ matrix.target }}/release
tar czf ${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }}
mv ${{ matrix.asset_name }}.tar.gz ../../..
- name: Create archive (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
cd target/${{ matrix.target }}/release
Compress-Archive -Path ${{ matrix.artifact_name }} -DestinationPath ../../../${{ matrix.asset_name }}.zip
- name: Upload artifact (Linux/macOS)
if: matrix.os != 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.tar.gz
- name: Upload artifact (Windows)
if: matrix.os == 'windows-latest'
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.asset_name }}
path: ${{ matrix.asset_name }}.zip
upload-release-assets:
name: Upload Release Assets
needs: [semantic-release, build]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts
- name: Display structure
run: ls -R artifacts
- name: Upload release assets
uses: softprops/action-gh-release@v1
with:
tag_name: v${{ needs.semantic-release.outputs.new_release_version }}
files: artifacts/**/*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
docker:
name: Build and Push Docker Image
needs: [semantic-release, build]
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
ref: v${{ needs.semantic-release.outputs.new_release_version }}
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v5
with:
images: ghcr.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=semver,pattern={{major}}.{{minor}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=semver,pattern={{major}},value=${{ needs.semantic-release.outputs.new_release_version }}
type=raw,value=latest
- name: Build and push
uses: docker/build-push-action@v5
with:
context: .
push: true
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
platforms: linux/amd64,linux/arm64
cache-from: type=gha
cache-to: type=gha,mode=max