Skip to content

Merge pull request #22 from persevie/chore/test-coverage #7

Merge pull request #22 from persevie/chore/test-coverage

Merge pull request #22 from persevie/chore/test-coverage #7

Workflow file for this run

name: Build and Release
on:
push:
branches:
- main
permissions:
contents: write
jobs:
determine_release:
name: Determine if release is needed
runs-on: ubuntu-latest
outputs:
SHOULD_RELEASE: ${{ steps.release_check.outputs.SHOULD_RELEASE }}
NEW_TAG: ${{ steps.release_check.outputs.NEW_TAG }}
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Determine if release is needed
id: release_check
shell: bash
run: |
git fetch --tags
CURRENT_VERSION=$(grep '^version = ' Cargo.toml | head -n1 | awk -F\" '{print $2}')
echo "Current version: $CURRENT_VERSION"
if git rev-parse "v$CURRENT_VERSION" >/dev/null 2>&1; then
echo "Tag v$CURRENT_VERSION already exists. No release needed."
echo "SHOULD_RELEASE=false" >> $GITHUB_OUTPUT
else
echo "No existing tag for version $CURRENT_VERSION. Release is needed."
echo "SHOULD_RELEASE=true" >> $GITHUB_OUTPUT
echo "NEW_TAG=v$CURRENT_VERSION" >> $GITHUB_OUTPUT
fi
test_coverage:
name: Lint and test
runs-on: ubuntu-latest
needs: determine_release
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Install llvm-tools-preview
run: rustup component add llvm-tools-preview
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-cargo-build-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-build-
- name: Install grcov
run: cargo install grcov
- name: Run tests with coverage
run: ./scripts/coverage.sh
- name: Codecov upload lcov.info
uses: codecov/codecov-action@v4
with:
files: lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
build:
name: Build
runs-on: ${{ matrix.runs-on }}
needs: determine_release
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
strategy:
matrix:
include:
- name: linux_x86_64
runs-on: ubuntu-latest
target: x86_64-unknown-linux-gnu
artifact_name: grimoire_css-linux-x86_64
artifact_path: target/x86_64-unknown-linux-gnu/release/grimoire_css
- name: macos_x86_64
runs-on: macos-latest
target: x86_64-apple-darwin
artifact_name: grimoire_css-macos-x86_64
artifact_path: target/x86_64-apple-darwin/release/grimoire_css
- name: macos_arm64
runs-on: macos-12
target: aarch64-apple-darwin
artifact_name: grimoire_css-macos-arm64
artifact_path: target/aarch64-apple-darwin/release/grimoire_css
- name: windows_x86_64
runs-on: windows-latest
target: x86_64-pc-windows-msvc
artifact_name: grimoire_css-windows-x86_64.exe
artifact_path: target/x86_64-pc-windows-msvc/release/grimoire_css.exe
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
target: ${{ matrix.target }}
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo git
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Cache Cargo build
uses: actions/cache@v4
with:
path: target
key: ${{ runner.os }}-build-${{ matrix.target }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-build-${{ matrix.target }}-
- name: Build project
run: cargo build --release --target ${{ matrix.target }}
- name: Prepare artifact
run: |
mkdir -p artifacts
cp "${{ matrix.artifact_path }}" "artifacts/${{ matrix.artifact_name }}"
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: ${{ matrix.artifact_name }}
path: artifacts/${{ matrix.artifact_name }}
publish:
name: Publish to crates.io
runs-on: ubuntu-latest
needs: [determine_release, build]
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- name: Checkout Code
uses: actions/checkout@v4
- name: Set up Rust
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
- name: Cache Cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-registry-
- name: Cache Cargo git
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: ${{ runner.os }}-cargo-git-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-git-
- name: Publish to crates.io
env:
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}
run: |
cargo login ${{ secrets.CARGO_REGISTRY_TOKEN }}
cargo publish
release:
name: Release
runs-on: ubuntu-latest
needs: [determine_release, publish]
if: needs.determine_release.outputs.SHOULD_RELEASE == 'true'
steps:
- name: Checkout Code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./artifacts
- name: Create and push tag
run: |
git config user.name "${{ github.actor }}"
git config user.email "${{ github.actor }}@users.noreply.github.com"
git tag -a "${{ needs.determine_release.outputs.NEW_TAG }}" -m "Release ${{ needs.determine_release.outputs.NEW_TAG }}"
git push origin "${{ needs.determine_release.outputs.NEW_TAG }}"
- name: Create GitHub Release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ needs.determine_release.outputs.NEW_TAG }}
files: ./artifacts/**/*
body: "Release of Grimoire CSS version ${{ needs.determine_release.outputs.NEW_TAG }}"
draft: false
prerelease: false
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}