From f857870b27b8feac13bae28de7371ef193d7a7ff Mon Sep 17 00:00:00 2001 From: AlphaKeks Date: Fri, 10 Jan 2025 07:45:06 +0100 Subject: [PATCH] Refactor CI setup --- .github/workflows/check.yaml | 46 ++++++++-------------------------- .github/workflows/docker.yaml | 24 ++++++++++++++++++ .github/workflows/nix.yaml | 21 ---------------- .github/workflows/openapi.yaml | 2 +- flake.nix | 26 +++++++++++-------- 5 files changed, 50 insertions(+), 69 deletions(-) create mode 100644 .github/workflows/docker.yaml delete mode 100644 .github/workflows/nix.yaml diff --git a/.github/workflows/check.yaml b/.github/workflows/check.yaml index d924225d..00f135af 100644 --- a/.github/workflows/check.yaml +++ b/.github/workflows/check.yaml @@ -3,14 +3,14 @@ # - fmt: checks that the code is formatted according to rustfmt # - clippy: checks that the code does not contain any clippy warnings -name: check +name: Checks permissions: contents: read on: push: - branches: ['master', 'take1337'] + branches: ['master'] pull_request: # If new code is pushed to a PR branch, then cancel in progress workflows for that PR. @@ -19,40 +19,14 @@ concurrency: group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} cancel-in-progress: true -env: - CARGO_TERM_COLOR: 'always' - SQLX_OFFLINE: '1' - jobs: - clippy: - name: clippy - runs-on: ubuntu-latest - permissions: - contents: read - checks: write - strategy: - fail-fast: false - steps: - - uses: actions/checkout@v4 - - name: Install Rust Nightly - uses: dtolnay/rust-toolchain@nightly - with: - components: clippy - - uses: Swatinem/rust-cache@v2 - - name: cargo clippy - run: | - cargo +nightly clippy --workspace --all-features --no-deps -- -Dwarnings - cargo +nightly clippy --workspace --tests --no-deps -- -Dwarnings - - rustfmt: - name: rustfmt + checks: + name: nix flake check runs-on: ubuntu-latest steps: - - uses: actions/checkout@v4 - - name: Install Rust Nightly - uses: dtolnay/rust-toolchain@nightly - with: - components: rustfmt - - uses: Swatinem/rust-cache@v2 - - name: cargo fmt - run: cargo +nightly fmt --all --check + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flake-checker-action@main + - name: checks + run: nix flake check .# diff --git a/.github/workflows/docker.yaml b/.github/workflows/docker.yaml new file mode 100644 index 00000000..369a31cf --- /dev/null +++ b/.github/workflows/docker.yaml @@ -0,0 +1,24 @@ +name: Docker Image + +permissions: + contents: read + +on: + push: + branches: ['master'] + +jobs: + docker-image: + name: Docker Image + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: DeterminateSystems/nix-installer-action@main + - uses: DeterminateSystems/magic-nix-cache-action@main + - uses: DeterminateSystems/flake-checker-action@main + - name: checks + run: nix build .#dockerImage -o cs2kz-api.image + - uses: actions/upload-artifact@v4 + with: + name: cs2kz-api.image + path: cs2kz-api.image diff --git a/.github/workflows/nix.yaml b/.github/workflows/nix.yaml deleted file mode 100644 index de7b765a..00000000 --- a/.github/workflows/nix.yaml +++ /dev/null @@ -1,21 +0,0 @@ -name: Nix - -permissions: - contents: read - -on: - push: - branches: ['master', 'take1337'] - pull_request: - -jobs: - nix: - name: Nix - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: cachix/install-nix-action@v25 - with: - nix_path: nixpkgs=channel:nixos-24.11 - - uses: DeterminateSystems/magic-nix-cache-action@v2 - - run: nix flake check diff --git a/.github/workflows/openapi.yaml b/.github/workflows/openapi.yaml index c791dc48..ea2c3b61 100644 --- a/.github/workflows/openapi.yaml +++ b/.github/workflows/openapi.yaml @@ -5,7 +5,7 @@ permissions: on: push: - branches: ['master', 'take1337'] + branches: ['master'] jobs: openapi: diff --git a/flake.nix b/flake.nix index 1e190fdb..357fd3c5 100644 --- a/flake.nix +++ b/flake.nix @@ -35,7 +35,21 @@ extensions = [ "clippy" "rustfmt" ]; })); - src = craneLib.cleanCargoSource ./.; + mkFileSet = files: nixpkgs.lib.fileset.toSource { + root = ./.; + fileset = nixpkgs.lib.fileset.unions (files ++ [ + (craneLib.fileset.commonCargoSources ./.) + ./crates/cs2kz/migrations + ./.sqlx + ./.example.env + ]); + }; + + fileSetForCrate = crate: mkFileSet [ + (craneLib.fileset.commonCargoSources crate) + ]; + + src = mkFileSet []; commonArgs = { inherit src; @@ -53,16 +67,6 @@ inherit (craneLib.crateNameFromCargoToml { inherit src; }) version; }; - fileSetForCrate = crate: nixpkgs.lib.fileset.toSource { - root = ./.; - fileset = nixpkgs.lib.fileset.unions [ - (craneLib.fileset.commonCargoSources ./.) - ./crates/cs2kz/migrations - ./.sqlx - ./.example.env - ]; - }; - cs2kz-api = craneLib.buildPackage (crateArgs // { pname = "cs2kz-api"; src = fileSetForCrate ./crates/cs2kz-api;