Feature-1342: add actions #75
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: Code Quality | ||
on: | ||
pull_request: | ||
types: [opened, synchronize, reopened] | ||
branches: | ||
- "**" | ||
- "!main" | ||
env: | ||
NODE_VERSION: "22.x" | ||
RUST_VERSION: "1.73" | ||
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: | ||
name: "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: Install node dependencies | ||
run: cd ui && npm install | ||
typecheck-ui: | ||
name: "Type-check 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: Reset nx | ||
# run: npx nx reset | ||
- name: Run build | ||
run: cd ui && npm run check | ||
test-ui: | ||
name: "Test UI" | ||
runs-on: ubuntu-latest | ||
needs: | ||
- typecheck-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: | ||
name: "Lint UI" | ||
runs-on: ubuntu-latest | ||
needs: | ||
- typecheck-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 | ||
install-api: | ||
name: "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: ${{ env.RUST_VERSION }} | ||
profile: minimal | ||
override: true | ||
- name: Cache cargo registry | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cargo/registry | ||
key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
restore-keys: | | ||
${{ runner.os }}-cargo_registry- | ||
- name: Cache cargo index | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cargo/git | ||
key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
restore-keys: | | ||
${{ runner.os }}-cargo_index- | ||
- name: Cache cargo build | ||
uses: actions/cache@v4 | ||
with: | ||
path: ./api/target | ||
key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
restore-keys: | | ||
${{ runner.os }}-cargo_build- | ||
- name: Cache sqlx binary | ||
uses: actions/cache@v4 | ||
with: | ||
path: ~/.cargo/bin/sqlx | ||
key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
restore-keys: | | ||
${{ runner.os }}-sqlx- | ||
- name: Start DB | ||
run: | ||
docker compose up -d db | ||
sleep 10 | ||
- name: Setup DB | ||
run: | | ||
cd api | ||
cargo install sqlx-cli --version 0.7.3 --no-default-features --features native-tls,postgres --locked --quiet | ||
sqlx database create | ||
sqlx migrate run | ||
- name: Upload DB data | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: db | ||
path: /var/lib/docker/volumes/${{ github.workspace }}_db | ||
- name: Install dependencies | ||
run: | | ||
cd api | ||
rm -r src/* | ||
echo "fn main() {}" > src/main.rs | ||
cargo build --all-targets --locked --quiet | ||
- name: Stop services | ||
run: | | ||
docker compose down | ||
lint-api: | ||
name: "Lint 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: ${{ env.RUST_VERSION }} | ||
profile: minimal | ||
override: true | ||
- name: Cache cargo registry | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/registry | ||
key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo index | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/git | ||
key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo build | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ./api/target | ||
key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" | ||
- name: Cache sqlx binary | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/bin/sqlx | ||
key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Run rustfmt | ||
run: | | ||
cd api | ||
rustup component add rustfmt | ||
cargo fmt --check | ||
- name: Run clippy | ||
run: | | ||
cd api | ||
rustup component add clippy | ||
cargo clippy --frozen | ||
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: ${{ env.RUST_VERSION }} | ||
profile: minimal | ||
override: true | ||
- name: Cache cargo registry | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/registry | ||
key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo index | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/git | ||
key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo build | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ./api/target | ||
key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" | ||
- name: Cache sqlx binary | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/bin/sqlx | ||
key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Download DB data | ||
uses: actions/download-artifact@v4 | ||
with: | ||
name: db | ||
path: /var/lib/docker/volumes/${{ github.workspace }}_db | ||
- name: Start DB | ||
run: | ||
docker compose up -d db | ||
sleep 10 | ||
- name: Start API | ||
run: | ||
cd api | ||
nohup cargo run --frozen > ../api.log 2>&1 & | ||
echo $! > ../api.pid | ||
- name: Run test | ||
run: | | ||
cd api | ||
cargo test --frozen | ||
- name: Stop services | ||
run: | | ||
kill $(cat api.pid) | ||
docker compose down | ||
check-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: ${{ env.RUST_VERSION }} | ||
profile: minimal | ||
override: true | ||
- name: Cache cargo registry | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/registry | ||
key: "${{ runner.os }}-cargo_registry-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo index | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/git | ||
key: "${{ runner.os }}-cargo_index-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Cache cargo build | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ./api/target | ||
key: "${{ runner.os }}-cargo_build-${{ env.RUST_VERSION }}-${{ hashFiles('/api/Cargo.lock') }}" | ||
- name: Cache sqlx binary | ||
uses: actions/cache/restore@v4 | ||
with: | ||
path: ~/.cargo/bin/sqlx | ||
key: "${{ runner.os }}-sqlx-${{ env.RUST_VERSION }}-${{ hashFiles('./api/Cargo.lock') }}" | ||
- name: Run check | ||
run: | | ||
cd api | ||
cargo check --frozen | ||
cleanup: | ||
runs-on: ubuntu-latest | ||
needs: | ||
- build-api | ||
- lint-ui | ||
- test-ui | ||
if: always() | ||
steps: | ||
- name: Find DB artifact | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
artifact_name="db" | ||
artifacts=$(curl -s -H "Authorization: token $GITHUB_TOKEN" \ | ||
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts") | ||
artifact_id=$(echo "$artifacts" | jq -r ".artifacts[] | select(.name==\"$artifact_name\") | .id") | ||
echo "artifact_id=$artifact_id" >> $GITHUB_ENV | ||
- name: Delete DB artifact | ||
if: ${{ env.artifact_id != '' }} | ||
env: | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run: | | ||
curl -X DELETE -H "Authorization: token $GITHUB_TOKEN" \ | ||
"https://api.github.com/repos/${{ github.repository }}/actions/artifacts/${{ env.artifact_id }}" |