feat: add example application #82
Workflow file for this run
This file contains 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: Rust CI | |
on: | |
pull_request: | |
branches: | |
- main | |
push: | |
branches: | |
- main | |
jobs: | |
prepare: | |
name: Prepare and lint | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v4 | |
with: | |
persist-credentials: true | |
# token: ${{ secrets.GITHUB_TOKEN }} | |
- uses: dtolnay/rust-toolchain@stable | |
with: | |
components: rustfmt, clippy | |
- name: Format code | |
run: cargo fmt --all | |
- name: Run clippy | |
run: cargo clippy --all-features --tests -- -D warnings | |
- name: Install sqlx-cli | |
run: cargo install sqlx-cli --no-default-features --features native-tls,postgres | |
- name: Run sqlx prepare | |
run: cargo sqlx prepare --workspace --check | |
env: | |
SQLX_OFFLINE: true | |
# Uncomment the following lines if you want to commit the changes, TOOD: add token to repo secrets | |
# - name: Commit changes if any | |
# uses: stefanzweifel/git-auto-commit-action@v5 | |
# with: | |
# commit_message: "chore: format code and run clippy" | |
# commit_options: "--no-gpg-sign" | |
test: | |
name: Docker build and test | |
runs-on: ubuntu-latest | |
needs: prepare | |
env: | |
DATABASE_URL: postgres://postgres:postgres@localhost:5432/test_db | |
services: | |
postgres: | |
image: postgres:latest | |
env: | |
POSTGRES_PASSWORD: postgres | |
POSTGRES_USER: postgres | |
POSTGRES_DB: test_db | |
ports: | |
- 5432:5432 | |
options: >- | |
--health-cmd pg_isready | |
--health-interval 10s | |
--health-timeout 5s | |
--health-retries 5 | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Build Docker image for testing | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: server/services/manager/Dockerfile | |
target: builder | |
load: true | |
tags: app-builder:latest | |
cache-from: type=gha | |
cache-to: type=gha,mode=max | |
- name: Set up database and run migrations | |
run: | | |
docker run --network host \ | |
-e DATABASE_URL=${DATABASE_URL} \ | |
app-builder /bin/bash -c " | |
cargo install sqlx-cli --no-default-features --features postgres && | |
cargo sqlx database create && | |
cargo sqlx migrate run --source ./server/libs/db-common/migrations | |
" | |
- name: Run tests in container | |
run: | | |
docker run --network host \ | |
-e DATABASE_URL=${DATABASE_URL} \ | |
app-builder cargo test --all-features | |
publish: | |
name: Publish Docker image | |
needs: test | |
runs-on: ubuntu-latest | |
if: github.event_name == 'push' && github.ref == 'refs/heads/main' | |
steps: | |
- uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Build and push | |
uses: docker/build-push-action@v5 | |
with: | |
context: . | |
file: server/services/manager/Dockerfile | |
push: true | |
tags: | | |
ghcr.io/${{ github.repository }}/manager:latest | |
ghcr.io/${{ github.repository }}/manager:${{ github.sha }} | |
cache-from: type=gha | |
cache-to: type=gha,mode=max |