Skip to content

Commit

Permalink
Add github workflows
Browse files Browse the repository at this point in the history
  • Loading branch information
damccull committed Nov 23, 2023
1 parent 5a0edc2 commit 352cf38
Show file tree
Hide file tree
Showing 4 changed files with 223 additions and 0 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/audit.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
name: Security audit
on:
schedule:
- cron: '0 0 * * *'
push:
paths:
- '**/Cargo.lock'
- '.github/workflows/audit.yml'
pull_request:
paths:
- "**/Cargo.lock"
- '.github/workflows/audit.yml'

jobs:
security_audit:
runs-on: ubuntu-latest
strategy:
matrix:
checks:
- advisories
- bans licenses sources

# Prevent sudden announcement of a new advisory from failing ci
continue-on-error: ${{ matrix.checks == 'advisories' }}

steps:
- uses: actions/checkout@v3
- uses: EmbarkStudios/cargo-deny-action@v1
with:
command: check ${{ matrix.checks }}
59 changes: 59 additions & 0 deletions .github/workflows/coverage.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Code coverage

on:
push:
branches:
- main
pull_request:
types: [ opened, synchronize, reopened ]
branches:
- main

env:
CARGO_TERM_COLOR: always
SQLX_VERSION: 0.6.3
SQLX_FEATURES: "rustls,postgres"

jobs:
coverage:
name: Code coverage
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
redis:
image: redis:7
ports:
- 6379:6379
steps:
- name: Checkout repository
uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- name: Install libpq
run: sudo apt-get update && sudo apt-get install postgresql-client -y
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
- name: Install tarpaulin
run: cargo install cargo-tarpaulin
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Migrate database
run: |
cd zero2prod
SKIP_DOCKER=true cargo xtask postgres
- name: Generate code coverage
run: |
cd zero2prod
cargo tarpaulin --verbose
29 changes: 29 additions & 0 deletions .github/workflows/fly.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
name: Fly Deploy
on:
push:

workflow_run:
workflows:
- CI/CD Prechecks
#disable this workflow. To enable, remove this and uncomment the 'branches' section.
branches-ignore:
- '*'
#branches:
# - main
types:
- completed
jobs:
deploy:
name: Deploy app
runs-on: ubuntu-latest
# Only deploy the app if the `general` workflow was a success.
if: ${{ github.event.workflow_run.conclusion == 'success' }}
steps:
- uses: actions/checkout@v3
- uses: superfly/flyctl-actions/setup-flyctl@master
- name: Deploy to fly.io
run: |
cd zero2prod
flyctl deploy --remote-only
env:
FLY_API_TOKEN: ${{ secrets.FLY_API_TOKEN }}
105 changes: 105 additions & 0 deletions .github/workflows/general.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
name: CI/CD Prechecks

on:
push:
branches:
- main
- actix
pull_request:
types: [ opened, synchronize, reopened ]
branches:
- main
- actix

env:
CARGO_TERM_COLOR: always
SQLX_VERSION: 0.6.3
SQLX_FEATURES: "rustls,postgres"

jobs:
test:
name: Test
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
redis:
image: redis:7
ports:
- 6379:6379
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Migrate database
run: |
sudo apt-get install libpq-dev -y
cd zero2prod
SKIP_DOCKER=true cargo xtask postgres
- name: Check sqlx-data.json is up-to-date
run: |
cd zero2prod
cargo sqlx prepare --check -- --bin zero2prod
- name: Run tests
run: cargo test

fmt:
name: Rustfmt
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: rustfmt
- name: Enforce formatting
run: cargo fmt --check

clippy:
name: Clippy
runs-on: ubuntu-latest
services:
postgres:
image: postgres:14
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: password
POSTGRES_DB: postgres
ports:
- 5432:5432
steps:
- uses: actions/checkout@v3
- uses: dtolnay/rust-toolchain@stable
with:
components: clippy
- uses: Swatinem/rust-cache@v2
with:
key: sqlx-${{ env.SQLX_VERSION }}
- name: Install sqlx-cli
run:
cargo install sqlx-cli
--version=${{ env.SQLX_VERSION }}
--features ${{ env.SQLX_FEATURES }}
--no-default-features
--locked
- name: Migrate database
run: |
sudo apt-get install libpq-dev -y
cd zero2prod
SKIP_DOCKER=true cargo xtask postgres
- name: Linting
run: cargo clippy -- -D warnings

0 comments on commit 352cf38

Please sign in to comment.