Skip to content

Commit 810306c

Browse files
committed
ci-automation/image-changes, .github/ci: Further deduplication
1 parent 89f0cba commit 810306c

File tree

3 files changed

+119
-110
lines changed

3 files changed

+119
-110
lines changed

.github/workflows/ci.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -234,10 +234,10 @@ jobs:
234234
)
235235
236236
- name: Generate reports against last release
237-
run: .github/workflows/image_changes.sh release
237+
run: .github/workflows/image_changes.sh ${{ matrix.arch }} release
238238

239239
- name: Generate reports against last nightly
240-
run: .github/workflows/image_changes.sh nightly
240+
run: .github/workflows/image_changes.sh ${{ matrix.arch }} nightly
241241

242242
- name: Upload binpkgs
243243
uses: actions/upload-artifact@v3

.github/workflows/image_changes.sh

Lines changed: 35 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -3,70 +3,41 @@
33
set -x
44
set -euo pipefail
55

6-
mode=${1}; shift
7-
case ${mode} in
8-
release|nightly)
9-
:
10-
;;
11-
*)
12-
echo "invalid mode ${mode@Q}" >&2
13-
exit 1
14-
;;
15-
esac
16-
17-
git_tag_for_mode="git_tag_for_${mode}"
18-
prepare_env_vars_and_params_for_mode="prepare_env_vars_and_params_for_${mode}"
19-
report_file_name="image-changes-reports-${mode}.txt"
20-
216
source ci-automation/image_changes.sh
227

