From 97937eb28ccc6d2c8ff61638a38b02b811919c36 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Sat, 30 Nov 2024 14:36:26 -0600 Subject: [PATCH 1/2] Github actions --- .github/workflows/master.yml | 100 ++++++++++++++++++++++++++++++++++ .github/workflows/pr.yml | 102 +++++++++++++++++++++++++++++++++++ .gitignore | 6 ++- 3 files changed, 207 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/master.yml create mode 100644 .github/workflows/pr.yml diff --git a/.github/workflows/master.yml b/.github/workflows/master.yml new file mode 100644 index 0000000..efce2ac --- /dev/null +++ b/.github/workflows/master.yml @@ -0,0 +1,100 @@ +name: Master Branch CI + +on: + push: + branches: [ "main", "master" ] + paths-ignore: + - '**.md' + - 'docs/**' + - '.gitignore' + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-D warnings" + +jobs: + test-and-lint: + name: Test and Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 + components: clippy, rustfmt + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-directories: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev + + - name: Run tests + run: cargo test + + - name: Check formatting + run: cargo fmt --all -- --check + + - name: Run clippy + run: cargo clippy --all-targets + + build: + name: Build Release (${{ matrix.target }}) + runs-on: ubuntu-latest + needs: test-and-lint + strategy: + matrix: + include: + - target: x86_64-unknown-linux-gnu + artifact_name: ghost-resend-mailer-x86_64-linux + - target: aarch64-unknown-linux-gnu + artifact_name: ghost-resend-mailer-aarch64-linux + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 + targets: ${{ matrix.target }} + + - name: Install cross-compilation dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev + if [ "${{ matrix.target }}" = "aarch64-unknown-linux-gnu" ]; then + sudo apt-get install -y gcc-aarch64-linux-gnu + fi + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-directories: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + + - name: Install cross + run: cargo install cross --git https://github.com/cross-rs/cross + + - name: Build release + run: cross build --release --target ${{ matrix.target }} + + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + name: ${{ matrix.artifact_name }} + path: target/${{ matrix.target }}/release/ghost-resend-mailer + retention-days: 7 diff --git a/.github/workflows/pr.yml b/.github/workflows/pr.yml new file mode 100644 index 0000000..b7330bf --- /dev/null +++ b/.github/workflows/pr.yml @@ -0,0 +1,102 @@ +name: Pull Request Checks + +on: + pull_request: + branches: [ "main", "master" ] + paths-ignore: + - '**.md' + - 'docs/**' + - '.gitignore' + +env: + CARGO_TERM_COLOR: always + RUSTFLAGS: "-D warnings" + +jobs: + check: + name: Check + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-directories: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev + + - name: Run cargo check + run: cargo check --all-targets + + test: + name: Test Suite + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-directories: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev + + - name: Run cargo test + run: cargo test + + lints: + name: Lints + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust toolchain + uses: dtolnay/rust-toolchain@master + with: + toolchain: 1.78.0 + components: clippy, rustfmt + + - name: Cache dependencies + uses: Swatinem/rust-cache@v2 + with: + cache-directories: | + ~/.cargo/registry/index + ~/.cargo/registry/cache + ~/.cargo/git + target + + - name: Install dependencies + run: | + sudo apt-get update + sudo apt-get install -y pkg-config libssl-dev + + - name: Run cargo fmt + run: cargo fmt --all -- --check + + - name: Run cargo clippy + run: cargo clippy --all-targets diff --git a/.gitignore b/.gitignore index 86a1361..321fe55 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,6 @@ +/target +**/*.rs.bk +Cargo.lock .env -target/* +.env.* +.DS_Store From 8a2865bf5480b11938c9e521e35b970af434b223 Mon Sep 17 00:00:00 2001 From: Tony Giorgio Date: Sat, 30 Nov 2024 14:38:47 -0600 Subject: [PATCH 2/2] Clippy fix --- src/config.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/config.rs b/src/config.rs index a53089a..089f480 100644 --- a/src/config.rs +++ b/src/config.rs @@ -20,8 +20,9 @@ impl Config { .map_err(|_| anyhow::anyhow!("GHOST_URL environment variable not found"))?, ghost_admin_id: std::env::var("GHOST_ADMIN_ID") .map_err(|_| anyhow::anyhow!("GHOST_ADMIN_ID environment variable not found"))?, - ghost_admin_secret: std::env::var("GHOST_ADMIN_SECRET") - .map_err(|_| anyhow::anyhow!("GHOST_ADMIN_SECRET environment variable not found"))?, + ghost_admin_secret: std::env::var("GHOST_ADMIN_SECRET").map_err(|_| { + anyhow::anyhow!("GHOST_ADMIN_SECRET environment variable not found") + })?, webhook_secret: std::env::var("WEBHOOK_SECRET") .map_err(|_| anyhow::anyhow!("WEBHOOK_SECRET environment variable not found"))?, resend_api_key: std::env::var("RESEND_API_KEY") @@ -35,4 +36,3 @@ impl Config { }) } } -