-
Notifications
You must be signed in to change notification settings - Fork 1
154 lines (144 loc) · 6.09 KB
/
build-and-deploy.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: "Build and deploy"
on:
push:
release:
types: [published]
workflow_dispatch:
inputs:
module:
description: "Module to build and deploy"
required: true
type: choice
options:
- fullstack
- frontend
- backend
- metabase
behavior:
description: Workflow behavior
type: choice
options:
- deploy-dev
- test-only
- deploy-only
required: true
permissions:
contents: write
packages: write
id-token: write
jobs:
evaluate-build-module:
permissions: write-all
name: Evaluate modules to build
runs-on: ubuntu-latest
outputs:
build_module: ${{ steps.set-module.outputs.build_module }}
build_metabase: ${{ steps.set-module.outputs.build_metabase }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Check change
id: check-change
uses: dorny/paths-filter@v3
with:
filters: |
frontend:
- 'frontend/**'
- '.github/workflows/build-and-deploy-frontend.yml'
- '.github/workflows/build-and-deploy.yml'
backend:
- '!frontend/**'
metabase:
- '.metabase_version'
- '.nais/dev/metabase/**'
- '.nais/prod/metabase/**'
- '.nais/vars.yaml'
ref: ${{ github.ref_name }}
- name: Set module to build and deploy
id: set-module
run: |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then
echo "build_module=${{ github.event.inputs.module }}" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == "release" ]; then
echo "build_module=fullstack" >> $GITHUB_OUTPUT
elif [ "${{ steps.check-change.outputs.frontend }}" == 'true' ] && [ "${{ steps.check-change.outputs.backend }}" == 'false' ]; then
echo "build_module=frontend" >> $GITHUB_OUTPUT
elif [ "${{ steps.check-change.outputs.frontend }}" == 'false' ] && [ "${{ steps.check-change.outputs.backend }}" == 'true' ]; then
echo "build_module=backend" >> $GITHUB_OUTPUT
elif [ "${{ steps.check-change.outputs.frontend }}" == 'true' ] && [ "${{ steps.check-change.outputs.backend }}" == 'true' ]; then
echo "build_module=fullstack" >> $GITHUB_OUTPUT
else
echo "build_module=none" >> $GITHUB_OUTPUT
fi
if [ "${{ github.event.inputs.module }}" == 'metabase' ] || [ "${{ github.event.inputs.module }}" == 'fullstack' ]; then
echo "build_metabase=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" == "release" ]; then
echo "build_metabase=true" >> $GITHUB_OUTPUT
elif [ "${{ github.event_name }}" != "workflow_dispatch" ] && [ "${{ steps.check-change.outputs.metabase }}" == 'true' ]; then
echo "build_metabase=true" >> $GITHUB_OUTPUT
else
echo "build_metabase=false" >> $GITHUB_OUTPUT
fi
- name: Show modules to build
run: |
echo "Modules to build: ${{ steps.set-module.outputs.build_module }}"
echo "Build metabase: ${{ steps.set-module.outputs.build_metabase }}"
evaluate-deploy-environment:
name: Evaluate environments to deploy
runs-on: ubuntu-latest
outputs:
deploy_env: ${{ steps.set-environment.outputs.deploy_env }}
notest: ${{ steps.set-environment.outputs.notest }}
steps:
- name: Set environment based on event
id: set-environment
run: |
if [ ${{ github.event_name }} == push ]; then
if [ ${{ github.ref }} == 'refs/heads/main' ]; then
echo "deploy_env=prod-and-dev" >> $GITHUB_OUTPUT
else
echo "deploy_env=none" >> $GITHUB_OUTPUT
fi
elif [ ${{ github.event_name }} == release ]; then
echo "deploy_env=prod-only" >> $GITHUB_OUTPUT
elif [ ${{ github.event_name }} == workflow_dispatch ]; then
if [ ${{ github.event.inputs.behavior }} == 'deploy-dev' ]; then
echo "deploy_env=dev-only" >> $GITHUB_OUTPUT
elif [ ${{ github.event.inputs.behavior }} == 'deploy-only' ]; then
echo "deploy_env=dev-only" >> $GITHUB_OUTPUT
echo "notest=true" >> $GITHUB_OUTPUT
elif [ ${{ github.event.inputs.behavior }} == 'test-only' ]; then
echo "deploy_env=none" >> $GITHUB_OUTPUT
fi
fi
- name: Show environments to deploy
run: |
echo "Deploy to: ${{ steps.set-environment.outputs.deploy_env }}"
echo "Bypass test: ${{ steps.set-environment.outputs.notest }}"
call-build-and-deploy-frontend:
needs: [evaluate-deploy-environment, evaluate-build-module]
name: Frontend
if: ${{ needs.evaluate-build-module.outputs.build_module == 'fullstack' || needs.evaluate-build-module.outputs.build_module == 'frontend' }}
uses: ./.github/workflows/build-and-deploy-frontend.yml
with:
deploy_env: ${{ needs.evaluate-deploy-environment.outputs.deploy_env }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
secrets: inherit
call-build-and-deploy-backend:
needs: [evaluate-deploy-environment, evaluate-build-module]
name: Backend
if: ${{ needs.evaluate-build-module.outputs.build_module == 'fullstack' || needs.evaluate-build-module.outputs.build_module == 'backend' }}
uses: ./.github/workflows/build-and-deploy-backend.yml
with:
deploy_env: ${{ needs.evaluate-deploy-environment.outputs.deploy_env }}
project_id: ${{ vars.NAIS_MANAGEMENT_PROJECT_ID }}
notest: ${{ needs.evaluate-deploy-environment.outputs.notest }}
secrets: inherit
call-build-and-deploy-metabase:
needs: [evaluate-deploy-environment, evaluate-build-module]
name: Metabase
if: ${{ needs.evaluate-build-module.outputs.build_metabase == 'true' }}
uses: ./.github/workflows/deploy-metabase.yaml
with:
deploy_env: ${{ needs.evaluate-deploy-environment.outputs.deploy_env }}
secrets: inherit