23-
git_tag=''
24-
"${git_tag_for_mode}" . git_tag
25-
26-
declare -a var_names=(
27-
package_diff_env package_diff_params
28-
size_changes_env size_changes_params
29-
show_changes_env show_changes_params
30-
)
31-
declare -a "${var_names[@]}"
32-
version_description=''
33-
var_names+=( version_description )
34-
35-
"${prepare_env_vars_and_params_for_mode}" "${arch}" "${git_tag}" "${var_names[@]}"
36-
37-
package_diff_env+=(
38-
"FROM_B=file://${PWD}/artifacts/images"
39-
# BOARD_B and CHANNEL_B are unused.
40-
)
41-
package_diff_params+=(
42-
# The package-diff script appends version to the file
43-
# URL, but the directory with the image has no version
44-
# component at its end, so we use . as a version.
45-
'.'
46-
)
47-
# Nothing to add to size changes env.
48-
size_changes_params+=(
49-
"local:${PWD}/artifacts/images"
50-
)
51-
show_changes_env+=(
52-
# Override the default locations of repositories.
53-
"SCRIPTS_REPO=."
54-
"COREOS_OVERLAY_REPO=../coreos-overlay"
55-
"PORTAGE_STABLE_REPO=../portage-stable"
56-
)
57-
show_changes_params+=(
58-
# We may not have a tag handy, so we tell show-changes
59-
# to use git HEAD as a reference to new changelog
60-
# entries.
61-
'NEW_VERSION=HEAD'
62-
)
8+
# Callback invoked by run_image_changes_job, read its docs to learn
9+
# about the details about the callback.
10+
function github_ricj_callback() {
11+
package_diff_env+=(
12+
"FROM_B=file://${PWD}/artifacts/images"
13+
# BOARD_B and CHANNEL_B are unused.
14+
)
15+
package_diff_params+=(
16+
# The package-diff script appends version to the file
17+
# URL, but the directory with the image has no version
18+
# component at its end, so we use . as a version.
19+
'.'
20+
)
21+
# Nothing to add to size changes env.
22+
size_changes_params+=(
23+
"local:${PWD}/artifacts/images"
24+
)
25+
show_changes_env+=(
26+
# Override the default locations of repositories.
27+
"SCRIPTS_REPO=."
28+
"COREOS_OVERLAY_REPO=../coreos-overlay"
29+
"PORTAGE_STABLE_REPO=../portage-stable"
30+
)
31+
show_changes_params+=(
32+
# We may not have a tag handy, so we tell show-changes
33+
# to use git HEAD as a reference to new changelog
34+
# entries.
35+
'NEW_VERSION=HEAD'
36+
)
37+
}
38+
39+
arch=${1}; shift
40+
mode=${1; shift
41+
report_file_name="image-changes-reports-${mode}.txt"
6342
64-
declare -a oemids base_sysexts
65-
get_oem_id_list . "${arch}" oemids
66-
get_base_sysext_list . "${arch}" base_sysexts
67-
generate_image_changes_report \
68-
"${version_description}" "${report_file_name}" "../flatcar-build-scripts" \
69-
"${package_diff_env[@]}" --- "${package_diff_params[@]}" -- \
70-
"${size_changes_env[@]}" --- "${size_changes_params[@]}" -- \
71-
"${show_changes_env[@]}" --- "${show_changes_params[@]}" -- \
72-
"${oemids[@]}" -- "${base_sysexts[@]}"
43+
run_image_changes_job "${arch}" "${mode}" "${report_file_name}" '../flatcar-build-scripts' github_ricj_callback

ci-automation/image_changes.sh

Lines changed: 82 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -36,36 +36,28 @@ function image_changes() (
3636
local arch what
3737

3838
arch=${1}; shift
39-
what=${1}; shift
39+
# make nightly and release from last-nightly and last-release, respectively
40+
mode=${1#last-}; shift
4041

41-
local -a package_diff_env package_diff_params
42-
local -a size_changes_env size_changes_params
43-
local -a show_changes_env show_changes_params
44-
local version_description
45-
local -a var_names=(
46-
package_diff_env package_diff_params
47-
size_changes_env size_changes_params
48-
show_changes_env show_changes_params
49-
version_description
50-
)
51-
52-
case ${what} in
53-
last-release)
54-
local git_tag
55-
git_tag_for_release . git_tag
56-
prepare_env_vars_and_params_for_release "${arch}" "${git_tag}" "${var_names[@]}"
57-
;;
58-
last-nightly)
59-
local git_tag
60-
git_tag_for_nightly . git_tag
61-
prepare_env_vars_and_params_for_bincache "${arch}" "${git_tag}" "${var_names[@]}"
62-
;;
63-
*)
64-
echo "invalid argument '${what}', expected 'last-nightly' or 'last-release'" >&2
65-
exit 1
66-
;;
67-
esac
42+
local fbs_repo='../flatcar-build-scripts'
43+
rm -rf "${fbs_repo}"
44+
git clone \
45+
--depth 1 \
46+
--single-branch \
47+
"https://github.com/flatcar/flatcar-build-scripts" \
48+
"${fbs_repo}"
49+
if [[ -z "${BUILDCACHE_SERVER:-}" ]]; then
50+
local BUILDCACHE_SERVER=$(source ci-automation/ci-config.env; echo "${BUILDCACHE_SERVER}")
51+
fi
52+
echo "Image URL: http://${BUILDCACHE_SERVER}/images/${arch}/${version}/flatcar_production_image.bin.bz2"
53+
echo
54+
run_image_changes_job "${arch}" "${mode}" '-' "${fbs_repo}" ricj_callback
55+
)
56+
# --
6857

