Skip to content

OPHYK-212 Wait for servers to respond before running Playwright tests #937

OPHYK-212 Wait for servers to respond before running Playwright tests

OPHYK-212 Wait for servers to respond before running Playwright tests #937

Workflow file for this run

name: organisaatio
on:
workflow_dispatch:
push:
branches: [master]
pull_request:
jobs:
build:
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.14
ports:
- 5433:5432
env:
POSTGRES_USER: postgres
POSTGRES_DB: organisaatio
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: szenius/[email protected]
with:
timezoneLinux: "Europe/Helsinki"
- name: Build frontend
working-directory: organisaatio-ui
run: |
npm ci
npm run lint
npm run prettier
CI=true npm run test
npm run build
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build
- uses: actions/upload-artifact@v4
with:
name: organisaatio-service-jar
path: organisaatio-service/build/libs/organisaatio-service.jar
cypress:
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- name: Cypress coverrage cache
uses: actions/cache@v4
env:
cache-name: cache-cypress-coverage
with:
path: organisaatio-ui/cypress-coverage
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- name: pre scripts
run: |
PGPASSWORD=postgres psql -c 'CREATE DATABASE organisaatio;' -h localhost -U postgres
cd mock-api && npm install && cd -
cd organisaatio-ui && npm ci --force && cd -
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build backend with no tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build -x test
- name: Run Cypress
run: |
cd mock-api && npm run mock-api &
cd organisaatio-ui && npm run start &
java -jar -Xms2g -Xmx2g -Dspring.config.location=classpath:application.properties,classpath:application-test-envs.properties -Dspring.profiles.active=dev -Dspring.flyway.enabled=true -Durl-virkailija=http://localhost:9000 -Dhost.virkailija=localhost:9000 -Durl-ytj=http://localhost:9000/ytj -Durl-oidservice=http://localhost:9000/oidservice -Dcas.service.organisaatio-service=http://localhost:8080/organisaatio-service-not-available organisaatio-service/build/libs/organisaatio-service.jar &
cd organisaatio-ui && npm run cypress:ci
kill $(jobs -p) || true
playwright:
timeout-minutes: 60
runs-on: ubuntu-latest
services:
postgres:
image: postgres
ports:
- 5432:5432
env:
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
cache-dependency-path: organisaatio-ui/package-lock.json
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- name: pre scripts
run: |
PGPASSWORD=postgres psql -c 'CREATE DATABASE organisaatio;' -h localhost -U postgres
cd mock-api && npm ci && cd -
cd organisaatio-ui && npm ci --force && cd -
cd playwright && npm ci && npx playwright install --with-deps && cd -
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Build backend with no tests
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew clean build -x test
- name:
run: |
cd mock-api && npm run mock-api &
cd organisaatio-ui && npm run start &
java -jar -Xms2g -Xmx2g -Dspring.config.location=classpath:application.properties,classpath:application-test-envs.properties -Dspring.profiles.active=dev -Dspring.flyway.enabled=true -Durl-virkailija=http://localhost:9000 -Dhost.virkailija=localhost:9000 -Durl-ytj=http://localhost:9000/ytj -Durl-oidservice=http://localhost:9000/oidservice -Dcas.service.organisaatio-service=http://localhost:8080/organisaatio-service-not-available organisaatio-service/build/libs/organisaatio-service.jar &
while ! nc -z localhost 3003; do
sleep 1; echo "Sleeping 3003"
done
while ! nc -z localhost 8080; do
sleep 1; echo "Sleeping 8080"
done
cd playwright && npx playwright test
kill $(jobs -p) || true
- uses: actions/upload-artifact@v4
if: always()
with:
name: playwright-report
path: playwright/playwright-report/
retention-days: 30
sonarcloud:
needs: [cypress, playwright]
runs-on: ubuntu-latest
services:
postgres:
image: postgres:12.14
ports:
- 5433:5432
env:
POSTGRES_USER: postgres
POSTGRES_DB: organisaatio
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set timezone
uses: szenius/[email protected]
with:
timezoneLinux: "Europe/Helsinki"
- name: Cypress coverrage cache
uses: actions/cache@v4
env:
cache-name: cache-cypress-coverage
with:
path: organisaatio-ui/cypress-coverage
key: ${{ runner.os }}-build-${{ env.cache-name }}-${{ github.sha }}
- uses: actions/setup-java@v4
with:
java-version: 21
distribution: "corretto"
- name: Cache SonarCloud packages
uses: actions/cache@v4
with:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache Gradle packages
uses: actions/cache@v4
with:
path: ~/.gradle/caches
key: ${{ runner.os }}-gradle-${{ hashFiles('**/*.gradle') }}
restore-keys: ${{ runner.os }}-gradle
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
run: ./gradlew build sonarqube
deploy-container:
needs: [cypress, build, playwright]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Download organisaatio-service-jar
uses: actions/download-artifact@v4
with:
name: organisaatio-service-jar
- name: Build Docker Conainer
shell: bash
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
run: |
git clone https://github.com/Opetushallitus/ci-tools.git
source ci-tools/common/setup-tools.sh
export BASE_IMAGE="baseimage-fatjar-openjdk21:master"
export ARTIFACT_NAME="organisaatio"
cp organisaatio-service.jar $DOCKER_BUILD_DIR/artifact/$ARTIFACT_NAME.jar
cp -vr src/main/resources/oph-configuration $DOCKER_BUILD_DIR/config/
./ci-tools/common/pull-image.sh
./ci-tools/github-build/build-fatjar.sh $ARTIFACT_NAME
./ci-tools/github-build/upload-image.sh $ARTIFACT_NAME
deploy-artifacts:
needs: [build, cypress, playwright]
if: github.ref == 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_sadeRepositoryUsername: ${{ secrets.ARTIFACTORY_USERNAME }}
ORG_GRADLE_PROJECT_sadeRepositoryPassword: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: ./gradlew publish -PversionSuffix=.RELEASE
deploy-artifacts-snapshot:
needs: [build, cypress, playwright]
if: github.ref != 'refs/heads/master'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: "21"
distribution: "corretto"
- uses: gradle/actions/wrapper-validation@v3
- uses: gradle/actions/setup-gradle@v3
- name: Publish
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
ORG_GRADLE_PROJECT_sadeRepositoryUsername: ${{ secrets.ARTIFACTORY_USERNAME }}
ORG_GRADLE_PROJECT_sadeRepositoryPassword: ${{ secrets.ARTIFACTORY_PASSWORD }}
run: ./gradlew publish