Skip to content

Update pre-commit hook pre-commit/pre-commit-hooks to v5 #1643

Update pre-commit hook pre-commit/pre-commit-hooks to v5

Update pre-commit hook pre-commit/pre-commit-hooks to v5 #1643

Workflow file for this run

---
name: CI
on:
push:
branches-ignore:
- gh-pages
pull_request:
branches-ignore:
- gh-pages
workflow_dispatch:
schedule:
- cron: "0 4 * * 1,4"
release:
types:
- published
- created
jobs:
lint:
name: Lint
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
with:
components: clippy,rustfmt
- uses: actions-rs/clippy-check@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
args: --all-features --workspace
- uses: mbrobbel/[email protected]
with:
token: ${{ secrets.GITHUB_TOKEN }}
# cant push to main directly
if: github.ref != 'refs/heads/main'
- name: Run pre-commit checks
uses: pre-commit/[email protected]
docs:
name: "Generate rustdoc"
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
- name: Install cargo-make
uses: taiki-e/install-action@v2
with:
tool: [email protected]
- name: Build docs
run: cargo make docs
build-test:
name: Build and Test (${{ matrix.target.name }})
runs-on: ubuntu-22.04
strategy:
matrix:
target:
- name: aarch64-unknown-linux-gnu
- name: x86_64-unknown-linux-gnu
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
with:
key: "{{ matrix.target.name }}"
- name: Install build tools
uses: taiki-e/install-action@v2
with:
tool: [email protected],[email protected]
- name: Build and Test release binary
run: |
cargo make -p release build-${{ matrix.target.name }}
cargo make -p release test-${{ matrix.target.name }}
- name: Upload binary artifact
uses: actions/upload-artifact@v4
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
with:
name: metallb-dyn6.${{ matrix.target.name }}
path: target/${{ matrix.target.name }}/release/metallb-dyn6
coverage:
name: Create Test Coverage Report
runs-on: ubuntu-22.04
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Install rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Enable cargo caching
uses: Swatinem/rust-cache@v2
- name: Install build tools
uses: taiki-e/install-action@v2
with:
tool: [email protected],[email protected]
- name: Build coverage
run: cargo make coverage
- name: Upload coverage report
uses: codecov/codecov-action@v4
with:
files: ./lcov.info
token: ${{ secrets.CODECOV_TOKEN }}
docker:
name: "Publish Docker Image"
runs-on: ubuntu-22.04
if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/v')
needs:
- build-test
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Create target directories
run: |
mkdir -p target/x86_64-unknown-linux-gnu/release target/aarch64-unknown-linux-gnu/release
- name: Get x86_64-unknown-linux-gnu artifact
uses: actions/download-artifact@v4
with:
name: metallb-dyn6.x86_64-unknown-linux-gnu
path: target/x86_64-unknown-linux-gnu/release/metallb-dyn6
- name: Get aarch64-unknown-linux-gnu artifact
uses: actions/download-artifact@v4
with:
name: metallb-dyn6.aarch64-unknown-linux-gnu
path: target/aarch64-unknown-linux-gnu/release/metallb-dyn6
- name: Login to GHCR
uses: docker/login-action@v3
with:
registry: ghcr.io
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Login to quay.io
uses: docker/login-action@v3
with:
registry: quay.io
username: ${{ secrets.QUAY_USERNAME }}
password: ${{ secrets.QUAY_TOKEN}}
# version is either the major release ('1'), major + minor ('1.2') or full version ('1.2.3-pre.4')
# Note that no tag '0[-arch]' will be generated, as 0.x versions are unstable and should not be relied upon
- name: Generate docker tags
id: tags
uses: docker/metadata-action@v5
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
images: |
ghcr.io/${{ github.repository }}
quay.io/${{ github.repository }}
tags: |
type=semver,pattern={{version}},enable=${{ startsWith(github.ref, 'refs/tags/v')}}
type=semver,pattern={{major}}.{{minor}},enable=${{ startsWith(github.ref, 'refs/tags/v')}}
type=semver,pattern={{major}},enable=${{ startsWith(github.ref, 'refs/tags/v') && !startsWith(github.ref, 'refs/tags/v0.') }}
latest
- name: Build and push
uses: docker/build-push-action@v6
with:
context: .
platforms: linux/amd64,linux/arm64
tags: ${{ steps.tags.outputs.tags }}
push: true
file: Dockerfile.multiarch
gh-release-artifacts:
name: Upload ${{ matrix.target }} to GH Release
if: startsWith(github.ref, 'refs/tags/v')
runs-on: ubuntu-22.04
needs:
- build-test
strategy:
matrix:
target:
- name: aarch64-unknown-linux-gnu
- name: x86_64-unknown-linux-gnu
steps:
- name: Check out codebase
uses: actions/checkout@v4
- name: Get target binary artifact
uses: actions/download-artifact@v4
with:
name: metallb-dyn6.${{ matrix.target.name }}
path: /tmp/metallb-dyn6
- name: Create release asset archive
run: tar cvzf binary.tar.gz --directory=/tmp metallb-dyn6
- name: Upload release artifact
id: upload-release-asset
uses: actions/upload-release-asset@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ github.event.release.upload_url }}
asset_path: binary.tar.gz
asset_name: metallb-dyn6-${{ matrix.target.name }}.tar.gz
asset_content_type: application/tar+gzip