HMS-5287: Add playwright and github action to backend #3971
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: build-test | |
on: | |
push: | |
branches: | |
- main | |
paths-ignore: | |
- "**.md" | |
pull_request: | |
paths-ignore: | |
- "**.md" | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
jobs: | |
playwright-tests: | |
runs-on: | |
- codebuild-content-services-backend-repo-${{ github.run_id }}-${{ github.run_attempt }} | |
- instance-size:medium | |
- buildspec-override:true | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v3 | |
- name: Get current PR URL | |
id: get-pr-url | |
run: | | |
# Extract the pull request URL from the event payload | |
pr_url=$(jq -r '.pull_request.html_url' < "$GITHUB_EVENT_PATH") | |
echo "Pull Request URL: $pr_url" | |
# Set the PR URL as an output using the environment file | |
echo "pr_url=$pr_url" >> $GITHUB_ENV | |
- name: Get appropriate front-end branch | |
run: | | |
chmod +x .github/workflowScripts/getFrontendRepo.sh | |
.github/workflowScripts/getFrontendRepo.sh "${{ env.pr_url }}" | |
- name: Compare .nvmrc files | |
id: compare-nvmrc | |
run: | | |
# Get both .nvmrc files | |
backendNvmrc="_playwright-tests/.nvmrc" | |
frontendNvmrc="content-sources-frontend/.nvmrc" | |
# Check if both files exist | |
if [ ! -f "$backendNvmrc" ]; then | |
echo "Error: $backendNvmrc does not exist." | |
exit 1 | |
fi | |
if [ ! -f "$frontendNvmrc" ]; then | |
echo "Error: $frontendNvmrc does not exist." | |
exit 1 | |
fi | |
# Compare the contents of the two files | |
if ! cmp -s "$backendNvmrc" "$frontendNvmrc"; then | |
echo "Error: The .nvmrc files are not the same." | |
exit 1 | |
fi | |
echo "The .nvmrc versions are the same!" | |
- name: Stop build iff .nvmrc files are not the same | |
if: steps.compare-nvmrc.outcome == 'failure' | |
run: | | |
echo "Build failed due to .nvmrc file mismatch." | |
exit 1 | |
# - name: Cache - Restore API-test node_modules | |
# uses: actions/cache@v4 | |
# with: | |
# path: "_playwright-tests/node_modules" | |
# key: ${{ runner.os }}-api-node-modules-${{ hashFiles('_playwright-tests/yarn.lock') }} | |
# restore-keys: | | |
# ${{ runner.os }}-api-node-modules- | |
- name: Cache - Restore front-end-test node_modules | |
if: always() | |
uses: actions/cache@v4 | |
with: | |
path: "content-sources-frontend/node_modules" | |
key: ${{ runner.os }}-frontend-node-modules-${{ hashFiles('content-sources-frontend/yarn.lock') }} | |
restore-keys: | | |
${{ runner.os }}-frontend-node-modules- | |
# - name: Cache - Restore go modules | |
# uses: actions/cache@v4 | |
# with: | |
# path: | | |
# ~/.cache/go-build | |
# ~/go/pkg/mod | |
# key: ${{ runner.os }}-go-${{ hashFiles('go.sum') }} | |
# restore-keys: | | |
# ${{ runner.os }}-go- | |
# - name: Run get_go_version.sh script | |
# id: get-go-version | |
# run: | | |
# chmod +x ./scripts/get_go_version.sh | |
# GO_VERSION=$(./scripts/get_go_version.sh ./go.mod) | |
# echo "::set-output name=go-version::$GO_VERSION" | |
# - name: Set up Go | |
# uses: actions/setup-go@v4 | |
# with: | |
# go-version: "${{ steps.get-go-version.outputs.go-version }}" | |
# - name: Set up Make | |
# run: | | |
# sudo apt-get install make | |
# - name: Copy the example config | |
# run: | | |
# cp ./configs/config.yaml.example ./configs/config.yaml | |
# - name: Create backend .env file | |
# working-directory: _playwright-tests | |
# run: | | |
# echo "BASE_URL=http://127.0.0.1:8000" >> .env | |
# echo "TOKEN=apple" >> .env | |
# echo "CI=true" >> .env | |
# - name: Backend compose-up | |
# run: make compose-up | |
# - name: Backend run | |
# run: make run & | |
- name: Set up Node.js | |
uses: actions/setup-node@v4 | |
with: | |
node-version-file: "_playwright-tests/.nvmrc" | |
# - name: Install API playwright and dependencies | |
# working-directory: _playwright-tests | |
# run: yarn install | |
# - name: Install Playwright Browsers | |
# working-directory: _playwright-tests | |
# run: yarn playwright install --with-deps | |
# - name: Run API Playwright tests | |
# working-directory: _playwright-tests | |
# run: yarn playwright test | |
# - name: Publish API Test Report | |
# uses: ctrf-io/github-test-reporter@v1 | |
# with: | |
# report-path: "./_playwright-tests/playwright-ctrf/playwright-ctrf.json" | |
# if: always() | |
# - name: Store API Test report | |
# uses: actions/upload-artifact@v4 | |
# if: ${{ !cancelled() }} | |
# with: | |
# name: playwright-ctrf | |
# path: ./_playwright-tests/playwright-ctrf | |
# retention-days: 10 | |
- name: Create front-end .env file | |
working-directory: content-sources-frontend | |
run: | | |
echo "USER1USERNAME=${{ secrets.USER1USERNAME }}" >> .env | |
echo "USER1PASSWORD=${{ secrets.USER1PASSWORD }}" >> .env | |
echo "BASE_URL=https://stage.foo.redhat.com:1337" >> .env | |
- name: Install front-end dependencies | |
working-directory: content-sources-frontend | |
run: yarn install | |
- name: Install front-end Playwright Browsers | |
working-directory: content-sources-frontend | |
run: yarn playwright install --with-deps | |
- name: Increase file watchers limit | |
run: | | |
echo fs.inotify.max_user_watches=524288 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p | |
- name: Update /etc/hosts | |
working-directory: content-sources-frontend | |
run: | | |
sudo npm run patch:hosts | |
- name: Build front-end FEC container | |
working-directory: content-sources-frontend | |
run: | | |
yarn build | |
- name: Start front-end server | |
working-directory: content-sources-frontend | |
run: | | |
BACKEND_PORT=8000 yarn start:stage & | |
npx wait-on https://localhost:1337 | |
- name: Run front-end Playwright tests | |
working-directory: content-sources-frontend | |
run: yarn playwright test | |
- name: Stop server | |
working-directory: content-sources-frontend | |
run: | | |
kill $(jobs -p) | |
- name: Publish front-end Test Report | |
uses: ctrf-io/github-test-reporter@v1 | |
with: | |
report-path: "./content-sources-frontend/playwright-ctrf/playwright-ctrf.json" | |
if: always() | |
- name: Store front-end Test report | |
uses: actions/upload-artifact@v4 | |
if: ${{ !cancelled() }} | |
with: | |
name: playwright-ctrf | |
path: ./content-sources-frontend/playwright-ctrf | |
retention-days: 10 | |
# openapidiff: | |
# name: Openapi diff | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: actions/setup-go@v4 | |
# with: | |
# go-version: "1.23" | |
# - run: | | |
# go get -u github.com/swaggo/swag/cmd/swag | |
# - run: | | |
# make openapi | |
# - run: | | |
# git diff --exit-code api/openapi.json | |
# openapivalidate: | |
# name: openapi validate | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: openapi-generators/openapitools-generator-action@v1 | |
# with: | |
# generator: python | |
# openapi-file: api/openapi.json | |
# golangci: | |
# name: Lint | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: actions/setup-go@v4 | |
# with: | |
# go-version: "1.23" | |
# - name: golangci-lint | |
# uses: golangci/golangci-lint-action@v6 | |
# with: | |
# version: v1.61.0 | |
# skip-go-installation: true | |
# args: --timeout=5m | |
# checkmigrations: | |
# name: Check db migrations | |
# runs-on: ubuntu-latest | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: tj-actions/changed-files@v41 | |
# id: files | |
# - run: | | |
# #!/bin/bash | |
# migrations_latest=$(cat db/migrations.latest) | |
# num_files_added=${{ steps.files.outputs.added_files_count }} | |
# if [ "$num_files_added" -gt 0 ]; then | |
# new_migrations_added=$(echo "${{ steps.files.outputs.added_files }}" | grep 'db/migrations' || true) | |
# if [ -n "$new_migrations_added" ]; then | |
# if echo "$new_migrations_added" | grep -q "$migrations_latest"; then | |
# echo "OK: Latest migration content (db/migrations.latest) reflects the timestamp of the latest migrations added." | |
# else | |
# echo "Error: Latest migration content (db/migrations.latest) does NOT reflect the timestamp of the latest migrations added." | |
# echo "New migration files added: $new_migrations_added" | |
# echo "In db/migration.latest: $migrations_latest" | |
# exit 1 | |
# fi | |
# else | |
# echo "OK: No new migration files added." | |
# fi | |
# else | |
# echo "OK: No new files added." | |
# fi | |
# gotest: | |
# name: Test | |
# runs-on: ubuntu-latest | |
# services: | |
# postgres: | |
# image: postgres:16 | |
# env: | |
# POSTGRES_PASSWORD: postgres | |
# options: >- | |
# --health-cmd pg_isready | |
# --health-interval 10s | |
# --health-timeout 5s | |
# --health-retries 5 | |
# ports: | |
# - 5433:5432 | |
# steps: | |
# - uses: actions/checkout@v3 | |
# - uses: actions/setup-go@v4 | |
# with: | |
# go-version: "1.23" | |
# - name: unit tests | |
# run: | | |
# make get-deps ${PWD}/release/dbmigrate db-migrate-up test-unit | |
# env: | |
# DATABASE_HOST: localhost | |
# DATABASE_PORT: 5433 | |
# DATABASE_USER: postgres | |
# DATABASE_NAME: postgres | |
# DATABASE_PASSWORD: postgres | |
# CLIENTS_PULP_SERVER: http://localhost:8080 | |
# CLIENTS_PULP_USERNAME: admin | |
# CLIENTS_PULP_PASSWORD: password | |
# CLIENTS_CANDLEPIN_SERVER: http://localhost:8181/candlepin | |
# CLIENTS_CANDLEPIN_USERNAME: admin | |
# CLIENTS_CANDLEPIN_PASSWORD: admin | |
# CLIENTS_CANDLEPIN_DEVEL_ORG: true | |
# - name: Add hosts to /etc/hosts | |
# run: | | |
# sudo echo "127.0.0.1 pulp.content" | sudo tee -a /etc/hosts | |
# - name: start pulp | |
# uses: isbang/[email protected] | |
# with: | |
# compose-file: docker-compose.yml | |
# cwd: ./compose_files/pulp/ | |
# down-flags: --volumes | |
# - name: Wait for pulp | |
# run: | | |
# docker run --network=host --rm -v ${PWD}:/local curlimages/curl \ | |
# curl --retry-all-errors --fail --retry-delay 10 --retry 32 --retry-max-time 240 http://localhost:8080/api/pulp/default/api/v3/repositories/rpm/rpm/ -u admin:password | |
# sleep 30 | |
# - name: start candlepin | |
# uses: isbang/[email protected] | |
# with: | |
# compose-file: docker-compose.yml | |
# cwd: ./deployments/ | |
# services: | | |
# candlepin | |
# down-flags: --volumes | |
# env: | |
# CONTENT_DATABASE_PORT: 5434 | |
# - name: Wait for candlepin | |
# run: | | |
# docker run --network=host --rm -v ${PWD}:/local curlimages/curl \ | |
# curl --retry-all-errors --fail --retry-delay 10 --retry 32 --retry-max-time 240 http://localhost:8181/candlepin/owners -u admin:admin | |
# sleep 30 | |
# - name: integration tests | |
# run: | | |
# go run cmd/candlepin/main.go init | |
# make test-integration | |
# env: | |
# DATABASE_HOST: localhost | |
# DATABASE_PORT: 5433 | |
# DATABASE_USER: postgres | |
# DATABASE_NAME: postgres | |
# DATABASE_PASSWORD: postgres | |
# CLIENTS_PULP_SERVER: http://localhost:8080 | |
# CLIENTS_PULP_USERNAME: admin | |
# CLIENTS_PULP_PASSWORD: password | |
# CLIENTS_PULP_DATABASE_HOST: localhost | |
# CLIENTS_PULP_DATABASE_PORT: 5432 | |
# CLIENTS_PULP_DATABASE_USER: pulp | |
# CLIENTS_PULP_DATABASE_PASSWORD: password | |
# CLIENTS_PULP_DATABASE_NAME: pulp | |
# CLIENTS_CANDLEPIN_SERVER: http://localhost:8181/candlepin | |
# CLIENTS_CANDLEPIN_USERNAME: admin | |
# CLIENTS_CANDLEPIN_PASSWORD: admin | |
# CLIENTS_CANDLEPIN_DEVEL_ORG: true | |
# - name: db migration tests | |
# run: | | |
# make test-db-migrations | |
# env: | |
# DATABASE_HOST: localhost | |
# DATABASE_PORT: 5433 | |
# DATABASE_USER: postgres | |
# DATABASE_NAME: postgres | |
# DATABASE_PASSWORD: postgres | |
# CLIENTS_PULP_SERVER: http://localhost:8080 | |
# CLIENTS_PULP_USERNAME: admin | |
# CLIENTS_PULP_PASSWORD: password |