🔧 Modernize CI/CD pipeline with updated actions #101
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# This workflow handles continuous integration and deployment for the Git-Iris project. | |
# It runs tests and builds for all pushes, and creates releases for tagged pushes. | |
name: CI/CD | |
on: | |
push: | |
branches: | |
- main # Trigger on pushes to main branch | |
tags: | |
- "v*.*.*" # Trigger on version tags | |
pull_request: | |
branches: | |
- main # Trigger on pull requests to main branch | |
jobs: | |
# This job runs for all pushes and pull requests | |
build-and-test: | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- build: linux-amd64 | |
os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
cmd: cargo | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Rust cache | |
uses: Swatinem/rust-cache@v2 | |
with: | |
key: ${{ matrix.os }}-${{ matrix.target }} | |
- name: Build | |
run: ${{ matrix.cmd }} build --verbose --locked --target ${{ matrix.target }} | |
- name: Run tests | |
run: ${{ matrix.cmd }} test --verbose --locked --target ${{ matrix.target }} | |
# The following jobs only run on tag pushes (i.e., releases) | |
build-artifacts: | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: build-and-test | |
runs-on: ${{ matrix.os }} | |
strategy: | |
matrix: | |
include: | |
- build: linux-amd64 | |
os: ubuntu-latest | |
target: x86_64-unknown-linux-gnu | |
binary_name: git-iris | |
- build: windows-gnu | |
os: windows-latest | |
target: x86_64-pc-windows-gnu | |
binary_name: git-iris.exe | |
# Disabled macos-arm64 due to segfault in tests | |
# - build: macos-arm64 | |
# os: macos-latest | |
# target: aarch64-apple-darwin | |
# binary_name: git-iris | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: ${{ matrix.target }} | |
- name: Rust cache | |
uses: Swatinem/rust-cache@v2 | |
with: | |
key: ${{ matrix.os }}-${{ matrix.target }}-release | |
- name: Build release binary | |
run: cargo build --verbose --locked --release --target ${{ matrix.target }} | |
- name: Upload artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: git-iris-${{ matrix.build }} | |
path: ./target/${{ matrix.target }}/release/${{ matrix.binary_name }} | |
if-no-files-found: error | |
retention-days: 1 | |
build-packages: | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: build-and-test | |
runs-on: ubuntu-latest | |
outputs: | |
version: ${{ steps.get_version.outputs.VERSION }} | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Get version | |
id: get_version | |
run: echo "VERSION=${GITHUB_REF_NAME#v}" >> $GITHUB_OUTPUT | |
- name: Install Rust | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- name: Rust cache | |
uses: Swatinem/rust-cache@v2 | |
# Build DEB package | |
- name: Install cargo-deb | |
run: cargo install cargo-deb | |
- name: Build .deb package | |
run: cargo deb | |
- name: Upload DEB artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: git-iris-deb | |
path: ./target/debian/git-iris_${{ steps.get_version.outputs.VERSION }}-1_amd64.deb | |
if-no-files-found: error | |
retention-days: 1 | |
# Build RPM package | |
- name: Install cargo-generate-rpm | |
run: cargo install cargo-generate-rpm | |
- name: Build Release Binary for RPM | |
run: cargo build --release | |
- name: Build .rpm package | |
run: cargo generate-rpm | |
- name: Upload RPM artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: git-iris-rpm | |
path: ./target/generate-rpm/git-iris-${{ steps.get_version.outputs.VERSION }}-1.x86_64.rpm | |
if-no-files-found: error | |
retention-days: 1 | |
# Upload man page as artifact | |
- name: Upload man page artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: git-iris-man | |
path: ./git-iris.1 | |
if-no-files-found: error | |
retention-days: 1 | |
create-release: | |
if: startsWith(github.ref, 'refs/tags/') | |
needs: [build-artifacts, build-packages] | |
runs-on: ubuntu-latest | |
permissions: | |
contents: write | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Download all artifacts | |
uses: actions/download-artifact@v4 | |
with: | |
path: ./artifacts | |
- name: Prepare release assets | |
run: | | |
mkdir -p release-assets | |
find ./artifacts -type f -exec cp {} ./release-assets/ \; | |
ls -la ./release-assets | |
- name: Create GitHub Release | |
uses: softprops/action-gh-release@v2 | |
with: | |
name: Release ${{ github.ref_name }} | |
draft: false | |
prerelease: false | |
files: | | |
./release-assets/* | |
generate_release_notes: true |