Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into chore/pwa
Browse files Browse the repository at this point in the history
# Conflicts:
#	.prettierrc
#	apps/spa/project.json
#	apps/spa/src/app/app.module.ts
#	apps/spa/src/index.html
#	package-lock.json
  • Loading branch information
timonmasberg committed Feb 15, 2024
2 parents c0895ac + 8b93c9f commit 08978fb
Show file tree
Hide file tree
Showing 85 changed files with 3,821 additions and 5,656 deletions.
34 changes: 14 additions & 20 deletions .github/actions/build-and-deploy-api/action.yml
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
name: 'build-and-deploy-api'
description: 'Builds API Project for Production and Deploys it to a given WA Slot'
description: 'Builds API project for production and deploys it to a given environment'

inputs:
releaseVersion:
required: true
description: "Release Version (Commit or Tag)"
slot:
deploymentEnv:
required: true
description: "Slot Identifier"
mongoUri:
required: true
description: "Mongo Connection URI"
sentryKey:
required: true
description: "Sentry DSN Key"
description: "Deployment Environment"
sentryAuthToken:
required: true
description: "Sentry Auth Token"
Expand All @@ -26,6 +20,9 @@ inputs:
containerRegistryPassword:
required: true
description: "Container registry password"
containerTag:
required: true
description: "Container tag"
outputs:
url:
description: "API URL"
Expand All @@ -42,6 +39,11 @@ runs:
registry: ${{ inputs.containerRegistryUrl }}
username: ${{ inputs.containerRegistryUsername }}
password: ${{ inputs.containerRegistryPassword }}
- name: Create Environment
run: envsubst < apps/api/src/app/environment.template > apps/api/src/app/environment.ts
shell: bash
env:
RELEASE_VERSION: ${{ inputs.releaseVersion }}
- name: Build app
run: |
npx nx build api --prod
Expand All @@ -55,20 +57,12 @@ runs:
context: ./
file: ./apps/api/Dockerfile
build-args: |
NODE_VERSION=${{ steps.node-version-check.outputs.node-version}}
NODE_VERSION=${{ steps.node-version-check.outputs.node-version }}
push: true
tags: |
ghcr.io/kordis-leitstelle/kordis-api:${{ inputs.releaseVersion}}
${{ inputs.containerTag }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Set environment for deployment
run: envsubst < apps/api/src/.env.template > dist/apps/api/.env
env:
MONGODB_URI: ${{ inputs.mongoUri }}
ENVIRONMENT_NAME: ${{ inputs.slot }}
RELEASE_VERSION: ${{ inputs.releaseVersion }}
SENTRY_KEY: ${{ inputs.sentryKey }}
shell: bash
- name: Deploy API
id: wa-deployment
run: echo "url=placeholder" >> $GITHUB_OUTPUT
Expand All @@ -80,6 +74,6 @@ runs:
SENTRY_ORG: kordis-leitstelle
SENTRY_PROJECT: kordis-api
with:
environment: ${{ inputs.slot }}
environment: ${{ inputs.deploymentEnv }}
version: ${{ inputs.releaseVersion }}
sourcemaps: ./dist/apps/api
58 changes: 37 additions & 21 deletions .github/actions/build-and-deploy-spa/action.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,28 @@
name: 'build-and-deploy-spa'
description: 'Builds SPA Project for Production and Deploys it to a given SWA Environment'
description: 'Builds SPA project for production and deploys it to a given environment'

inputs:
apiUrl:
required: true
description: "Base URL of the API"
oauthConfig:
required: true
description: "OAuthConfig from the angular-oauth2-oidc package"
releaseVersion:
required: true
description: "Release Version (Commit or Tag)"
deploymentEnv:
required: true
description: "Deployment Environment"
sentryKey:
required: true
description: "Sentry DSN Key"
sentryAuthToken:
required: true
description: "Sentry Auth Token"
containerRegistryUrl:
required: true
description: "Container registry url"
containerRegistryUsername:
required: true
description: "Container registry username"
containerRegistryPassword:
required: true
description: "Container registry password"
containerTag:
required: true
description: "Container tag"
outputs:
url:
description: "SPA URL"
Expand All @@ -28,25 +31,38 @@ outputs:
runs:
using: "composite"
steps:
- name: Generate Third-Party Licenses
run: npx --yes [email protected] --input package.json --output apps/spa/src/assets/third-party-licenses.txt --ci
shell: bash
- run: |
envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.prod.ts
npx nx build spa --prod
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v3
with:
registry: ${{ inputs.containerRegistryUrl }}
username: ${{ inputs.containerRegistryUsername }}
password: ${{ inputs.containerRegistryPassword }}
- run: envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.ts
shell: bash
env:
IS_PRODUCTION: true
ENVIRONMENT_NAME: ${{ inputs.deploymentEnv }}
API_URL: ${{ inputs.apiUrl }}
OAUTH_CONFIG: ${{ inputs.oauthConfig }}
RELEASE_VERSION: ${{ inputs.releaseVersion }}
SENTRY_KEY: ${{ inputs.sentryKey }}
- run: |
npx nx build spa --prod
npx --yes [email protected] --input package.json --output dist/apps/spa/browser/assets/third-party-licenses.txt --ci
shell: bash
- name: Build and push image
uses: docker/build-push-action@v5
with:
context: ./
file: ./apps/spa/docker/Dockerfile
push: true
tags: |
${{ inputs.containerTag }}
cache-from: type=gha
cache-to: type=gha,mode=max
- name: Deploy SPA
id: spa-deployment
shell: bash
run: echo "url=placeholder" >> $GITHUB_OUTPUT
- name: Build SPA with source maps
- name: Build SPA with source maps for sentry
run: npx nx build spa --prod --source-map=true
shell: bash
- name: Create Sentry release
Expand Down
39 changes: 24 additions & 15 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
with:
fetch-depth: 0
- name: Ensure Conventional Commits
uses: webiny/action-conventional-commits@v1.2.0
uses: webiny/action-conventional-commits@v1.3.0
- name: Setup node
uses: actions/setup-node@v4
with:
Expand All @@ -34,33 +34,42 @@ jobs:
- name: Lint
run: npx nx affected --target=lint --parallel=3

- name: Run Tests with Code Coverage
run: npx nx affected --target=test --parallel=3 --ci --coverage --coverageReporters=lcov
- name: Run all tests
if: github.event_name == 'push'
run: npx nx run-many --all --target=test --parallel --ci --coverage --coverageReporters=lcov
- name: Run affected tests
if: github.event_name == 'pull_request'
run: npx nx affected --target=test --parallel --ci --coverage --coverageReporters=lcov
- name: Merge Coverage files
run: '[ -d "./coverage/" ] && ./node_modules/.bin/lcov-result-merger ./coverage/**/lcov.info ./coverage/lcov.info || exit 0'

- name: Create SPA Environment File
run: envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.prod.ts
- name: Create Environments
run: |
envsubst < apps/spa/src/environments/environment.template > apps/spa/src/environments/environment.ts
envsubst < apps/api/src/app/environment.template > apps/api/src/app/environment.ts
env:
IS_PRODUCTION: true
ENVIRONMENT_NAME: 'ci'
RELEASE_VERSION: ${{ github.sha }}
API_URL: http://localhost:3000/
OAUTH_CONFIG: undefined
- name: Build
run: npx nx run-many -t build --all --parallel=3
run: |
npx nx run-many -t build --all --parallel=3
docker build -t kordis-api:${{ github.sha }} -f ./apps/api/Dockerfile --build-arg NODE_VERSION=$(cat .nvmrc | tr -cd '[:digit:].') . &
docker build -t kordis-spa:${{ github.sha }} -f ./apps/spa/docker/Dockerfile . &
wait
- name: Install Chromium for E2Es
run: npx -y playwright install chromium
- name: Start and prepare MongoDB for E2Es
run: ./tools/db/kordis-db.sh init e2edb
- name: Start API and SPA containers
run: |
docker run -d -p 3000:3333 -e MONGODB_URI=mongodb://host.docker.internal:27017/e2edb kordis-api:${{ github.sha }}
docker run -d -p 4200:8080 -e API_URL=http://localhost:3000 kordis-spa:${{ github.sha }}
- name: Run E2Es
run: npm run serve:all:prod & (npx wait-on tcp:3000 && npx wait-on http://localhost:4200 && npx nx e2e spa-e2e)
run: npx wait-on -t 30s tcp:3000 && npx wait-on -t 30s http://localhost:4200 && npx nx e2e spa-e2e --skipInstall
env:
E2E_BASE_URL: http://localhost:4200/
MONGODB_URI: mongodb://127.0.0.1:27017/e2edb
ENVIRONMENT_NAME: 'ci'
RELEASE_VERSION: ${{ github.sha }}
SENTRY_KEY: ${{ secrets.SENTRY_KEY }}
PORT: 3000
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-test-results
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,11 @@ jobs:
uses: actions/checkout@v4

- name: Initialize CodeQL
uses: github/codeql-action/init@v2
uses: github/codeql-action/init@v3
with:
languages: ${{ matrix.language }}

- name: Perform CodeQL Analysis
uses: github/codeql-action/analyze@v2
uses: github/codeql-action/analyze@v3
with:
category: '/language:${{matrix.language}}'
14 changes: 7 additions & 7 deletions .github/workflows/next-deployment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,13 @@ jobs:
id: api-deployment
uses: ./.github/actions/build-and-deploy-api
with:
slot: "next"
deploymentEnv: "next"
releaseVersion: ${{ github.sha }}
mongoUri: ${{ secrets.DEV_MONGODB_URI }}
sentryKey: ${{ secrets.API_SENTRY_KEY }}
sentryAuthToken: ${{ secrets.SENTRY_AUTH_TOKEN }}
containerRegistryUrl: ghcr.io
containerRegistryUsername: ${{ github.actor }}
containerRegistryPassword: ${{ secrets.GITHUB_TOKEN }}
containerTag: ghcr.io/kordis-leitstelle/kordis-api:${{ github.sha }}
- name: Apply Database Migrations
run: echo "add again once infrastructure is set up" # ./tools/db/kordis-db.sh apply-pending-migrations
env:
Expand All @@ -47,12 +46,13 @@ jobs:
id: spa-deployment
uses: ./.github/actions/build-and-deploy-spa
with:
apiUrl: ${{ steps.api-deployment.outputs.url }}
oauthConfig: ${{ secrets.DEV_OAUTH_CONFIG }}
releaseVersion: ${{ github.sha }}
deploymentEnv: "next"
sentryKey: ${{ secrets.SPA_SENTRY_KEY }}
sentryAuthToken: ${{ secrets.SENTRY_AUTH_TOKEN }}
containerRegistryUrl: ghcr.io
containerRegistryUsername: ${{ github.actor }}
containerRegistryPassword: ${{ secrets.GITHUB_TOKEN }}
containerTag: ghcr.io/kordis-leitstelle/kordis-spa:${{ github.sha }}

e2e:
needs: deployment
Expand All @@ -69,7 +69,7 @@ jobs:
env:
E2E_BASE_URL: ${{ needs.deployment.outputs.spaUrl }}
AADB2C_TEST_USERS: ${{ secrets.E2E_TEST_USERS }}
- uses: actions/upload-artifact@v3
- uses: actions/upload-artifact@v4
if: failure()
with:
name: e2e-test-results
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/nx-migration-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- uses: timonmasberg/[email protected].8
- uses: timonmasberg/[email protected].12
with:
repoToken: ${{ secrets.WORKFLOW_PAT }}
prTitle: 'chore(deps): migrate nx to $VERSION'
Loading

0 comments on commit 08978fb

Please sign in to comment.