From 47f87cb472eb5e300d9d52f8cf12db8e5e38b26a Mon Sep 17 00:00:00 2001 From: hopeyen Date: Tue, 12 Dec 2023 10:54:51 -0600 Subject: [PATCH] ci: add workflows to test, build containers and binaries --- .github/workflows/containers.yml | 63 +++++++++++++++++++++++++ .github/workflows/gen-binaries.yml | 48 +++++++++++++++++++ .github/{ => workflows}/release.yml | 2 +- .github/workflows/tests.yml | 71 +++++++++++++++++++++++++++++ 4 files changed, 183 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/containers.yml create mode 100644 .github/workflows/gen-binaries.yml rename .github/{ => workflows}/release.yml (94%) create mode 100644 .github/workflows/tests.yml diff --git a/.github/workflows/containers.yml b/.github/workflows/containers.yml new file mode 100644 index 0000000..6ae9959 --- /dev/null +++ b/.github/workflows/containers.yml @@ -0,0 +1,63 @@ +name: Build and upload Docker image + +on: + push: + tags: + - "*.*.*" + branches: + - main + pull_request: + branches: + - main + - dev + +env: + REGISTRY: ghcr.io/${{ github.repository_owner }} + +jobs: + builds-linux: + runs-on: ubuntu-latest + + strategy: + matrix: + target: [subfile-exchange] + + permissions: + packages: write + + steps: + - name: Checkout + uses: actions/checkout@v3 + + - name: Docker meta + id: meta + uses: docker/metadata-action@v4 + with: + # list of Docker images to use as base name for tags + images: | + ${{ env.REGISTRY }}/${{matrix.target}} + # generate Docker tags based on the following events/attributes + tags: | + type=schedule + type=ref,event=branch + type=ref,event=pr + type=semver,pattern={{version}} + type=semver,pattern={{major}}.{{minor}} + type=semver,pattern={{major}}.{{minor}}.{{patch}} + type=semver,pattern={{major}} + type=sha + + - name: Log in to the Container registry + uses: docker/login-action@465a07811f14bebb1938fbed4728c6a1ff8901fc + with: + registry: ${{ env.REGISTRY }} + username: ${{ github.actor }} + password: ${{ secrets.GITHUB_TOKEN }} + + - name: Build and push + uses: docker/build-push-action@v4 + with: + context: ./ + push: true + tags: ${{ steps.meta.outputs.tags }} + file: Dockerfile.${{ matrix.target }} diff --git a/.github/workflows/gen-binaries.yml b/.github/workflows/gen-binaries.yml new file mode 100644 index 0000000..123c0e5 --- /dev/null +++ b/.github/workflows/gen-binaries.yml @@ -0,0 +1,48 @@ +name: Build and upload release binaries + +on: + release: + types: [published] + +jobs: + build-linux: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Build release binary + run: | + cargo build --release + - name: Upload Ubuntu binary + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./target/release/subfile-exchange + asset_name: subfile-exchange-${{ github.event.release.tag_name }}-ubuntu + asset_content_type: binary/octet-stream + build-macos: + runs-on: macos-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + - name: Build release binary + run: | + cargo build --release + - name: Upload MacOS binary + uses: actions/upload-release-asset@v1.0.1 + env: + GITHUB_TOKEN: ${{ secrets.RELEASE_TOKEN }} + with: + upload_url: ${{ github.event.release.upload_url }} + asset_path: ./target/release/subfile-exchange + asset_name: subfile-exchange-${{ github.event.release.tag_name }}-macos + asset_content_type: binary/octet-stream diff --git a/.github/release.yml b/.github/workflows/release.yml similarity index 94% rename from .github/release.yml rename to .github/workflows/release.yml index 8711833..a74ec84 100644 --- a/.github/release.yml +++ b/.github/workflows/release.yml @@ -28,6 +28,6 @@ changelog: - title: Refactor 🌱 labels: - refactor - - title: Other Changes + - title: Other Changes 🗳️ labels: - "*" diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml new file mode 100644 index 0000000..86bbcd1 --- /dev/null +++ b/.github/workflows/tests.yml @@ -0,0 +1,71 @@ +name: tests + +on: + push: + branches: [ main, dev ] + pull_request: + workflow_dispatch: + +jobs: + fmt: + name: cargo fmt + runs-on: ubuntu-latest + container: + image: rust:1.74-bookworm + steps: + - uses: actions/checkout@v3 + - run: | + rustup component add rustfmt + cargo fmt --all -- --check + + clippy: + name: cargo clippy + runs-on: ubuntu-latest + container: + image: rust:1.74-bookworm + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-clippy-${{ hashFiles('**/Cargo.lock') }} + - run: | + rustup component add clippy + # Temporarily allowing dead-code, while denying all other warnings + cargo clippy --all-features --all-targets -- -A dead-code -D warnings + + test-and-coverage: + name: cargo test and coverage + runs-on: ubuntu-latest + permissions: + contents: write + pull-requests: write + actions: read + container: + image: rust:1.74-bookworm + steps: + - uses: actions/checkout@v3 + - uses: actions/cache@v3 + with: + path: | + ~/.cargo/bin/ + ~/.cargo/registry/index/ + ~/.cargo/registry/cache/ + ~/.cargo/git/db/ + target/ + key: ${{ runner.os }}-cargo-test-${{ hashFiles('**/Cargo.lock') }} + - name: Install cargo-llvm-cov + uses: taiki-e/install-action@cargo-llvm-cov + - name: Run tests and generate coverage report + run: cargo llvm-cov test --all-features --workspace --lcov --output-path lcov.info + - name: Test documentation code snippets + run: cargo test --doc --all-features --workspace + - name: Upload coverage to Coveralls + uses: coverallsapp/github-action@v2.2.0 + with: + file: ./lcov.info