58+
# Callback invoked by run_image_changes_job, read its docs to learn
59+
# about the details about the callback.
60+
function ricj_callback() {
6961
local ic_head_tag version
7062
head_git_tag . ic_head_tag
7163
version=$(source sdk_container/.repo/manifests/version.txt; echo "${FLATCAR_VERSION}")
@@ -94,29 +86,75 @@ function image_changes() (
9486
# here instead of the vernum variable.
9587
"NEW_VERSION=${ic_head_tag}"
9688
)
89+
}
90+
# --
91+
92+
# Runs the whole image changes job for given arch and mode. The report
93+
# is written to the given file. The reports will be done using tools
94+
# from the passed path to the flatcar build scripts repository. The
95+
# parameters and environment of the tools should will be partially set
96+
# up depending on mode, but the further setup should be done by the
97+
# passed callback.
98+
#
99+
# The callback takes no parameters. It should assume that array
100+
# variables 'package_diff_env', 'package_diff_params',
101+
# 'size_changes_env', 'size_changes_params', 'show_changes_env' and
102+
# 'show_changes_params' are already defined, so it can append
103+
# necessary data into them.
104+
#
105+
# 1 - arch
106+
# 2 - mode
107+
# 3 - report file name ('-' for standard output)
108+
# 4 - path to the flatcar-build-scripts repository
109+
# 5 - name of a callback function
110+
function run_image_changes_job() {
111+
arch=${1}; shift
112+
mode=${1}; shift
113+
report_file_name=${1}; shift
114+
fbs_repo=${1}; shift
115+
cb=${1}; shift
116+
117+
case ${mode} in
118+
release|nightly)
119+
:
120+
;;
121+
*)
122+
echo "invalid mode ${mode@Q}, expected 'nightly' or 'release'" >&2
123+
exit 1
124+
;;
125+
esac
126+
127+
local -a package_diff_env package_diff_params
128+
local -a size_changes_env size_changes_params
129+
local -a show_changes_env show_changes_params
130+
local version_description
131+
local -a var_names=(
132+
package_diff_env package_diff_params
133+
size_changes_env size_changes_params
134+
show_changes_env show_changes_params
135+
version_description
136+
)
137+
local git_tag_for_mode prepare_env_vars_and_params_for_mode
138+
git_tag_for_mode="git_tag_for_${mode}"
139+
prepare_env_vars_and_params_for_mode="prepare_env_vars_and_params_for_${mode}"
140+
141+
local git_tag
142+
"${git_tag_for_mode}" . git_tag
143+
"${prepare_env_vars_and_params_for_mode}" "${arch}" "${git_tag}" "${var_names[@]}"
144+
145+
# invoke callback that should append necessary info to env and params variables
146+
"${cb}"
97147

98-
local fbs_repo='../flatcar-build-scripts'
99-
rm -rf "${fbs_repo}"
100-
git clone \
101-
--depth 1 \
102-
--single-branch \
103-
"https://github.com/flatcar/flatcar-build-scripts" \
104-
"${fbs_repo}"
105-
if [[ -z "${BUILDCACHE_SERVER:-}" ]]; then
106-
local BUILDCACHE_SERVER=$(source ci-automation/ci-config.env; echo "${BUILDCACHE_SERVER}")
107-
fi
108-
echo "Image URL: http://${BUILDCACHE_SERVER}/images/${arch}/${version}/flatcar_production_image.bin.bz2"
109-
echo
110148
local -a oemids base_sysexts
111149
get_oem_id_list . "${arch}" oemids
112150
get_base_sysext_list . "${arch}" base_sysexts
113151
generate_image_changes_report \
114-
"${version_description}" '-' "${fbs_repo}" \
152+
"${version_description}" "${report_file_name}" "${fbs_repo}" \
115153
"${package_diff_env[@]}" --- "${package_diff_params[@]}" -- \
116154
"${size_changes_env[@]}" --- "${size_changes_params[@]}" -- \
117155
"${show_changes_env[@]}" --- "${show_changes_params[@]}" -- \
118156
"${oemids[@]}" -- "${base_sysexts[@]}"
119-
)
157+
}
120158
# --
121159

122160
# Gets a git tag that can be passed to
@@ -180,7 +218,7 @@ function head_git_tag() {
180218
}
181219

182220
# Gets a git tag of a previous nightly that can be passed to
183-
# prepare_env_vars_and_params_for_bincache.
221+
# prepare_env_vars_and_params_for_nightly.
184222
#
185223
# 1 - scripts repo
186224
# 2 - name of a variable to store the result in
@@ -357,7 +395,7 @@ function prepare_env_vars_and_params_for_release() {
357395
# nightly relative to the git tag. The git tag should be in form of
358396
# <channel>-<version id>-<build id>, which is the usual format used in
359397
# scripts repo.
360-
function prepare_env_vars_and_params_for_bincache() {
398+
function prepare_env_vars_and_params_for_nightly() {
361399
local arch git_tag
362400
arch=${1}; shift
363401
git_tag=${1}; shift

0 commit comments

Comments
 (0)