-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yml
359 lines (313 loc) · 15.1 KB
/
action.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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
# Tutorial to use with: https://github.com/andry81-devops/accum-content
#
name: accum-content
description: 'GitHub composite action to periodically download and accumulate content into repository'
branding:
icon: download
color: white
inputs:
deps_repo_owner:
description: 'Owner of a repository used to checkout dependencies'
required: true
deps_repo_branch:
description: 'Repository branch used to checkout dependencies'
default: master
deps_repo_read_token:
description: 'PAT token to a repository used to checkout dependencies'
default: ${{ github.token }}
config_repo_owner:
description: 'Owner of a repository used to read and execute content config file'
required: true
config_repo:
description: 'Repository name used to read and execute content config file'
required: true
config_repo_branch:
description: 'Repository branch used to read and execute content config file'
default: master
config_repo_read_token:
description: 'PAT token used to read content config file repository'
required: true
store_repo_owner:
description: 'Owner of a repository used to store content'
required: true
store_repo:
description: 'Repository name used to store content'
required: true
store_repo_branch:
description: 'Repository branch used to store content'
default: master
store_repo_write_token:
description: 'PAT token to the content store repository with write/push access rights'
required: true
commit_msg_entity:
description: 'Commit message entity'
# examples:
# - my-store-dir-1
# - my-store-dir-2
content_config_file:
description: 'Content config file in the content config repository'
required: true
content_index_file:
description: 'Content index file in the content store repository'
required: true
content_index_dir:
description: 'Content index directory in the content store repository. If is not defined, then relative to content_index_file'
curl_flags:
description: 'additional curl flags'
# example:
# `-H 'Cache-Control: no-cache'`
# NOTE:
# The `flags` converts into `GH_WORKFLOW_FLAGS` environment variable as a single line string.
# You must evaluate it to a shell array to be able to use it in the bash shell: `eval __flags__=($GH_WORKFLOW_FLAGS)`
#
flags:
description: >
String of flag values list in format of `NAME[=[EXPR]]` ready to be evaluated as a shell array: `(<0> <1> ... <N>)`.
If `EXPR` is not empty and begins by '[' then, use `eval EXPR` instead of `(( EXPR ))` expression.
Otherwise if a flag expression is `NAME=`, then false (unflagged).
Otherwise if a flag expression is `NAME`, then true (flagged).
# See dependent repositories and scripts for details.
# Flag expression examples:
# # A is true, B is true, C is false, D is true, F is false, T is true.
# # GH_WORKFLOW_FLAGS=`A=1 B="1 + 1" C="1 - 1" D='[[ "1" -eq "1" ]]' F= T`
# flags: >-
# A=1
# B="1 + 1"
# C="1 - 1"
# D='[[ "1" -eq "1" ]]'
# F=
# T
# builtin flag names:
# ENABLE_PRINT_INITIAL_ENV_INTO_STDOUT=1
env:
description: environment variables
# See dependent repositories and scripts for details.
# examples:
# ENABLE_GENERATE_CHANGELOG_FILE=1
# CHANGELOG_FILE=repo/{{REPO_OWNER}}/{{REPO}}/content-changelog.txt
# ENABLE_COMMIT_MESSAGE_DATE_WITH_TIME=1 # insert the time string in format HH:MMZ additionally after the date in each commit message
# ENABLE_COMMIT_MESSAGE_WITH_WORKFLOW_RUN_NUMBER=1 # insert the workflow run number after date/time prefix in each commit message
# ENABLE_YAML_PRINT_AFTER_EDIT=1
# ENABLE_YAML_PRINT_AFTER_PATCH=1
# ENABLE_YAML_DIFF_PRINT_AFTER_EDIT=1
# ENABLE_YAML_DIFF_PRINT_BEFORE_PATCH=1
# ENABLE_YAML_PATCH_DIFF_PAUSE_MODE=1
# ENABLE_GITHUB_ACTIONS_RUN_URL_PRINT_TO_CHANGELOG=1
# ENABLE_REPO_STORE_COMMITS_URL_PRINT_TO_CHANGELOG=1
# CONTINUE_ON_INVALID_INPUT=1
# CONTINUE_ON_EMPTY_CHANGES=1
# ERROR_ON_EMPTY_CHANGES_WITHOUT_ERRORS=1
# NO_SKIP_UNEXPIRED_ENTRIES=1
# NO_DOWNLOAD_ENTRIES=1
# NO_DOWNLOAD_ENTRIES_AND_CREATE_EMPTY_INSTEAD=1
# USE_PYTHON3_PIP_INSTALL_CMDLINE="<pip-install-cmdline>"
# USE_APT_GET_INSTALL_CMDLINE="<apt-get-install-cmdline>"
runs:
using: "composite"
steps:
- name: '[accum-content][01] load `flags` parameter into `GH_WORKFLOW_FLAGS` environment variable'
shell: bash
run: |
### [accum-content][01] load `flags` parameter into `GH_WORKFLOW_FLAGS` environment variable
# suppress not zero exit code
{ IFS=$' \t' read -r -d '' GH_WORKFLOW_FLAGS || (( 1 )); } <<::EOF::
${{ inputs.flags }}
::EOF::
GH_WORKFLOW_FLAGS="${GH_WORKFLOW_FLAGS//[$'\n\r']/}" # remove all line returns
echo "GH_WORKFLOW_FLAGS=$GH_WORKFLOW_FLAGS" >> $GITHUB_ENV
- name: '[accum-content][02] print initial environment variables'
shell: bash
run: |
### [accum-content][02] print initial environment variables
eval __flags__=($GH_WORKFLOW_FLAGS)
for arg in "${__flags__[@]}"; do
# suppress not zero exit code
IFS=$'=\n' read -r -d '' name value <<< "$arg" || (( 1 ))
if [[ "$name" == 'ENABLE_PRINT_INITIAL_ENV_INTO_STDOUT' ]]; then
# If `value` is not empty and begins by '[' then, use `eval "$value"` instead of `(( value ))` expression.
# Otherwise if `value` is empty and `arg` with assign character, then false (unflagged).
# Otherwise if `value` is empty and `arg` without assign character, then true (flagged).
if [[ -z "$value" && "${arg/=/}" == "$arg" ]] || ( [[ "${value:0:1}" != "[" ]] && (( value )) ) || ( [[ "${value:0:1}" == "[" ]] && eval "$value" ) ; then
env | sort
break
fi
fi
done
- name: '[accum-content][03] install packages with caching'
uses: andry81-forks/cache-apt-pkgs-action@latest
with:
packages: xmlstarlet
# step is required to workaround variable expansion in variables
- name: '[accum-content][04] declare dependent variables'
shell: bash
run: |
### [accum-content][04] declare dependent variables
echo "GH_WORKFLOW_ROOT=$GITHUB_WORKSPACE/gh-workflow" >> $GITHUB_ENV
- name: '[accum-content][05] checkout gh-workflow@${{ inputs.deps_repo_branch }}'
uses: andry81-devops/gh-action--git-checkout@master
with:
repository: ${{ inputs.deps_repo_owner }}/gh-workflow
ref: ${{ inputs.deps_repo_branch }}
path: gh-workflow
token: ${{ inputs.deps_repo_read_token }}
mkdir-p: >-
${{ env.GH_WORKFLOW_ROOT }}
- name: '[accum-content][06] update permissions'
shell: bash
run: |
### [accum-content][06] update permissions
chmod ug+x $GH_WORKFLOW_ROOT/bash/_common/update-permissions.sh
$GH_WORKFLOW_ROOT/bash/_common/update-permissions.sh ug+x "$GH_WORKFLOW_ROOT/bash" -iname '*.sh'
# step is required to pass environment variables externally
- name: '[accum-content][07] declare variables from lists'
shell: bash
run: |
### [accum-content][07] declare variables from lists
# suppress not zero exit code
{ IFS=$' \t' read -r -d '' INPUT_ENV || (( 1 )); } <<::EOF::
${{ inputs.env }}
::EOF::
INPUT_ENV="${INPUT_ENV//[$'\n\r']/}" # remove all line returns
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
${INPUT_ENV} \
"GHWF_GITHUB_ACTIONS_RUN_URL=https://github.com/${{ github.repository }}/actions/runs/${{ github.run_id }}" \
"GHWF_REPO_STORE_COMMITS_URL=https://github.com/${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}/commits?branch=${{ inputs.store_repo_branch }}"
- name: '[accum-content][08] install apt-get prerequisites'
shell: bash
run: |
### [accum-content][08] install apt-get prerequisites
if [[ -n "$USE_APT_GET_INSTALL_CMDLINE" ]]; then
function call()
{
echo ">$@"
"$@"
}
while IFS=$'\n' read -r line; do
call sudo apt-get install $line
echo '---'
done <<< "$USE_APT_GET_INSTALL_CMDLINE"
fi
- name: '[accum-content][09] install python prerequisites'
shell: bash
run: |
### [accum-content][09] install python prerequisites
if [[ -n "$USE_PYTHON3_PIP_INSTALL_CMDLINE" ]]; then
function call()
{
echo ">$@"
"$@"
}
while IFS=$'\n' read -r line; do
python3 -m pip install $line
echo '---'
done <<< "$USE_PYTHON3_PIP_INSTALL_CMDLINE"
fi
- name: '[accum-content][10] variables validation'
shell: bash
run: |
### [accum-content][10] variables validation
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"CHANGELOG_FILE=${CHANGELOG_FILE:-"changelog.txt"}"
if (( ! NO_SKIP_UNEXPIRED_ENTRIES )) && [[ "${{ github.event.inputs.no_skip_unexpired_entries }}" == 'true' || "${{ github.event.inputs.no_skip_unexpired_entries }}" -ne 0 ]]; then
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"NO_SKIP_UNEXPIRED_ENTRIES=1"
fi
if (( ! NO_DOWNLOAD_ENTRIES )) && [[ "${{ github.event.inputs.no_download_entries }}" == 'true' || "${{ github.event.inputs.no_download_entries }}" -ne 0 ]]; then
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"NO_DOWNLOAD_ENTRIES=1"
fi
- name: '[accum-content][11] declare local variables'
shell: bash
run: |
### [accum-content][11] declare local variables
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"changelog_file=$CHANGELOG_FILE" \
"CHANGELOG_FILE=$GITHUB_WORKSPACE/content-cache/$CHANGELOG_FILE" \
"commit_msg_entity=${{ inputs.commit_msg_entity }}" \
"content_config_file=$GITHUB_WORKSPACE/content-config/${{ inputs.content_config_file }}" \
"content_index_file=$GITHUB_WORKSPACE/content-cache/${{ inputs.content_index_file }}" \
"content_index_dir=${{ inputs.content_index_dir }}" \
"curl_flags=${{ inputs.curl_flags }}"
- name: '[accum-content][12] declare local variables'
shell: bash
run: |
### [accum-content][12] declare local variables
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"content_config_dir=${content_config_file%/*}" \
"content_index_file_dir=${content_index_file%/*}" \
"changelog_dir=${CHANGELOG_FILE%/*}"
- name: '[accum-content][13] head annotations'
shell: bash
run: |
### [accum-content][13] head annotations
$GH_WORKFLOW_ROOT/bash/github/print-notice.sh \
"content config file: https://github.com/${{ inputs.config_repo_owner }}/${{ inputs.config_repo }}/tree/${{ inputs.config_repo_branch }}/${{ inputs.content_config_file }}" \
"content index file: https://github.com/${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}/tree/${{ inputs.store_repo_branch }}/${{ inputs.content_index_file }}" \
"content index dir: ${{ inputs.content_index_dir }}"
$GH_WORKFLOW_ROOT/bash/github/print-notice-ln.sh \
"content changelog file: https://github.com/${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}/tree/${{ inputs.store_repo_branch }}/$changelog_file" \
"env:"$'\n'" GITHUB_RUN_ID=\`$GITHUB_RUN_ID\`"$'\n'" GITHUB_RUN_NUMBER=\`$GITHUB_RUN_NUMBER\`"
- name: '[accum-content][14] checkout content-config@${{ inputs.config_repo_branch }}'
uses: andry81-devops/gh-action--git-checkout@master
with:
repository: ${{ inputs.config_repo_owner }}/${{ inputs.config_repo }}
ref: ${{ inputs.config_repo_branch }}
path: content-config
token: ${{ inputs.config_repo_read_token }}
mkdir-p: >-
${{ env.content_config_dir }}
- name: '[accum-content][15] checkout content-cache@${{ inputs.store_repo_branch }}'
uses: andry81-devops/gh-action--git-checkout@master
with:
repository: ${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}
ref: ${{ inputs.store_repo_branch }}
path: content-cache
token: ${{ inputs.store_repo_write_token }}
mkdir-p: >-
${{ env.content_index_file_dir }}
${{ env.content_index_dir }}
${{ env.changelog_dir }}
- name: '[accum-content][16] accumulate content using `${{ inputs.content_config_file }}` config'
id: accum-content
shell: bash
run: |
### [accum-content][16] accumulate content using `${{ inputs.content_config_file }}` config
cd $GITHUB_WORKSPACE/content-cache
$GH_WORKFLOW_ROOT/bash/cache/accum-content.sh
# caution: no operation after that line if non zero exit code happens above
- name: '[accum-content][17] commit content-cache'
shell: bash
run: |
### [accum-content][17] commit content-cache
cd $GITHUB_WORKSPACE/content-cache
git add .
git config --global user.name "GitHub Action"
git config --global user.email "[email protected]"
COMMIT_MESSAGE="A/U: $COMMIT_MESSAGE_DATE_TIME_PREFIX:"
if (( ENABLE_COMMIT_MESSAGE_WITH_WORKFLOW_RUN_NUMBER )) && [[ -n "$GITHUB_RUN_NUMBER" ]]; then
COMMIT_MESSAGE="$COMMIT_MESSAGE #$GITHUB_RUN_NUMBER:"
fi
COMMIT_MESSAGE="$COMMIT_MESSAGE ${COMMIT_MESSAGE_PREFIX}${COMMIT_MESSAGE_SUFFIX:+" | "}$COMMIT_MESSAGE_SUFFIX"
git status
git commit -m "$COMMIT_MESSAGE"
$GH_WORKFLOW_ROOT/bash/github/set-env-from-args.sh \
"HEAD_COMMIT_HASH=$(git rev-parse HEAD)"
- name: '[accum-content][18] push board-stats'
uses: ad-m/github-push-action@master
with:
repository: ${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}
branch: ${{ inputs.store_repo_branch }}
directory: content-cache
github_token: ${{ inputs.store_repo_write_token }}
- name: '[accum-content][19] print commit parameters into pipeline log only'
shell: bash
run: |
### [accum-content][19] print commit parameters into pipeline log only
$GH_WORKFLOW_ROOT/bash/github/print-notice.sh \
"commit reference url: https://github.com/${{ inputs.store_repo_owner }}/${{ inputs.store_repo }}/commit/$HEAD_COMMIT_HASH"
- name: '[accum-content][20] flush print annotations'
if: always()
shell: bash
run: |
### [accum-content][20] flush print annotations
$GH_WORKFLOW_ROOT/bash/github/flush-print-annotations.sh