Skip to content

Commit a4a130f

Browse files
committed
CI: add distribution version consistency checks
This should make sure that we do not forget to update the DISTRO_VERSION and DISTRO_CODENAME when a new tag is created or a new yocto version branch is started. Signed-off-by: Leonard Göhrs <l.goehrs@pengutronix.de>
1 parent ba3e18a commit a4a130f

File tree

2 files changed

+112
-0
lines changed

2 files changed

+112
-0
lines changed
Lines changed: 89 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,89 @@
1+
import os
2+
import re
3+
4+
import bb.tinfoil
5+
import git
6+
7+
# TODO: add minor version numbers once we have them
8+
RE_VERSION_TAG = "v(?P<year>[0-9][0-9])\.(?P<month>[0-9][0-9])"
9+
RE_VERSION_BB = "(?P<year>[0-9][0-9])\.(?P<month>[0-9][0-9])(?P<dev>$|\+dev)"
10+
11+
12+
def bb_variables(names):
13+
ret = dict()
14+
15+
with bb.tinfoil.Tinfoil(tracking=True, setup_logging=True) as tinfoil:
16+
tinfoil.prepare(quiet=2, config_only=True)
17+
d = tinfoil.config_data
18+
19+
for name in names:
20+
ret[name] = d.getVar(name)
21+
22+
return ret
23+
24+
25+
def git_prev_tag():
26+
repo = git.Repo()
27+
28+
current_commit_is_tagged = True
29+
30+
for commit in repo.iter_commits():
31+
for tag in repo.tags:
32+
if tag.commit == commit:
33+
return (tag, current_commit_is_tagged)
34+
35+
current_commit_is_tagged = False
36+
37+
38+
def check_version(distro_version):
39+
prev_tag, commit_is_tagged = git_prev_tag()
40+
41+
print(f"Checking tag {prev_tag.name} against version {distro_version}")
42+
43+
version_tag = re.fullmatch(RE_VERSION_TAG, prev_tag.name)
44+
version_tag_numeric = int(version_tag["year"]) * 100 + int(version_tag["month"])
45+
46+
version_bb = re.fullmatch(RE_VERSION_BB, distro_version)
47+
version_bb_numeric = int(version_bb["year"]) * 100 + int(version_bb["month"])
48+
49+
if commit_is_tagged:
50+
# The version in a tagged commit must match the version in the tag's name.
51+
assert version_bb["dev"] == ""
52+
assert version_tag_numeric == version_bb_numeric
53+
54+
elif version_bb["dev"] == "":
55+
# Release candidates already have the next release version set,
56+
# but there must not be a tag with the same or a newer version number
57+
# in the current commits history.
58+
assert version_bb_numeric > version_tag_numeric
59+
60+
else:
61+
# Non release candidate versions should have the previous tagged
62+
# version number plus the +dev suffix set.
63+
assert version_bb_numeric == version_tag_numeric
64+
65+
66+
def check_codename(codename):
67+
base_ref = os.environ.get("GITHUB_BASE_REF")
68+
ref = os.environ.get("GITHUB_REF")
69+
70+
if base_ref is not None:
71+
print(f"Checking codename {codename} against pull request into {base_ref}")
72+
assert codename == f"tacos-{base_ref}"
73+
elif ref is not None:
74+
print(f"Checking codename {codename} against branch {ref}")
75+
assert codename == f"tacos-{ref}"
76+
else:
77+
print("Running outside of GitHub CI. Skipping codename check")
78+
return
79+
80+
81+
def main():
82+
variables = bb_variables(("DISTRO_VERSION", "DISTRO_CODENAME"))
83+
84+
check_version(variables["DISTRO_VERSION"])
85+
check_codename(variables["DISTRO_CODENAME"])
86+
87+
88+
if __name__ == "__main__":
89+
main()
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
name: distribution version
2+
3+
on:
4+
push:
5+
pull_request:
6+
jobs:
7+
check:
8+
name: consistency check
9+
runs-on: ubuntu-latest
10+
if: github.repository == 'linux-automation/meta-lxatac'
11+
steps:
12+
- name: Install required packages
13+
run: |
14+
sudo apt-get install diffstat chrpath python3-git
15+
- name: Checkout
16+
uses: actions/checkout@v4
17+
with:
18+
fetch-depth: 0
19+
submodules: recursive
20+
- name: Check version number and codename
21+
run: |
22+
source oe-init-build-env && cd -
23+
python3 .github/workflows/distribution-version.py

0 commit comments

Comments
 (0)