Docker builds and optimized CI workflow #488
Workflow file for this run
This file contains 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
name: CI checks | |
on: | |
push: | |
pull_request: | |
jobs: | |
deps-cache: | |
name: Cache Dependencies | |
runs-on: ${{ vars.RUNNER_TYPE || 'ubuntu-latest' }} | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: actions-rs/toolchain@v1 | |
with: | |
profile: minimal | |
toolchain: stable | |
- name: Cache Rust dependencies | |
uses: actions/cache@v3 | |
id: cache | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-v1-${{ hashFiles('**/Cargo.lock') }} | |
restore-keys: | | |
${{ runner.os }}-cargo-v1- | |
- name: Fetch dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: cargo fetch | |
- name: Quick compilation check | |
run: cargo check --all-targets | |
- name: Build dependencies | |
if: steps.cache.outputs.cache-hit != 'true' | |
run: cargo build --all-targets | |
# Uncomment this when tests are passing | |
# test: | |
# needs: deps-cache | |
# name: Run Tests | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v4 | |
# - name: Restore cache | |
# uses: actions/cache@v3 | |
# with: | |
# path: | | |
# ~/.cargo/registry | |
# ~/.cargo/git | |
# target | |
# key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
# - name: Run tests | |
# run: cargo test --workspace --release | |
# - name: Run slow tests | |
# run: cargo test --workspace --release -- --ignored | |
clippy: | |
needs: deps-cache | |
name: Clippy | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Run clippy with console output | |
run: cargo clippy --all-targets | |
continue-on-error: true | |
- name: Output clippy to Github | |
uses: actions-rs/clippy-check@v1 | |
# Remove when clippy is green in local dev environments | |
continue-on-error: true | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
args: --all-targets | |
fmt: | |
needs: deps-cache | |
name: Rustfmt | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Restore cache | |
uses: actions/cache@v3 | |
with: | |
path: | | |
~/.cargo/registry | |
~/.cargo/git | |
target | |
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} | |
- name: Check formatting | |
run: cargo fmt --all -- --check | |
docker: | |
name: Build Docker image, push if tagged | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to DockerHub | |
uses: docker/login-action@v3 | |
with: | |
username: ${{ secrets.DOCKERHUB_USERNAME }} | |
password: ${{ secrets.DOCKERHUB_TOKEN }} | |
- name: Extract metadata for Docker | |
id: meta | |
uses: docker/metadata-action@v5 | |
with: | |
images: ${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_REPO || 'zaino' }} | |
tags: | | |
type=ref,event=branch | |
type=ref,event=pr | |
type=semver,pattern={{version}} | |
type=semver,pattern={{major}}.{{minor}} | |
type=sha | |
- name: Docker Build, push if tagged | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
platforms: linux/amd64 | |
push: ${{ startsWith(github.ref, 'refs/tags/') }} | |
tags: ${{ steps.meta.outputs.tags }} | |
labels: ${{ steps.meta.outputs.labels }} | |
cache-from: | | |
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_REPO || 'zaino' }}:buildcache | |
type=gha | |
cache-to: | | |
type=registry,ref=${{ secrets.DOCKERHUB_USERNAME }}/${{ vars.DOCKER_REPO || 'zaino' }}:buildcache,mode=max | |
type=gha,mode=max | |
create-release: | |
needs: docker | |
name: Create GitHub Release | |
runs-on: ubuntu-latest | |
if: startsWith(github.ref, 'refs/tags/') && github.token != '' | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
fetch-depth: 0 | |
- name: Generate Changelog | |
id: changelog | |
run: | | |
PREVIOUS_TAG=$(git describe --tags --abbrev=0 HEAD^ 2>/dev/null || echo "") | |
if [ -z "$PREVIOUS_TAG" ]; then | |
git log --pretty=format:"* %s" > CHANGELOG.md | |
else | |
git log --pretty=format:"* %s" $PREVIOUS_TAG..HEAD > CHANGELOG.md | |
fi | |
- name: Create Release | |
uses: softprops/action-gh-release@v1 | |
with: | |
files: | | |
CHANGELOG.md | |
body_path: CHANGELOG.md | |
draft: false | |
prerelease: false | |
token: ${{ secrets.GITHUB_TOKEN }} |