diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..1d0e84f --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,57 @@ +name: Release + +on: + pull_request: + push: + tags: + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 + +env: + CARGO_TERM_COLOR: always + CARGO_INCREMENTAL: 0 + CARGO_NET_RETRY: 10 + RUST_BACKTRACE: short + RUSTUP_MAX_RETRIES: 10 + +jobs: + checks: + runs-on: ${{ matrix.os }} + + strategy: + fail-fast: false + matrix: + os: + - ubuntu-latest + + toolchain: + - 1.77.2 + + steps: + - uses: actions/checkout@v2 + - uses: extractions/setup-just@v1 + with: + just-version: 1.25.2 + - uses: Swatinem/rust-cache@v2 + with: + key: ${{ runner.os }}-${{ hashFiles('Cargo.lock') }}-${{ matrix.toolchain }} + - uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.toolchain }} + - name: Install musl tools + run: | + sudo apt-get install -y musl-tools + rustup target add x86_64-unknown-linux-musl + - name: Build Musl binary + run: just cargo-build + - name: Generate artifacts + run: just release-artifacts + - uses: actions/upload-artifact@v3 + with: + name: binaries + path: artifacts/* + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: artifacts/* + generate_release_notes: true diff --git a/.github/workflows/rust.yaml b/.github/workflows/rust.yaml index d321348..a2f0266 100644 --- a/.github/workflows/rust.yaml +++ b/.github/workflows/rust.yaml @@ -2,8 +2,6 @@ name: Rust on: push: - tags: - - 'v*' branches: [main] pull_request: workflow_dispatch: @@ -25,7 +23,6 @@ jobs: os: - ubuntu-latest - macos-latest - - windows-latest toolchain: - 1.77.2 @@ -41,26 +38,13 @@ jobs: with: toolchain: ${{ matrix.toolchain }} components: clippy, rustfmt - targets: x86_64-unknown-linux-musl - uses: Swatinem/rust-cache@v2 - with: - workspaces: | - rust - - name: Dependencies + - name: Musl Dependencies run: sudo apt install musl-tools -y - - name: Compile application - run: just cargo-compile - - name: Build binary - run: just cargo-build + if: runner.os == 'Linux' + - name: Build application + run: just cargo-build-no-target - name: Lint run: | just cargo-clippy-check just cargo-fmt-check - - name: Artifacts - run: just release-artifacts - - name: Release - uses: softprops/action-gh-release@v2 - if: startsWith(github.ref, 'refs/tags/') - with: - files: artifacts/* - generate_release_notes: true diff --git a/justfile b/justfile index ef1d369..eca6565 100644 --- a/justfile +++ b/justfile @@ -2,17 +2,17 @@ default: just --list --unsorted -# Compile application -cargo-compile: - cargo test --release --no-run --locked --target x86_64-unknown-linux-musl - # Build application cargo-build: cargo build --release --locked --target x86_64-unknown-linux-musl +# Build application (default target) +cargo-build-no-target: + cargo build --release --locked + # Clippy check cargo-clippy-check: - cargo clippy --target x86_64-unknown-linux-musl --release --no-deps --workspace --locked --tests -- -Dwarnings + cargo clippy --release --no-deps --workspace --locked --tests -- -Dwarnings # Cargo fmt check cargo-fmt-check: @@ -21,7 +21,7 @@ cargo-fmt-check: # Create release artifacts release-artifacts: mkdir -p artifacts - cp target/x86_64-unknown-linux-musl/release/health-check ./artifacts/ + cp target/x86_64-unknown-linux-musl/release/health-check ./artifacts/health-check-x86_64-unknown-linux-musl # Test 1: Will raise alert to slack test1: diff --git a/src/slack.rs b/src/slack.rs index 3e3e735..b485da8 100644 --- a/src/slack.rs +++ b/src/slack.rs @@ -20,21 +20,6 @@ fn readable_image_id(version: &str) -> &str { } } -#[cfg(test)] -mod tests { - use crate::slack::readable_image_id; - - #[test] - fn guess_readable_image_id_works() { - let image_id = - readable_image_id("ghcr.io/fpco/some-app:d5def5afc6030dda860a79f231b295e2e412bc28"); - assert_eq!(image_id, "d5def5afc6030dda860a79f231b295e2e412bc28"); - - let image_id = readable_image_id("d5def5afc6030dda860a79f231b295e2e412bc28"); - assert_eq!(image_id, "d5def5afc6030dda860a79f231b295e2e412bc28"); - } -} - impl SlackApp { pub(crate) fn new( webhook: Url, @@ -120,3 +105,18 @@ impl SlackApp { } } } + +#[cfg(test)] +mod tests { + use crate::slack::readable_image_id; + + #[test] + fn guess_readable_image_id_works() { + let image_id = + readable_image_id("ghcr.io/fpco/some-app:d5def5afc6030dda860a79f231b295e2e412bc28"); + assert_eq!(image_id, "d5def5afc6030dda860a79f231b295e2e412bc28"); + + let image_id = readable_image_id("d5def5afc6030dda860a79f231b295e2e412bc28"); + assert_eq!(image_id, "d5def5afc6030dda860a79f231b295e2e412bc28"); + } +}