-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
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>
- Loading branch information
Showing
2 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
import re | ||
|
||
import bb.tinfoil | ||
import git | ||
|
||
# TODO: add minor version numbers once we have them | ||
RE_VERSION_TAG = "v(?P<year>[0-9][0-9])\.(?P<month>[0-9][0-9])" | ||
RE_VERSION_BB = "(?P<year>[0-9][0-9])\.(?P<month>[0-9][0-9])(?P<dev>$|\+dev)" | ||
|
||
|
||
def bb_variables(names): | ||
ret = dict() | ||
|
||
with bb.tinfoil.Tinfoil(tracking=True, setup_logging=True) as tinfoil: | ||
tinfoil.prepare(quiet=2, config_only=True) | ||
d = tinfoil.config_data | ||
|
||
for name in names: | ||
ret[name] = d.getVar(name) | ||
|
||
return ret | ||
|
||
|
||
def git_prev_tag(): | ||
repo = git.Repo() | ||
|
||
current_commit_is_tagged = True | ||
|
||
for commit in repo.iter_commits(): | ||
for tag in repo.tags: | ||
if tag.commit == commit: | ||
return (tag, current_commit_is_tagged) | ||
|
||
current_commit_is_tagged = False | ||
|
||
|
||
def check_version(distro_version): | ||
prev_tag, commit_is_tagged = git_prev_tag() | ||
|
||
print(f"Checking tag {prev_tag.name} against version {distro_version}") | ||
|
||
version_tag = re.fullmatch(RE_VERSION_TAG, prev_tag.name) | ||
version_tag_numeric = int(version_tag["year"]) * 100 + int(version_tag["month"]) | ||
|
||
version_bb = re.fullmatch(RE_VERSION_BB, distro_version) | ||
version_bb_numeric = int(version_bb["year"]) * 100 + int(version_bb["month"]) | ||
|
||
if commit_is_tagged: | ||
# The version in a tagged commit must match the version in the tag's name. | ||
assert version_bb["dev"] == "" | ||
assert version_tag_numeric == version_bb_numeric | ||
|
||
elif version_bb["dev"] == "": | ||
# Release candidates already have the next release version set, | ||
# but there must not be a tag with the same or a newer version number | ||
# in the current commits history. | ||
assert version_bb_numeric > version_tag_numeric | ||
|
||
else: | ||
# Non release candidate versions should have the previous tagged | ||
# version number plus the +dev suffix set. | ||
assert version_bb_numeric == version_tag_numeric | ||
|
||
|
||
def check_codename(codename): | ||
base_ref = os.environ.get("GITHUB_BASE_REF") | ||
ref = os.environ.get("GITHUB_REF") | ||
|
||
if base_ref is not None: | ||
print(f"Checking codename {codename} against pull request into {base_ref}") | ||
assert codename == f"tacos-{base_ref}" | ||
elif ref is not None: | ||
print(f"Checking codename {codename} against branch {ref}") | ||
assert codename == f"tacos-{ref}" | ||
else: | ||
print("Running outside of GitHub CI. Skipping codename check") | ||
return | ||
|
||
|
||
def main(): | ||
variables = bb_variables(("DISTRO_VERSION", "DISTRO_CODENAME")) | ||
|
||
check_version(variables["DISTRO_VERSION"]) | ||
check_codename(variables["DISTRO_CODENAME"]) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
name: distribution version | ||
|
||
on: | ||
push: | ||
pull_request: | ||
jobs: | ||
check: | ||
name: version consistency | ||
runs-on: ubuntu-latest | ||
if: github.repository == 'linux-automation/meta-lxatac' | ||
steps: | ||
- name: Install required packages | ||
run: | | ||
sudo apt-get install diffstat chrpath python3-git | ||
- name: Checkout | ||
uses: actions/checkout@v4 | ||
with: | ||
fetch-depth: 0 | ||
submodules: recursive | ||
- name: Check version number and codename | ||
run: | | ||
source oe-init-build-env && cd - | ||
python3 .github/workflows/distribution-version.py |