Add mailersend #52
Workflow file for this run
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build, Test & Push to GHCR | |
on: | |
push: | |
branches: | |
- main | |
pull_request: | |
branches: | |
- main | |
types: [opened, synchronize, reopened] | |
workflow_dispatch: | |
permissions: | |
contents: read | |
env: | |
CARGO_TERM_COLOR: always | |
CARGO_INCREMENTAL: 1 | |
RUST_BACKTRACE: short | |
REGISTRY: ghcr.io | |
IMAGE_NAME: ${{ github.repository }} | |
jobs: | |
# === LINT JOB (Fast Feedback) === | |
lint: | |
name: Lint & Format | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
components: clippy, rustfmt | |
- name: Use cached dependencies | |
uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: "main" | |
key: "lint" | |
cache-all-crates: true | |
- name: Run clippy | |
run: cargo clippy --all-targets -- -D warnings | |
- name: Run format check | |
run: cargo fmt --all -- --check | |
# === TEST JOB === | |
test: | |
name: Build & Test | |
runs-on: ubuntu-24.04 | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Install Rust toolchain | |
uses: dtolnay/rust-toolchain@stable | |
with: | |
targets: x86_64-unknown-linux-gnu | |
- name: Set OpenSSL Paths | |
run: | | |
echo "OPENSSL_LIB_DIR=/usr/lib/x86_64-linux-gnu" >> $GITHUB_ENV | |
echo "OPENSSL_INCLUDE_DIR=/usr/include/x86_64-linux-gnu" >> $GITHUB_ENV | |
- name: Use cached dependencies | |
uses: Swatinem/rust-cache@v2 | |
with: | |
shared-key: "main" | |
key: "test" | |
cache-all-crates: true | |
save-if: ${{ github.ref == 'refs/heads/main' }} | |
- name: Build | |
run: cargo build --all-targets | |
- name: Run tests | |
run: cargo test | |
# === DOCKER BUILD & PUSH JOB === | |
docker: | |
name: Build & Push Docker Image | |
runs-on: ubuntu-24.04 | |
needs: [lint, test] # Only run if lint and test pass | |
if: github.event_name == 'push' || github.event_name == 'pull_request' | |
permissions: | |
contents: read | |
packages: write | |
attestations: write | |
id-token: write | |
steps: | |
- name: Checkout | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GHCR | |
uses: docker/login-action@v3 | |
with: | |
registry: ${{ env.REGISTRY }} | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Determine Image Tags | |
id: tags | |
run: | | |
BRANCH_NAME=${GITHUB_HEAD_REF:-${GITHUB_REF##*/}} | |
IMAGE_NAME="${{ env.REGISTRY }}/${{ github.repository }}/${BRANCH_NAME}" | |
echo "backend_tags=$IMAGE_NAME:latest,$IMAGE_NAME:${{ github.sha }}" >> $GITHUB_OUTPUT | |
echo "backend_image_name=$IMAGE_NAME" >> $GITHUB_OUTPUT | |
- name: Build and Push Backend Image | |
id: push_backend | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: ./Dockerfile | |
platforms: linux/amd64 | |
push: true | |
provenance: true | |
tags: ${{ steps.tags.outputs.backend_tags }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
labels: | | |
org.opencontainers.image.title=Refactor Platform Backend | |
org.opencontainers.image.description=Rust backend for refactor coaching platform | |
org.opencontainers.image.source=${{ github.server_url }}/${{ github.repository }} | |
org.opencontainers.image.revision=${{ github.sha }} | |
- name: Attest Backend Build | |
if: github.ref == 'refs/heads/main' && github.event_name == 'push' | |
uses: actions/attest-build-provenance@v2 | |
with: | |
subject-name: ${{ steps.tags.outputs.backend_image_name }} | |
subject-digest: ${{ steps.push_backend.outputs.digest }} | |
push-to-registry: true | |
- name: Print Usage Instructions | |
run: | | |
echo "🎉 Build, Test & Push completed successfully!" | |
echo "" | |
echo "📦 Backend Image Pushed:" | |
echo " docker pull ${{ steps.tags.outputs.backend_image_name }}:latest" | |
echo " docker pull ${{ steps.tags.outputs.backend_image_name }}:${{ github.sha }}" | |
echo "" | |
echo "🚀 Run Backend:" | |
echo " docker run --rm --env-file .env -p ${{ vars.BACKEND_PORT || '4000' }}:${{ vars.BACKEND_PORT || '4000' }} ${{ steps.tags.outputs.backend_image_name }}:latest" |