Files
photoview/.github/workflows/tests.yml
Kostiantyn dee3a151e9 Update GitHub workflows with various improvements (#1028)
Updated DB images in tests to align with the PROD setup
Try to upload coverage only if tests were executed (passed or failed) - not skipped or canceled
Added ESLint execution after UI tests with results exported to artifact
Shifted scheduled run time from 00 minutes according to GitHub recommendations, as the 00 minutes of each hour is the busiest time
Dynamically extract a list of langs from the repo to use them for CodeQL analysis instead of hardcoded ones
Updated versions of several outdated actions
Added the Autobuild step before CodeQL analysis for GO
Added the Anchore dependency scan job, reporting to the Security tab. I can add steps to manage PR comments with the results, but I need a token to be provided by @viktorstrate
Added the Hadolint Dockerfile scan job, reporting to the Security tab. I can add steps to manage PR comments with the results, but I need a token to be provided by @viktorstrate
Implemented weekly rebuild of images for the latest commit in the master branch and the latest released tag. It will recreate images with the recent base image and 3rd-party dependencies even if there were no new pushes for a long time
Added the Dockle container analysis job to be run on master and tag and validate just pushed images, reporting to the Security tab
Added golangci-lint config to the /api folder, as a starting point and for local usage
Added 2 weekly jobs for Dependabot:
-- Maintain dependencies for GitHub Actions
-- Maintain dependencies for Dockerfile

---------

Co-authored-by: Konstantin Koval
2024-10-01 15:50:44 +03:00

139 lines
3.5 KiB
YAML

name: Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
jobs:
test-api:
name: Test API
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
database: ['sqlite', 'mysql', 'postgres']
services:
mariadb:
image: mariadb:lts
env:
MYSQL_DATABASE: photoview_test
MYSQL_USER: photoview
MYSQL_PASSWORD: photosecret
MYSQL_RANDOM_ROOT_PASSWORD: yes
# https://github.com/MariaDB/mariadb-docker/issues/497
options: >-
--health-cmd="mariadb-admin ping"
--health-interval=10s
--health-timeout=5s
--health-retries=5
ports:
- 3306:3306
postgres:
image: postgres:16-alpine
env:
POSTGRES_USER: photoview
POSTGRES_PASSWORD: photosecret
POSTGRES_DB: photoview_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5432:5432
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout repo
uses: actions/checkout@v4
- name: Build test image
uses: docker/build-push-action@v6
with:
pull: true
push: false
load: true
target: api
tags: photoview/api
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test
id: test
continue-on-error: true
run: |
docker run --name test --network host \
-e PHOTOVIEW_DATABASE_DRIVER=${{ matrix.database }} \
-e PHOTOVIEW_MYSQL_URL='photoview:photosecret@tcp(localhost:3306)/photoview_test' \
-e PHOTOVIEW_POSTGRES_URL='postgres://photoview:photosecret@localhost:5432/photoview_test' \
-e PHOTOVIEW_SQLITE_PATH=/tmp/photoview.db \
photoview/api \
go test ./... -v -database -filesystem -p 1 -coverprofile=coverage.txt -covermode=atomic
docker cp test:/app/api/coverage.txt ./api/
- name: Upload coverage
uses: codecov/codecov-action@v4
if: ${{ steps.test.conclusion == 'success' }}
with:
flags: api-${{ matrix.database }}
test-ui:
name: Test UI
runs-on: ubuntu-latest
steps:
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Checkout repo
uses: actions/checkout@v4
- name: Build test image
uses: docker/build-push-action@v6
with:
pull: true
push: false
load: true
target: ui
tags: photoview/ui
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Test
id: test
continue-on-error: true
run: |
docker run --name test photoview/ui npm run test:ci
docker cp test:/app/ui/coverage ./ui/
- name: Upload coverage
uses: codecov/codecov-action@v4
if: ${{ steps.test.conclusion == 'success' }}
with:
flags: ui
- name: Run ESLint
working-directory: ui
run: |
npm run lint:ci || true
echo "--------------------------"
echo "ESLint execution results :"
echo "--------------------------"
cat ./eslint-report.txt || echo "ESLint report file not found."
- name: ESLint artifact
id: eslint-artifact
uses: actions/upload-artifact@v4
with:
name: ESLint-report
path: ./ui/eslint-report.txt
if-no-files-found: warn
compression-level: 9
overwrite: true