From 56a5b6e3f363cc16ca6a922ce3a0933d4524b610 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leonard=20G=C3=B6hrs?= Date: Fri, 15 Dec 2023 11:09:48 +0100 Subject: [PATCH] CI: add distribution version consistency checks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 --- .github/workflows/distribution-version.py | 89 +++++++++++++++++++++ .github/workflows/distribution-version.yaml | 23 ++++++ 2 files changed, 112 insertions(+) create mode 100644 .github/workflows/distribution-version.py create mode 100644 .github/workflows/distribution-version.yaml diff --git a/.github/workflows/distribution-version.py b/.github/workflows/distribution-version.py new file mode 100644 index 00000000..3749302e --- /dev/null +++ b/.github/workflows/distribution-version.py @@ -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[0-9][0-9])\.(?P[0-9][0-9])" +RE_VERSION_BB = "(?P[0-9][0-9])\.(?P[0-9][0-9])(?P$|\+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() diff --git a/.github/workflows/distribution-version.yaml b/.github/workflows/distribution-version.yaml new file mode 100644 index 00000000..373b3900 --- /dev/null +++ b/.github/workflows/distribution-version.yaml @@ -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