Skip to content
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
31 changes: 31 additions & 0 deletions .github/setup/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
name: Shared Setup

description: "Install Rust, checkout code and install dependencies."

inputs:
rust-version:
description: 'Rust toolchain version'
required: false
default: '1.89'


runs:
using: "composite"
steps:
- name: Cache Cargo Dependencies
uses: actions/cache@v4
with:
path: |
~/.cargo
target
key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
${{ runner.os }}-cargo-

- name: Install Rust
uses: actions-rs/toolchain@v1
with:
toolchain: ${{ inputs.rust-version }}
profile: minimal
components: clippy, rustfmt
override: true
63 changes: 63 additions & 0 deletions .github/workflows/build-and-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
name: 'Build and Release'

on:
push:
tags:
- 'v*'

# This workflow will trigger on tags to build and create a release
jobs:
release-build:
runs-on: ubuntu-22.04
steps:
- uses: actions/checkout@v4

- name: Install Rust stable
uses: dtolnay/rust-toolchain@stable

- name: Get version
id: version
shell: bash
run: |
if [[ "${{ github.ref_type }}" == "tag" ]]; then
VERSION="${{ github.ref_name }}"
else
VERSION="v$(grep -m1 '^version' Cargo.toml | cut -d'"' -f2)"
fi
echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Build binary
run: cargo build --release

- name: Rename binary
run: cp target/release/homegate homegate-${{ steps.version.outputs.version }}-linux-amd64

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: linux-x86_64
path: homegate-*
if-no-files-found: error

release:
needs: release-build
if: github.ref_type == 'tag'
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- uses: actions/checkout@v4

- name: Download all artifacts
uses: actions/download-artifact@v4
with:
path: artifacts

- name: Create GitHub Release
uses: softprops/action-gh-release@v2
with:
tag_name: ${{ github.ref_name }}
name: Release ${{ github.ref_name }}
files: artifacts/**/homegate-*
generate_release_notes: true
draft: true
66 changes: 66 additions & 0 deletions .github/workflows/pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
name: PR actions

on:
push:
branches:
- main
pull_request:
branches:
- '**'
# Enable manual trigger
workflow_dispatch:


jobs:
rust-build:
name: Build Rust
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Setup environment
id: setup
uses: ./.github/setup
- name: Build Project
run: cargo build --release

formatting-and-tests:
name: Check formatting and run tests
runs-on: ubuntu-latest
needs: rust-build
services:
postgres:
image: postgres:17-alpine
env:
POSTGRES_USER: test_user
POSTGRES_PASSWORD: test_pass
POSTGRES_DB: postgres
ports: ['5432:5432']
options: >-
--health-cmd="pg_isready -U test_user"
--health-interval=5s
--health-timeout=5s
--health-retries=5
env:
DATABASE_URL: postgres://test_user:test_pass@localhost:5432/postgres?pubky-test=true
steps:
- uses: actions/checkout@v4
- name: Setup environment
id: setup
uses: ./.github/setup

- name: Wait for PostgreSQL
run: |
for i in {1..10}; do
pg_isready -h localhost -p 5432 -U test_user && break
echo "Postgres not ready yet… sleeping"
sleep 3
done

- name: Run Rustfmt (Code Formatting)
run: cargo fmt --all -- --check

- name: Run Clippy (Lint)
run: cargo clippy --all-targets --all-features -- -D warnings

- name: Run tests
run: cargo test --verbose
6 changes: 3 additions & 3 deletions src/sms_verification/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ async fn test_service_session_lifecycle(pool: PgPool) {

// Second send_code - API might return success again, but our code should
// see the existing pending session in DB and not create a duplicate
let _response2 = service
service
.create_verification(
&db,
CreateVerificationRequest {
Expand Down Expand Up @@ -329,7 +329,7 @@ async fn test_service_max_verified_sessions_limits(pool: PgPool) {
ip,
)
.await
.expect(&format!("send_code {} should succeed", i));
.unwrap_or_else(|_| panic!("send_code {} should succeed", i));

service
.validate_code(
Expand All @@ -340,7 +340,7 @@ async fn test_service_max_verified_sessions_limits(pool: PgPool) {
},
)
.await
.expect(&format!("verify_code {} should succeed", i));
.unwrap_or_else(|_| panic!("verify_code {} should succeed", i));
}

// 3rd attempt should fail weekly limit (no mock needed - validation happens before API call)
Expand Down
Loading