Skip to content

Feature-1342: add actions #65

Feature-1342: add actions

Feature-1342: add actions #65

Workflow file for this run

name: Code Quality
on:
pull_request:
types: [opened, synchronize, reopened]
branches:
- "**"
- "!main"
env:
NODE_VERSION: "22.x"
DB_USERNAME: postgres
DB_PASSWORD: postgres
DB_DATABASE: postgres
DATABASE_URL: postgres://postgres:postgres@localhost:5432/postgres?schema=public
jobs:
# add_review_links:
# runs-on: ubuntu-22.04
# timeout-minutes: 3
# steps:
# - uses: actions/checkout@v4
# - name: Add review links
# env:
# GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
# run: scripts/github_add_link_for_reviews.sh
dependency-review:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Review Dependencies
uses: actions/dependency-review-action@v4
install-ui:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Get npm cache directory
id: npm-cache-dir
run: echo "dir=$(npm config get cache)" >> ${GITHUB_OUTPUT}
- name: Cache npm
uses: actions/cache@v4
with:
path: ${{ steps.npm-cache-dir.outputs.dir }}
key: "${{ runner.os }}-npm-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}"
restore-keys: |
${{ runner.os }}-npm-
- name: Cache node modules
uses: actions/cache@v4
with:
path: ./ui/node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}"
restore-keys: |
${{ runner.os }}-node_modules-
# - name: Cache e2e node modules
# uses: actions/cache@v4
# with:
# path: ./e2e/node_modules
# key: "${{ runner.os }}-node_modules_e2e-${{ env.NODE_VERSION }}-${{ hashFiles('./e2e/package-lock.json') }}"
# restore-keys: |
# ${{ runner.os }}-node_modules_e2e-
- name: Install node dependencies
run: cd ui && npm install
test-ui:
runs-on: ubuntu-latest
needs: install-ui
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Restore cached node modules
uses: actions/cache/restore@v4
with:
path: ./ui/node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}"
- name: Run tests
run: cd ui && npm run test
lint-ui:
runs-on: ubuntu-latest
needs: install-ui
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Restore cached node modules
uses: actions/cache/restore@v4
with:
path: ./ui/node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}"
- name: Run lint
run: cd ui && npm run lint
# - name: Run prettier
# run: npx prettier --check .
# It would be cleaner and probably more performant to replace this build step
# with either a non-emitting build or a simple type check.
# We only have `build` available for now,
# since the project is currently split across a multitude of small packages,
# all of which have to specify their own commands.
# (Daniel von Atzigen, 2024-04-12)
build-ui:
runs-on: ubuntu-latest
needs:
- test-ui
- lint-ui
- dependency-review
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Setup node
uses: actions/setup-node@v4
with:
node-version: ${{ env.NODE_VERSION }}
- name: Restore cached node modules
uses: actions/cache/restore@v4
with:
path: ./ui/node_modules
key: "${{ runner.os }}-node_modules-${{ env.NODE_VERSION }}-${{ hashFiles('./ui/package-lock.json') }}"
# - name: Reset nx
# run: npx nx reset
- name: Run build
run: cd ui && npm run build
install-api:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73
profile: minimal
override: true
- name: Cache cargo registry
uses: actions/cache@v4
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
- name: Cache cargo index
uses: actions/cache@v4
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
- name: Cache cargo build
uses: actions/cache@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ hashFiles('**/Cargo.lock') }}
restore-keys: |
cargo-build-${{ runner.os }}-
- name: Cache sqlx binary
uses: actions/cache@v4
with:
path: ~/.cargo/bin/sqlx
key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
sqlx-${{ runner.os }}-
- name: Install Rust dependencies
env:
DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local"
run: |
docker compose up -d db
sleep 10
cd api
if [ ! -f ~/.cargo/bin/sqlx ]; then
cargo install sqlx-cli --version 0.7.3 --no-default-features --features native-tls,postgres --locked --quiet
fi
# sqlx database create
# sqlx migrate run
- name: Cache shared volume
uses: actions/cache@v4
with:
path: /var/lib/postgresql/data
key: db-data-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
db-data-${{ runner.os }}-
format-api:
runs-on: ubuntu-latest
needs:
- install-api
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73
profile: minimal
override: true
- name: Restore cached cargo registry
uses: actions/cache/restore@v4
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
- name: Restore cached cargo index
uses: actions/cache/restore@v4
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
- name: Restore cached cargo build
uses: actions/cache/restore@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-build-${{ runner.os }}-
- name: Restore cached sqlx binary
uses: actions/cache/restore@v4
with:
path: ~/.cargo/bin/sqlx
key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
sqlx-${{ runner.os }}-
# - name: Install Rust dependencies
# env:
# DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local"
# run: |
# docker compose up -d db
# sleep 10
# cd api
# sqlx database create
# sqlx migrate run
- name: Run container
run: |
docker compose up -d api
sleep 10
- name: Run fmt
run: |
docker compose exec api rustup component add rustfmt
docker compose exec api cargo fmt
- name: Run clippy
run: |
docker compose exec api rustup component add clippy
docker compose exec api cargo clippy
test-api:
runs-on: ubuntu-latest
needs:
- install-api
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73
profile: minimal
override: true
- name: Restore cached cargo registry
uses: actions/cache/restore@v4
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
- name: Restore cached cargo index
uses: actions/cache/restore@v4
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
- name: Restore cached cargo build
uses: actions/cache/restore@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-build-${{ runner.os }}-
- name: Restore cached sqlx binary
uses: actions/cache/restore@v4
with:
path: ~/.cargo/bin/sqlx
key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
sqlx-${{ runner.os }}-
# - name: Install Rust dependencies
# env:
# DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local"
# run: |
# docker compose up -d db
# sleep 10
# cd api
# sqlx database create
# sqlx migrate run
- name: Run test
run: |
docker compose up -d api
sleep 10
cd api
docker compose exec api cargo test --offline
build-api:
runs-on: ubuntu-latest
needs:
# - test-api
# - format-api
- install-api
- dependency-review
steps:
- name: Checkout repository
uses: actions/checkout@v4
- name: Install Rust toolchain
uses: actions-rs/toolchain@v1
with:
toolchain: 1.73
profile: minimal
override: true
- name: Restore cached cargo registry
uses: actions/cache/restore@v4
with:
path: ~/.cargo/registry
key: cargo-registry-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-registry-${{ runner.os }}-
- name: Restore cached cargo index
uses: actions/cache/restore@v4
with:
path: ~/.cargo/git
key: cargo-index-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-index-${{ runner.os }}-
- name: Restore cached cargo build
uses: actions/cache/restore@v4
with:
path: target
key: cargo-build-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
cargo-build-${{ runner.os }}-
- name: Restore cached sqlx binary
uses: actions/cache/restore@v4
with:
path: ~/.cargo/bin/sqlx
key: sqlx-${{ runner.os }}-${{ hashFiles('./api/Cargo.lock') }}
restore-keys: |
sqlx-${{ runner.os }}-
- name: Install Rust dependencies
env:
DATABASE_URL: "postgres://www-data:www-data@localhost:15432/swissgeol-local"
run: |
docker compose up -d db
sleep 10
cd api
# sqlx database create
# sqlx migrate run
- name: Build API
env:
S3_AWS_REGION: eu-west-1
AWS_ACCESS_KEY_ID: minio
AWS_SECRET_ACCESS_KEY: minio123
S3_BUCKET: ngmpub-userdata-local
PROJECTS_S3_BUCKET: ngmpub-project-files-local
S3_ENDPOINT: http://minio:9000
COGNITO_CLIENT_ID: 10h1tga4i933buv25lelalmtrn
COGNITO_POOL_ID: eu-west-1_dbfEb2FuH
PGUSER: www-data
PGPASSWORD: www-data
PGDATABASE: swissgeol-local
PGHOST: db
PGPORT: "5432"
APP_PORT: "3000"
SQLX_OFFLINE: "true"
DATABASE_URL: "postgres://www-data:www-data@db:5432/swissgeol-local"
run: |
apt update && apt install -y musl-tools musl-dev musl-gcc
rustup target add x86_64-unknown-linux-musl
cd api
cargo build --target x86_64-unknown-linux-musl