Skip to content

ci: fix the github actions workflows #194

ci: fix the github actions workflows

ci: fix the github actions workflows #194

Workflow file for this run

name: rust-ci
on:
push:
paths:
- '.github/workflows/rust-ci.yml'
- 'Cargo.lock'
- 'Cargo.toml'
- 'crates/**'
- 'Makefile.toml'
- 'migrations/**'
- 'rust-toolchain.toml'
- 'rustfmt.toml'
- 'sqlx-data.json'
pull_request:
workflow_dispatch:
env:
CARGO_TERM_COLOR: always
CARGO_MAKE_RUN_CODECOV: true
SQLX_OFFLINE: true
REGISTRY: ghcr.io
LOCAL_REGISTRY: localhost:5000
SERVER_IMAGE_NAME: carlomicieli/trenako-server
MIGRATIONS_IMAGE_NAME: carlomicieli/trenako-migrations
jobs:
checks:
runs-on: ubuntu-22.04
steps:
- name: Checkout source code
uses: actions/checkout@v3
- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install bunyan
run: npm install -g bunyan
- name: Setup the rust toolchain
uses: dtolnay/rust-toolchain@stable
- name: Install cargo make
run: cargo install [email protected]
- name: Set up cargo cache
uses: Swatinem/rust-cache@v2
continue-on-error: false
- name: Toolchain info
run: |
rustc --version
cargo --version --verbose
cargo make --version
- name: Run cargo check
run: cargo make check
- name: Check formatting with rustfmt
run: cargo make fmt-check
- name: Linting with Clippy
run: cargo make clippy
- name: Run the unit tests
run: cargo make unit-test
- name: Run the integration tests
run: cargo make integration-test | bunyan
docker:
runs-on: ubuntu-22.04
needs: checks
if: github.ref == 'refs/heads/main' || github.ref == 'refs/heads/dev'
permissions:
contents: read
packages: write
services:
registry:
image: registry:2
ports:
- 5000:5000
steps:
- name: Check out the repo
uses: actions/checkout@v3
- name: Setup node.js
uses: actions/setup-node@v3
with:
node-version: 16
- name: Install openapi-generator-cli
run: npm install @openapitools/openapi-generator-cli -g
- name: Set up JDK 17
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '17'
- name: Validate Gradle wrapper
uses: gradle/wrapper-validation-action@v1
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
build-root-directory: e2e
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
with:
driver-opts: network=host
- name: Log in to the Container registry
uses: docker/login-action@v2
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract metadata (tags, labels) for the server Docker image
id: meta-server
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ env.SERVER_IMAGE_NAME }}
${{ env.LOCAL_REGISTRY }}/${{ env.SERVER_IMAGE_NAME }}
tags: |
# set latest tag for default branch
# type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=raw,value={{date 'YYYYMMDDHHmm'}}-{{sha}}
- name: Extract metadata (tags, labels) for the migrations Docker image
id: meta-migrations
uses: docker/metadata-action@v4
with:
images: |
${{ env.REGISTRY }}/${{ env.MIGRATIONS_IMAGE_NAME }}
${{ env.LOCAL_REGISTRY }}/${{ env.MIGRATIONS_IMAGE_NAME }}
tags: |
# set latest tag for default branch
# type=raw,value=latest,enable=${{ github.ref == format('refs/heads/{0}', 'main') }}
type=raw,value=latest
type=raw,value={{date 'YYYYMMDDHHmm'}}-{{sha}}
- name: Build and export to Docker (server)
uses: docker/build-push-action@v4
with:
context: .
file: docker/server.dockerfile
load: true
tags: ${{ steps.meta-server.outputs.tags }}
labels: ${{ steps.meta-server.outputs.labels }}
- name: Build and export to Docker (migrations)
uses: docker/build-push-action@v4
with:
context: .
file: docker/migrations.dockerfile
load: true
tags: ${{ steps.meta-migrations.outputs.tags }}
labels: ${{ steps.meta-migrations.outputs.labels }}
- name: List docker images
run: docker image ls
- name: Generate the openapi schema
run: openapi-generator-cli generate -i openapi/api-schema.yaml -g openapi -o e2e/api/src/main/resources/openapi
- name: Run the E2E tests
uses: gradle/gradle-build-action@v2
env:
REGISTRY_NAME: localhost:5000
with:
arguments: api:test
build-root-directory: e2e