Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More CI fixes #2

Merged
merged 4 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
@@ -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
24 changes: 4 additions & 20 deletions .github/workflows/rust.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ name: Rust

on:
push:
tags:
- 'v*'
branches: [main]
pull_request:
workflow_dispatch:
Expand All @@ -25,7 +23,6 @@ jobs:
os:
- ubuntu-latest
- macos-latest
- windows-latest

toolchain:
- 1.77.2
Expand All @@ -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
12 changes: 6 additions & 6 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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:
Expand Down
30 changes: 15 additions & 15 deletions src/slack.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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");
}
}
Loading