-
Notifications
You must be signed in to change notification settings - Fork 67
156 lines (136 loc) · 5 KB
/
base.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
155
156
# Reusable workflow
name: base
# Controls when the action will run.
on:
# Run only when called from another workflow
workflow_call:
inputs:
values-file:
required: true
type: string
image-name:
required: true
type: string
git-version-mode:
required: true
type: string
secrets:
REGISTRY_URL:
required: true
REGISTRY_USER:
required: true
REGISTRY_PASSWORD:
required: true
COMMON_HELMCHART_NAME:
required: true
COMMON_HELMCHART_VERSION:
required: true
APP_NAME_BASE:
required: true
env:
ACTIONS_ALLOW_UNSECURE_COMMANDS: true
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
build-and-test:
runs-on: ubuntu-latest
env:
ACTIONS_STEP_DEBUG: true
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: '18.x'
cache: 'yarn'
cache-dependency-path: |
**/yarn.lock
- name: build
run: |
yarn
yarn generate-components-api
yarn build
cd server && yarn
- name: test
run: yarn test-ci
- name: eslint
run: yarn eslint
- name: stylelint
run: yarn stylelint
- name: Login to registry
uses: docker/login-action@v2
with:
registry: ${{ secrets.REGISTRY_URL }}
username: ${{ secrets.REGISTRY_USER }}
password: ${{ secrets.REGISTRY_PASSWORD }}
- name: Docker meta
id: meta
uses: docker/metadata-action@v4
with:
# list of Docker images to use as base name for tags
images: |
${{ secrets.REGISTRY_URL }}/${{ inputs.image-name }}
# generate Docker tags based on the following events/attributes
# This is our main tag for image in form sha-XXXXXX which we will use in helm values file (see "Preparation and Helm chart packaging" job)
tags: |
type=sha
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v2
- name: Build and push
id: docker_build
uses: docker/build-push-action@v3
with:
context: ./
file: ./Dockerfile
push: true
# Image will be tagged with all tags from "Docker meta" step
tags: ${{ steps.meta.outputs.tags }}
package:
needs: build-and-test
runs-on: ubuntu-20.04 # Gitversion requires .NET SDK 3.1
env:
ACTIONS_STEP_DEBUG: true
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
VALUES_FILE: ${{ inputs.values-file }}
COMMON_HELMCHART_VER: ${{ secrets.COMMON_HELMCHART_VERSION }}
steps:
- uses: actions/checkout@v3
name: Code checkout
with:
fetch-depth: 0
# install Gitversion to obtain semver version
- name: Install GitVersion
uses: gittools/actions/gitversion/[email protected]
with:
versionSpec: '5.8.3'
# need to updated
- name: Version determination
id: gitversion
uses: gittools/actions/gitversion/[email protected]
with:
additionalArguments: ${{ inputs.git-version-mode }}
useConfigFile: true
configFilePath: GitVersion.yml
- name: Install Helm
uses: azure/setup-helm@v3
with:
version: v3.8.0
- name: Preparation and Helm chart packaging
run: |
echo ${{ secrets.REGISTRY_PASSWORD }} | helm registry login ${{ secrets.REGISTRY_URL }} --username ${{ secrets.REGISTRY_USER }} --password-stdin
mkdir helmchart && cd ./helmchart # helm cannot untar file to the repo with the same name as a package. To avoid error we create temp folder
helm pull oci://${{ secrets.REGISTRY_URL }}/helm/${{ secrets.COMMON_HELMCHART_NAME }} --version ${COMMON_HELMCHART_VER} --untar
echo "[INFO] Replace Docker image tag in helm chart..."
sed -i -e "s/tag: latest/tag: sha-${GITVERSION_SHORTSHA}/g" ${{ secrets.COMMON_HELMCHART_NAME }}/${VALUES_FILE}
- name: Packaging and Uploading Helm Chart
run: |
cd ./helmchart
# workaround to avoid Helm chart versioning issues
current_timestamp=$(date +%s)
export helm_tag="$GITVERSION_MAJOR.$GITVERSION_MINOR.$current_timestamp"
echo "[INFO] ${helm_tag}..."
echo "[INFO] Replace Helm Chart package version..."
sed -i -e "s/version: ${COMMON_HELMCHART_VER}/version: ${helm_tag}/g" ${{ secrets.COMMON_HELMCHART_NAME }}/Chart.yaml
echo "[INFO] Changing Helm Chart package name..."
sed -i -e "s/name: ${{ secrets.COMMON_HELMCHART_NAME }}/name: ${{ secrets.APP_NAME_BASE }}/g" ${{ secrets.COMMON_HELMCHART_NAME }}/Chart.yaml
helm package ${{ secrets.COMMON_HELMCHART_NAME }}
helm push ${{ secrets.APP_NAME_BASE }}-${helm_tag}.tgz oci://${{ secrets.REGISTRY_URL }}/helm