-
Notifications
You must be signed in to change notification settings - Fork 0
185 lines (163 loc) · 5.39 KB
/
toolkit-build.yaml
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
name: Toolkit Dry Run Dev
on:
pull_request:
paths:
- "toolkit/**"
- ".github/workflows/toolkit-build.yaml"
- "!**/*.md"
env:
COLUMNS: 99
TOOLKIT_ENV: staging
TOOLKIT_VERSION: 0.3.18
PYTHON_VERSION: "3.11"
CLIENT_CONFIG_FILE: "power_ops_config.yaml"
CONFIGURATION_FILE: "resync/configuration.yaml"
jobs:
get-toolkit-version:
runs-on: ubuntu-latest
outputs:
image: ${{ steps.image.outputs.image }}
steps:
- id: image
run: echo "image=cognite/toolkit:$TOOLKIT_VERSION" >> "$GITHUB_OUTPUT"
build-modules:
name: Toolkit Dry Run
needs: get-toolkit-version
runs-on: ubuntu-latest
environment: CI
container:
image: ${{ needs.get-toolkit-version.outputs.image }}
env:
LOGIN_FLOW: client_credentials
CDF_CLUSTER: ${{ vars.CLUSTER }}
CDF_PROJECT: ${{ vars.PROJECT }}
IDP_CLIENT_ID: ${{ vars.CLIENT_ID }}
IDP_CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
IDP_TENANT_ID: ${{ vars.TENANT_ID }}
defaults:
run:
shell: bash
outputs:
build-status: ${{ steps.build.outcome }}
deploy-status: ${{ steps.deploy.outcome }}
steps:
- uses: actions/checkout@v4
- name: Create a folder for logs
run: |
if [ ! -d "cdf-tk-logs" ]; then
mkdir cdf-tk-logs
fi
- name: Opt-in for data collection
run: cdf collect opt-in
- name: Build modules
id: build
continue-on-error: true
run: |
set -o pipefail
cdf build --verbose --env $TOOLKIT_ENV --build-dir cdf-tk-build | tee cdf-tk-logs/build.log
- name: Dry run modules deployment
id: deploy
continue-on-error: true
if: ${{ steps.build.outcome == 'success' }}
run: |
set -o pipefail
cdf deploy --verbose --dry-run cdf-tk-build | tee cdf-tk-logs/deploy.log
- name: Store logs
id: store-logs
uses: actions/upload-artifact@v4
with:
name: cdf-tk-logs
path: cdf-tk-logs/
retention-days: 1
if-no-files-found: error
resync-purge:
name: Resync Purge Dry Run to CDF project ${{ vars.PROJECT }}
environment:
name: CI
runs-on: ubuntu-latest
outputs:
purge-status: ${{ steps.purge.outcome }}
steps:
- uses: actions/checkout@v4
- name: Create a folder for logs
run: |
if [ ! -d "resync-logs" ]; then
mkdir resync-logs
fi
- uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}
- name: Install dependencies
run: |
python3 -m pip install --upgrade pip poetry==1.*
poetry config virtualenvs.create false
poetry install
- name: Run resync plan
id: purge
env:
CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
CLIENT_ID: ${{ vars.CLIENT_ID }}
PROJECT: ${{ vars.PROJECT }}
CLUSTER: ${{ vars.CLUSTER }}
TENANT_ID: ${{ vars.TENANT_ID }}
continue-on-error: true
run: |
echo Running resync plan in CDF environment $PROJECT
set -o pipefail
powerops purge $CLIENT_CONFIG_FILE $CONFIGURATION_FILE --dry-run --logs resync-logs/purge.log
- name: Store logs
id: store-logs
uses: actions/upload-artifact@v4
with:
name: resync-logs
path: resync-logs/
retention-days: 1
if-no-files-found: error
pr-writeback:
needs: [build-modules, resync-purge]
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- uses: actions/checkout@v4
- name: Download toolkit log files
id: download-tk-logs
uses: actions/download-artifact@v4
with:
name: cdf-tk-logs
path: cdf-tk-logs
- name: Download resync log files
id: download-resync-logs
uses: actions/download-artifact@v4
with:
name: resync-logs
path: resync-logs
- name: Write a comment back to the PR
id: write_comment
shell: bash
run: |
set -e
B_STATUS="Build status: **${{ needs.build-modules.outputs.build-status }}**"
DR_STATUS="Dry run status: **${{ needs.build-modules.outputs.deploy-status }}**"
RP_STATUS="Resync purge status: **${{ needs.resync-purge.outputs.purge-status }}**"
if [ -f cdf-tk-logs/deploy.log ]; then
MSG=$(cat cdf-tk-logs/deploy.log)
elif [ -f cdf-tk-logs/build.log ]; then
MSG=$(cat cdf-tk-logs/build.log)
else
MSG='Error. Check toolkit workflow run for details.'
fi
if [ -f resync-logs/purge.log ]; then
MSG_PURGE=$(cat resync-logs/purge.log)
else
MSG_PURGE='Error. Check purge workflow run for details.'
fi
REPO_URL=$(jq '.repository.html_url' -r < "$GITHUB_EVENT_PATH")
PR_NUMBER=$(jq '.number' -r < "$GITHUB_EVENT_PATH")
RUN_LINK="[$GITHUB_RUN_ID]($REPO_URL/actions/runs/$GITHUB_RUN_ID)"
printf 'Toolkit dry run triggered: %s\n\n%s\n%s\n%s\n\n```\n%s\n```\n\n%s\n' \
"$RUN_LINK" "$B_STATUS" "$DR_STATUS" "$RP_STATUS" "$MSG" "$MSG_PURGE" > pr-comment-body.txt
gh pr comment $PR_NUMBER -F pr-comment-body.txt
env:
GH_TOKEN: ${{ github.token }}