-
-
Notifications
You must be signed in to change notification settings - Fork 0
executable file
·195 lines (162 loc) · 6.57 KB
/
ci-cd.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
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
name: 'CI / CD'
on:
workflow_dispatch:
push:
branches:
- 'development'
- 'production'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
env:
CI_CD_LOCAL_API_SERVICE_IMAGE: ci-cd.local/api-service
CI_DEVELOPMENT_BRANCH: ${{ vars.CI_DEVELOPMENT_BRANCH }}
CI_PRODUCTION_BRANCH: ${{ vars.CI_PRODUCTION_BRANCH }}
ENABLE_BUILD_IMAGE: ${{ vars.ENABLE_BUILD_IMAGE }}
IMAGE_TAG_DEVELOPMENT: ${{ vars.IMAGE_TAG_DEVELOPMENT }}
IMAGE_TAG_PRODUCTION: ${{ vars.IMAGE_TAG_PRODUCTION }}
ENABLE_PUSH_IMAGE: ${{ vars.ENABLE_PUSH_IMAGE }}
REGISTRY_URL: ${{ secrets.REGISTRY_URL }}
REGISTRY_USERNAME: ${{ secrets.REGISTRY_USERNAME }}
REGISTRY_TOKEN: ${{ secrets.REGISTRY_TOKEN }}
IMAGE_NAME: ${{ vars.IMAGE_NAME }}
ENABLE_TRIGGER_DEPLOY: ${{ vars.ENABLE_TRIGGER_DEPLOY }}
DEPLOY_DISPATCH_TOKEN: ${{ secrets.DEPLOY_DISPATCH_TOKEN }}
DEPLOY_OWNER: ${{ vars.DEPLOY_OWNER }}
DEPLOY_REPOSITORY: ${{ vars.DEPLOY_REPOSITORY }}
DEPLOY_WORKFLOW: ${{ vars.DEPLOY_WORKFLOW }}
DEPLOY_BRANCH: ${{ vars.DEPLOY_BRANCH }}
jobs:
ci-cd:
runs-on: ubuntu-latest
permissions:
contents: write
id-token: write
steps:
- uses: actions/create-github-app-token@v1
id: app-token
with:
app-id: ${{ secrets.LADESA_BOT_ID }}
private-key: ${{ secrets.LADESA_BOT_SECRET }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
token: ${{ steps.app-token.outputs.token }}
# - name: Set up QEMU
# uses: docker/setup-qemu-action@v3
- name: Use Node.js 22.x
uses: actions/setup-node@v4
with:
node-version: 22.x
cache: 'npm'
cache-dependency-path: package-lock.json
- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3
- name: Login into Registry
if: ${{ env.ENABLE_PUSH_IMAGE == 'true' }}
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY_URL }}
username: ${{ env.REGISTRY_USERNAME }}
password: ${{ env.REGISTRY_TOKEN }}
- name: Build api service locally
if: ${{ env.ENABLE_BUILD_IMAGE == 'true' }}
uses: docker/build-push-action@v6
with:
load: true
push: false
tags: ${{ env.CI_CD_LOCAL_API_SERVICE_IMAGE }}
file: 'Dockerfile.service'
cache-from: type=gha
cache-to: type=gha,mode=max
- name: 'Codegen: OpenAPI JSON with built image'
uses: addnab/docker-run-action@v3
if: ${{ env.ENABLE_BUILD_IMAGE == 'true' }}
with:
image: ${{ env.CI_CD_LOCAL_API_SERVICE_IMAGE }}
options: |
-u 1001
-v ${{ github.workspace }}/integrations/openapi-json:/tmp/openapi-json
-e OUT_FILE=/tmp/openapi-json/generated.json
run: npm run gen:openapi
- run: npm config set loglevel=verbose
- run: npm ci
- name: 'Codegen: remaining integrations'
shell: bash
working-directory: integrations
run: |
export CI_CD_CODEGEN_NPM_API_CLIENT_FETCH=true
./codegen.sh
- run: git config user.name 'github-actions[bot]'
- run: git config user.email 'github-actions[bot]@users.noreply.github.com'
- name: Log git changes
run: |
git status
- name: Commit generated code if possible
shell: bash
run: |
if [[ ! "$(git status --porcelain | grep integrations | wc -l)" == "0" ]]; then
git merge -m "chore: merge origin/${{ github.ref_name }} into ${{ github.ref_name }} [skip ci]" -X theirs origin/${{ github.ref_name }};
git add -A integrations;
git commit -m "feat(integrations): codegen [skip ci]"
git push origin ${{ github.ref_name }}
fi
- name: Prepare NPM token
uses: ./.github/actions/prepare-npm-token
with:
npm-token: ${{ secrets.NPM_TOKEN }}
- name: Release development
run: npm run release:development
if: github.ref_name == env.CI_DEVELOPMENT_BRANCH
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Release production
run: npm run release:production
if: github.ref_name == env.CI_PRODUCTION_BRANCH
# env:
# GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: update development from production
if: github.ref_name == env.CI_PRODUCTION_BRANCH
run: |
git checkout ${{ env.CI_DEVELOPMENT_BRANCH }};
git merge -m "chore: merge ${{ env.CI_PRODUCTION_BRANCH }} into ${{ env.CI_DEVELOPMENT_BRANCH }} [skip ci]" -X theirs ${{ env.CI_PRODUCTION_BRANCH }};
git push origin ${{ env.CI_DEVELOPMENT_BRANCH }};
git checkout ${{ env.CI_PRODUCTION_BRANCH }};
- name: Determine target image name
id: image-name
run: |
IMAGE_NAME="disabled"
if [[ "${{env.ENABLE_BUILD_IMAGE}}" == "true" ]]; then
IMAGE_NAME="local-service"
if [[ "${{ github.ref_name }}" == "${{ env.CI_DEVELOPMENT_BRANCH }}" ]]; then
IMAGE_NAME="${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_DEVELOPMENT }}"
elif [[ "${{ github.ref_name }}" == "${{ env.CI_PRODUCTION_BRANCH }}" ]]; then
IMAGE_NAME="${{ env.REGISTRY_URL }}/${{ env.IMAGE_NAME }}:${{ env.IMAGE_TAG_PRODUCTION }}"
fi
fi
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_OUTPUT
- name: Build and push image
if: ${{ steps.image-name.outputs.IMAGE_NAME != 'disabled' }}
uses: docker/build-push-action@v6
with:
load: true
context: .
file: 'Dockerfile.service'
push: ${{ env.ENABLE_PUSH_IMAGE == 'true' }}
tags: ${{ steps.image-name.outputs.IMAGE_NAME }}
cache-from: type=gha
cache-to: type=gha,mode=max
api-service-deploy:
runs-on: ubuntu-latest
needs: ci-cd
steps:
- name: Dispatch infrastructure deploy workflow
if: ${{ env.ENABLE_BUILD_IMAGE == 'true' && env.ENABLE_PUSH_IMAGE == 'true' && env.ENABLE_TRIGGER_DEPLOY == 'true' }}
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ env.DEPLOY_DISPATCH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{ env.DEPLOY_OWNER }}/${{ env.DEPLOY_REPOSITORY }}/actions/workflows/${{ env.DEPLOY_WORKFLOW }}/dispatches \
-d '{"ref":"${{ env.DEPLOY_BRANCH }}","inputs":{}}'