Skip to content

Commit

Permalink
Merge pull request #87 from hnez/version-checks
Browse files Browse the repository at this point in the history
CI: add distribution version consistency checks
  • Loading branch information
jluebbe authored Dec 18, 2023
2 parents 5f8ff8e + 7fa11b2 commit f46cf94
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 0 deletions.
91 changes: 91 additions & 0 deletions .github/workflows/distribution-version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
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()

# e.g. 'v23.11'
tag = repo.git.describe(tags=True, abbrev=0)

# e.g. 'v23.11-40-ga4a1'
commit_description = repo.git.describe(tags=True)

# The description matches the tag if there are no commits since the
# last tag.
commit_is_tagged = tag == commit_description

return (tag, commit_is_tagged)


def check_version(distro_version):
prev_tag, commit_is_tagged = git_prev_tag()

print(f"Checking tag {prev_tag} against version {distro_version}")

version_tag = re.fullmatch(RE_VERSION_TAG, prev_tag)
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 it must be newer than any tag in the current commit's 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()
24 changes: 24 additions & 0 deletions .github/workflows/distribution-version.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: distribution version

on:
create: # tags and branches
pull_request:
push:
jobs:
check:
name: consistency check
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

0 comments on commit f46cf94

Please sign in to comment.