Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ci: introduce stage and preview deployments #46

Merged
merged 43 commits into from
Feb 24, 2023
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
225cdb7
chore: switch to node 18 in nvmrc
timonmasberg Feb 9, 2023
405a700
feat(api): boostrap api with e2e project
timonmasberg Feb 9, 2023
015095e
ci: bootstrap stage and preview deployments
timonmasberg Feb 11, 2023
f6a3937
fix: action paths
timonmasberg Feb 11, 2023
8b093ee
test: try get sender from pr
timonmasberg Feb 11, 2023
803e37c
ci: rework preview deployments to deploy on comment
timonmasberg Feb 11, 2023
7a5365b
chore: update lock after rebase
timonmasberg Feb 11, 2023
1fb1ce1
chore: add github to .prettierignore
timonmasberg Feb 11, 2023
70ce1a8
fix: create angular env for ci build
timonmasberg Feb 11, 2023
fd34229
chore: exclude e2es and bootstrap files from code coverage
timonmasberg Feb 11, 2023
4591afa
ci: add swa deployment environment
timonmasberg Feb 11, 2023
62a97e8
chore: move nx angular plugin to dev dependencies
timonmasberg Feb 11, 2023
65a4ec3
chore: simplify api build script
timonmasberg Feb 12, 2023
3938c9e
ci: remove unnecessary fetch-depth 0
timonmasberg Feb 12, 2023
11357d4
fix: workflow if statement
timonmasberg Feb 12, 2023
811f280
fix: ci use azure cli action instead of install script
timonmasberg Feb 12, 2023
ba91cf5
ci: use service principal secret for azure login
timonmasberg Feb 12, 2023
52b8892
ci: test if az cli works after login without install
timonmasberg Feb 12, 2023
a5b13ff
ci: switch azure cli to bash
timonmasberg Feb 12, 2023
f9f62b1
ci: test preview deployment
timonmasberg Feb 12, 2023
dc845b1
ci: debug preview deployment
timonmasberg Feb 12, 2023
bf64425
ci: debug preview deployment
timonmasberg Feb 12, 2023
1016e68
ci: debug preview deployment
timonmasberg Feb 12, 2023
066746a
fix: has deployment ci scripts
timonmasberg Feb 12, 2023
d425dd8
ci: ensure conventional commits and pr title
timonmasberg Feb 12, 2023
a26ce84
ci: ensure conventional commits and pr title
timonmasberg Feb 12, 2023
f73c180
ci: ensure conventional commits and pr title
timonmasberg Feb 12, 2023
f9ef1fa
ci: ensure conventional commits and pr title
timonmasberg Feb 12, 2023
cdebcad
ci: change ci workflow order to only report on success
timonmasberg Feb 12, 2023
0e4ae38
ci: fix deployment workflows and adapt new names (#50)
timonmasberg Feb 13, 2023
26fed6b
chore: rename client project to spa (#50)
timonmasberg Feb 13, 2023
d35d877
ci: adapt new names in comments (#50)
timonmasberg Feb 13, 2023
44e217f
chore(api): remove global prefix
timonmasberg Feb 13, 2023
658d7a1
chore: fix code smells
timonmasberg Feb 13, 2023
6a19785
ci: remove unnecessary steps
timonmasberg Feb 14, 2023
186d7c5
chore: add dependencies lable to renovate PRs
timonmasberg Feb 14, 2023
983fd7d
ci: ci should only run on needed action events
timonmasberg Feb 14, 2023
35e4cae
chore: migrate to latest nx
timonmasberg Feb 17, 2023
7957f47
ci: fix ci main not running on synchronize
timonmasberg Feb 17, 2023
f1b0a0f
ci: remove workspace lint from ci
timonmasberg Feb 17, 2023
50c6b55
ci: rename stage to next
timonmasberg Feb 19, 2023
d35c34d
chore(api): enable cors
timonmasberg Feb 22, 2023
b6f5644
ci: fix spa deployment env names
timonmasberg Feb 24, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/actions/build-and-deploy-api/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: 'build-and-deploy-api'
description: 'Builds API Project for Production and Deploys it to a given WA Slot'

inputs:
slot:
required: true
description: "Slot Identifier"
publishProfile:
required: true
description: "Azure Web App Publisher Profile"
outputs:
url:
description: "Backend URL"
JSPRH marked this conversation as resolved.
Show resolved Hide resolved
value: ${{ steps.wa-deployment.outputs.webapp-url }}

runs:
using: "composite"
steps:
- run: |
npx nx build api --prod
cd dist/apps/api
npm i
npm prune --omit=dev
JSPRH marked this conversation as resolved.
Show resolved Hide resolved
shell: bash
- name: Deploy Backend
JSPRH marked this conversation as resolved.
Show resolved Hide resolved
id: wa-deployment
uses: azure/webapps-deploy@v2
with:
app-name: 'kordis-api'
slot: ${{ inputs.slot }}
publish-profile: ${{ inputs.publishProfile }}
package: dist/apps/api/
48 changes: 48 additions & 0 deletions .github/actions/build-and-deploy-webapp/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: 'build-and-deploy-webapp'
description: 'Builds Webapp Project for Production and Deploys it to a given SWA Environment'

inputs:
apiUrl:
required: true
description: "Base URL of the API"
deploymentName:
required: true
description: "Unique identifier for the deployment"
deploymentEnv:
required: true
description: "Azure SWA Deployment Environment"
angularEnvironment:
required: true
description: "Angular environment to use from the project.json"
publishToken:
required: true
description: "Azure Static Web App Deployment Token"
outputs:
url:
description: "Frontend URL"
value: ${{ steps.swa-deployment.outputs.static_web_app_url }}

runs:
using: "composite"
steps:
- run: |
envsubst < apps/client/src/environments/environment.template > apps/client/src/environments/environment.${{ inputs.angularEnvironment }}.ts
npx nx build client --prod --configuration=${{ inputs.angularEnvironment }}
shell: bash
env:
IS_PRODUCTION: true
DEPLOYMENT_NAME: ${{ inputs.deploymentName }}
API_URL: ${{ inputs.apiUrl }}
- name: Deploy Webapp
id: swa-deployment
uses: Azure/static-web-apps-deploy@v1
with:
azure_static_web_apps_api_token: ${{ inputs.publishToken }}
action: "upload"
app_location: "dist/apps/client/"
output_location: ''
skip_app_build: true
skip_api_build: true
deployment_environment: ${{ inputs.deploymentEnv }}


6 changes: 4 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ jobs:
with:
node-version-file: '.nvmrc'
cache: 'npm'
- uses: nrwl/nx-set-shas@v3
- run: npm ci
- uses: nrwl/nx-set-shas@v3
- run: npx nx workspace-lint
- name: Check Formatting
run: npx nx format:check
Expand All @@ -34,6 +34,8 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
- name: Build
run: npx nx affected --target=build --parallel=3
run: |
touch apps/client/src/environments/environment.prod.ts
npx nx affected --target=build --parallel=3
- name: Run e2es
run: npx nx affected --target=e2e
213 changes: 213 additions & 0 deletions .github/workflows/preview-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,213 @@
name: Preview Deployment
on:
pull_request:
types: [ closed, synchronize ]
issue_comment:
types: [ created ]

jobs:
verify-admin:
if: github.event_name == 'issue_comment' && github.event.issue.pull_request == true && startsWith(github.event.comment.body, '/deploy-preview')
runs-on: ubuntu-latest
outputs:
is-admin: ${{ steps.is-admin-check.outputs.require-result }}
steps:
- uses: actions-cool/check-user-permission@v2
id: is-admin-check
with:
require: 'admin'

has-deployment:
if: github.event_name == 'pull_request'
outputs:
has-swa: ${{ steps.has-swa.outputs.has-swa }}
has-wa: ${{ steps.has-wa.outputs.has-wa }}
runs-on: ubuntu-latest
steps:
- name: Install Azure CLI
run: curl -sL https://aka.ms/InstallAzureCLIDeb | sudo bash
- name: Check if Webapp Environment exists
id: has-swa
uses: azure/CLI@v1
with:
inlineScript: >
namePresence=$(az staticwebapp environment list --name kordis-webapp | grep '"name": "pr-${{ github.event.pull_request.number }}"');
if [ -n "$namePresence" ]; then
echo "has-swa=true";
else
echo "has-swa=false";
fi
>> $GITHUB_OUTPUT
- name: Check if API Environment exists
id: has-wa
uses: azure/CLI@v1
with:
inlineScript: >
namePresence=$(az webapp deployment slot list -n kordis-api --resource-group KORDIS | grep '"name": "pr-${{ github.event.pull_request.number }}"');
if [ -n "$namePresence" ]; then
echo "has-wa=true";
else
echo "has-wa=false";
fi
>> $GITHUB_OUTPUT

deployment:
needs: verify-admin
runs-on: ubuntu-latest
if: |
(github.event_name == 'issue_comment' && github.event.issue.pull_request == true && startsWith(github.event.comment.body, '/deploy-preview')) &&
(needs.verify-admin.outputs.is-admin == true)
steps:
- name: Remove Comment
uses: izhangzhihao/delete-comment@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
issue_number: ${{ github.event.issue.number }}
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Initial Deployment Preview Comment
uses: peter-evans/[email protected]
id: pr-preview-comment
with:
issue-number: ${{ github.event.pull_request.number }}
body: |
### 🚧 Building Deployment Preview..
A preview of this Pull Request is being created. Hold tight while it's building ⚒️
This comment will be automatically updated when the preview is ready.
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Create PR Deployment Slot
uses: Azure/cli@v1
with:
inlineScript: az webapp deployment slot create --name kordis-api --resource-group KORDIS --slot pr-${{ github.event.pull_request.number }}
- name: Build and Deploy API
id: api-deployment
uses: ./.github/actions/build-and-deploy-api
with:
slot: "pr-${{ github.event.pull_request.number }}"
publishProfile: ${{ secrets.AZURE_WEBAPP_API_PUBLISH_PROFILE }}
- name: Build and Deploy Webapp
id: webapp-deployment
uses: ./.github/actions/build-and-deploy-webapp
with:
apiUrl: ${{ steps.api-deployment.outputs.url }}
deploymentName: "pr-${{ github.event.pull_request.number }}"
deploymentEnv: "pr-${{ github.event.pull_request.number }}"
angularEnvironment: "stage"
publishToken: ${{ secrets.AZURE_STATIC_WEB_APP_TOKEN }}
- name: Update PR Preview Comment
uses: peter-evans/[email protected]
with:
comment-id: ${{ steps.pr-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### 🚀 Deployment Preview
Webapp: ${{ steps.webapp-deployment.outputs.url }}
Backend: ${{ steps.api-deployment.outputs.url }}
Commit SHA: ${{ github.sha }}
reactions: "rocket"

update-deployment:
needs: has-deployment
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request' && github.event.action = 'synchronize') &&
(needs.has-deployment.outputs.has-swa == true || needs.has-deployment.outputs.has-wa == true)
steps:
- name: Find PR Preview Comment
uses: peter-evans/find-comment@v1
id: deploy-preview-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Deployment Preview
- name: Update PR Preview Comment
if: steps.deploy-preview-comment.outputs.comment-id != ''
uses: peter-evans/[email protected]
with:
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### 🚧 Building Deployment Preview..
The Pull Request preview is being updated. Hold tight while it's building ⚒️
This comment will be automatically updated when the new version is ready.
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Build and Deploy API
id: api-deployment
uses: ./.github/workflows/parts/api-build-deploy.yml
with:
slot: "pr-${{ github.event.pull_request.number }}"
publishProfile: ${{ secrets.AZURE_WEBAPP_API_PUBLISH_PROFILE }}
- name: Build and Deploy Webapp
id: webapp-deployment
uses: ./.github/workflows/parts/webapp-build.yml
with:
apiUrl: ${{ steps.api-deployment.outputs.url }}
deploymentName: "pr-${{ github.event.pull_request.number }}"
deploymentEnv: "pr-${{ github.event.pull_request.number }}"
angularEnvironment: "stage"
publishToken: ${{ secrets.AZURE_STATIC_WEB_APP_TOKEN }}
- name: Update PR Preview Comment
uses: peter-evans/[email protected]
with:
comment-id: ${{ steps.pr-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### 🚀 Deployment Preview
Webapp: ${{ steps.webapp-deployment.outputs.url }}
Backend: ${{ steps.api-deployment.outputs.url }}
Commit SHA: ${{ github.sha }}
reactions: "rocket"

delete-deployment:
needs: has-deployment
runs-on: ubuntu-latest
if: |
(github.event_name == 'pull_request' && github.event.action = 'closed') &&
(needs.has-deployment.outputs.has-swa == true || needs.has-deployment.outputs.has-wa == true)
steps:
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Delete PR Deployment Slot
uses: Azure/cli@v1
with:
inlineScript: |
az webapp deployment slot delete --name kordis-api --resource-group KORDIS --slot pr-${{ github.event.pull_request.number }} -y
az staticwebapp environment delete --name kordis-webapp --environment-name pr-${{ github.event.pull_request.number }} -y
- name: Find PR Preview Comment
uses: peter-evans/find-comment@v1
id: deploy-preview-comment
with:
issue-number: ${{ github.event.pull_request.number }}
comment-author: "github-actions[bot]"
body-includes: Deployment Preview
- name: Update PR Preview Comment
if: steps.deploy-preview-comment.outputs.comment-id != ''
uses: peter-evans/[email protected]
with:
comment-id: ${{ steps.deploy-preview-comment.outputs.comment-id }}
edit-mode: replace
body: |
### Deployment Preview
🏁 This PR has been closed. No deployment preview is available.
reactions: "hooray"

46 changes: 46 additions & 0 deletions .github/workflows/stage-deployment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
name: Stage Deployment
concurrency: staging_environment

on:
push:
branches:
- main

jobs:
deployment:
runs-on: ubuntu-latest
outputs:
url: ${{ steps.webapp-deployment.outputs.url }}
environment:
name: Stage
url: ${{ steps.webapp-deployment.outputs.url }}
steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0
- uses: actions/setup-node@v3
with:
node-version-file: '.nvmrc'
cache: 'npm'
- run: npm ci
- name: Azure Login
uses: Azure/[email protected]
with:
client-id: ${{ secrets.AZURE_CLIENT_ID }}
tenant-id: ${{ secrets.AZURE_TENANT_ID }}
subscription-id: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
- name: Build and Deploy API
id: api-deployment
uses: ./.github/actions/build-and-deploy-api
with:
slot: "stage"
publishProfile: ${{ secrets.AZURE_WEBAPP_API_PUBLISH_PROFILE }}
- name: Build and Deploy Webapp
id: webapp-deployment
uses: ./.github/actions/build-and-deploy-webapp
with:
apiUrl: ${{ steps.api-deployment.outputs.url }}
deploymentName: "commit-${{ github.sha }}"
angularEnvironment: "stage"
deploymentEnv: "stage"
publishToken: ${{ secrets.AZURE_STATIC_WEB_APP_TOKEN }}
2 changes: 1 addition & 1 deletion .nvmrc
Original file line number Diff line number Diff line change
@@ -1 +1 @@
16
18
1 change: 1 addition & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
/dist
/coverage
package-lock.json
.github
18 changes: 18 additions & 0 deletions apps/api-e2e/.eslintrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": ["../../.eslintrc.json"],
"ignorePatterns": ["!**/*"],
"overrides": [
{
"files": ["*.ts", "*.tsx", "*.js", "*.jsx"],
"rules": {}
},
{
"files": ["*.ts", "*.tsx"],
"rules": {}
},
{
"files": ["*.js", "*.jsx"],
"rules": {}
}
]
}
Loading