CI: support release channels (v20.05 branch) (MR 1321)

Add common.get_upstream_branch() and use it instead of assuming "master"
as upstream branch.

Example: user forks v20.05 to v20.05_some-fix, then creates a merge
request. CI must use v20.05 as upstream branch, when comparing for
modified files etc.
This commit is contained in:
Oliver Smith 2020-06-16 19:13:33 +02:00 committed by Bart Ribbers
parent 4d116177ac
commit f415d413c5
No known key found for this signature in database
GPG key ID: 699D16185DAFAE61
2 changed files with 57 additions and 21 deletions

View file

@ -19,7 +19,7 @@ import pmb.helpers.logging
def get_package_version(args, package, revision, check=True):
# Redirect stderr to /dev/null, so git doesn't complain about files not
# existing in master for new packages
# existing in upstream branch for new packages
stderr = None
if not check:
stderr = subprocess.DEVNULL
@ -56,6 +56,7 @@ def version_compare_operator(result):
def exit_with_error_message():
branch = common.get_upstream_branch()
print()
print("ERROR: Modified package(s) don't have an increased version or a")
print("new package has a nonzero pkgrel!")
@ -63,15 +64,15 @@ def exit_with_error_message():
print("This can happen if you added a new package with a nonzero")
print("pkgrel, or if you did not change the pkgver/pkgrel")
print("variables in the APKBUILDs. Or you did change them, but the")
print("packages have been updated in the official master branch, and now")
print("your versions are not higher anymore.")
print(f"packages have been updated in the official '{branch}' branch, and")
print("now your versions are not higher anymore.")
print()
print("Your options:")
print("a) If you made changes to the packages, and did not increase the")
print(" pkgrel/pkgver: increase them now, and force push your branch.")
print(" => https://postmarketos.org/howto-bump-pkgrel-pkgver")
print("b) If you had already increased the package versions, rebase on")
print(" master, increase the versions again and then force push:")
print(f" '{branch}', increase the versions again and then force push:")
print(" => https://postmarketos.org/rebase")
print("c) If you made a change, that does not require rebuilding the")
print(" packages, such as only changing the arch=... line: you can")
@ -85,24 +86,25 @@ def exit_with_error_message():
def check_versions(args, packages):
error = False
# Get relevant commits: compare HEAD against upstream/master or HEAD~1
# (the latter if this CI check is running on upstream/master). Note that
# Get relevant commits: compare HEAD against upstream branch or HEAD~1
# (the latter if this CI check is running on upstream branch). Note that
# for the common.get_changed_files() code, we don't check against
# upstream/master, but against the latest common ancestor. This is not
# upstream branch HEAD, but against the latest common ancestor. This is not
# desired here, since we already know what packages changed, and really
# want to check if the version was increased towards *current* master.
commit = "upstream/master"
# want to check if the version was increased towards *current* upstream
# branch HEAD.
commit = f"upstream/{common.get_upstream_branch()}"
if common.run_git(["rev-parse", "HEAD"]) == common.run_git(["rev-parse",
commit]):
print("NOTE: upstream/master is on same commit as HEAD, comparing"
print(f"NOTE: {commit} is on same commit as HEAD, comparing"
" HEAD against HEAD~1.")
commit = "HEAD~1"
for package in packages:
# Get versions, skip new packages
head = get_package_version(args, package, "HEAD")
master = get_package_version(args, package, commit, False)
if not master:
upstream = get_package_version(args, package, commit, False)
if not upstream:
if head.rpartition('r')[2] != "0":
print(f"- {package}: {head} (HEAD) (new package) [ERROR]")
error = True
@ -110,8 +112,8 @@ def check_versions(args, packages):
print(f"- {package}: {head} (HEAD) (new package)")
continue
# Compare head and master versions
result = pmb.parse.version.compare(head, master)
# Compare head and upstream versions
result = pmb.parse.version.compare(head, upstream)
if result != 1:
error = True
@ -120,7 +122,7 @@ def check_versions(args, packages):
if result != 1:
formatstr += " [ERROR]"
operator = version_compare_operator(result)
print(formatstr.format(package, head, operator, master, commit))
print(formatstr.format(package, head, operator, upstream, commit))
if error:
exit_with_error_message()

View file

@ -4,6 +4,7 @@
# Various functions used in CI scripts
import configparser
import os
import subprocess
import sys
@ -53,24 +54,56 @@ def run_pmbootstrap(parameters, output_return=False):
return result.stdout
def get_upstream_branch():
""" Use pmaports.cfg from current branch (e.g. "v20.05_fix-ci") and
channels.cfg from master to retrieve the upstream branch.
:returns: branch name, e.g. "v20.05" """
global cache
if "upstream_branch" in cache:
return cache["upstream_branch"]
# Get channel (e.g. "stable") from pmaports.cfg
# https://postmarketos.org/pmaports.cfg
pmaports_dir = get_pmaports_dir()
pmaports_cfg = configparser.ConfigParser()
pmaports_cfg.read(f"{pmaports_dir}/pmaports.cfg")
channel = pmaports_cfg["pmaports"]["channel"]
# Get branch_pmaports (e.g. "v20.05") from channels.cfg
# https://postmarketos.org/channels.cfg
channels_cfg_str = run_git(["show", "upstream/master:channels.cfg"])
channels_cfg = configparser.ConfigParser()
channels_cfg.read_string(channels_cfg_str)
assert channel in channels_cfg, \
f"Channel '{channel}' from pmaports.cfg in your branch is unknown." \
" This appears to be an old branch, consider recreating your change" \
" on top of master."
ret = channels_cfg[channel]["branch_pmaports"]
cache["upstream_branch"] = ret
return ret
def get_changed_files(removed=True):
""" Get all changed files and print them, as well as the branch and the
commit that was used for the diff.
:param removed: also return removed files (default: True)
:returns: set of changed files
"""
branch_upstream = f"upstream/{get_upstream_branch()}"
commit_head = run_git(["rev-parse", "HEAD"])[:-1]
commit_upstream_master = run_git(["rev-parse", "upstream/master"])[:-1]
commit_upstream = run_git(["rev-parse", branch_upstream])[:-1]
print("commit HEAD: " + commit_head)
print("commit upstream/master: " + commit_upstream_master)
print(f"commit {branch_upstream}: f{commit_upstream}")
# Check if we are latest upstream/master
if commit_head == commit_upstream_master:
# Check if we are HEAD on the upstream branch
if commit_head == commit_upstream:
# then compare with previous commit
commit = "HEAD~1"
else:
# otherwise compare with latest common ancestor
commit = run_git(["merge-base", "upstream/master", "HEAD"])[:-1]
commit = run_git(["merge-base", branch_upstream, "HEAD"])[:-1]
print("comparing HEAD with: " + commit)
# Changed files
@ -96,6 +129,7 @@ def get_changed_packages_sanity_check(count):
if count <= 10:
return
branch = get_upstream_branch()
print()
print("ERROR: Too many packages have changed!")
print()
@ -105,7 +139,7 @@ def get_changed_packages_sanity_check(count):
print()
print("Your options:")
print("a) If you *did not* modify everything listed above, then rebase")
print(" your branch on the official postmarketOS/pmaports.git master")
print(f" your branch on the official postmarketOS/pmaports.git {branch}")
print(" branch. Feel free to ask in the chat for help if you need any.")
print("b) If you *did* modify all these packages, and you assume that")
print(" they will build within one hour: skip this sanity check by")