From 3a1b56653e24e1293c5b6e7fef12220862610b5e Mon Sep 17 00:00:00 2001 From: Matthias Dellweg Date: Tue, 3 Dec 2024 15:41:23 +0100 Subject: [PATCH] WIP Update CI Try to keep the workflows a bit closer to how we setup things in the plugin repositories. --- .ci/scripts/validate_commit_message.py | 49 ++++++++------------- .github/workflows/scripts/before_install.sh | 13 +++++- .github/workflows/scripts/check_commit.sh | 11 +++-- .github/workflows/scripts/install.sh | 4 +- 4 files changed, 38 insertions(+), 39 deletions(-) diff --git a/.ci/scripts/validate_commit_message.py b/.ci/scripts/validate_commit_message.py index 181729c..7db6ef2 100644 --- a/.ci/scripts/validate_commit_message.py +++ b/.ci/scripts/validate_commit_message.py @@ -6,38 +6,33 @@ # For more info visit https://github.com/pulp/plugin_template import re -import requests -import subprocess import sys from pathlib import Path +import subprocess +import os +import warnings +from github import Github -KEYWORDS = ["fixes", "closes", "re", "ref"] -NO_ISSUE = "[noissue]" -STATUSES = ["NEW", "ASSIGNED", "POST", "MODIFIED"] -REDMINE_URL = "https://pulp.plan.io" CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"] +KEYWORDS = ["fixes", "closes"] sha = sys.argv[1] -project = "" message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8") +g = Github(os.environ.get("GITHUB_TOKEN")) +repo = g.get_repo("pulp/pulp-openapi-generator") + def __check_status(issue): - response = requests.get(f"{REDMINE_URL}/issues/{issue}.json") - response.raise_for_status() - bug_json = response.json() - status = bug_json["issue"]["status"]["name"] - if status not in STATUSES: - sys.exit( - "Error: issue #{issue} has invalid status of {status}. Status must be one of " - "{statuses}.".format(issue=issue, status=status, statuses=", ".join(STATUSES)) + gi = repo.get_issue(int(issue)) + if gi.pull_request: + sys.exit(f"Error: issue #{issue} is a pull request.") + if gi.closed_at and "cherry picked from commit" not in message: + warnings.warn( + "When backporting, use the -x flag to append a line that says " + "'(cherry picked from commit ...)' to the original commit message." ) - - if project: - project_id = bug_json["issue"]["project"]["id"] - project_json = requests.get(f"{REDMINE_URL}/projects/{project_id}.json").json() - if project_json["project"]["identifier"] != project: - sys.exit(f"Error: issue {issue} is not in the {project} project.") + sys.exit(f"Error: issue #{issue} is closed.") def __check_changelog(issue): @@ -48,6 +43,8 @@ def __check_changelog(issue): for match in matches: if match.suffix not in CHANGELOG_EXTS: sys.exit(f"Invalid extension for changelog entry '{match}'.") + if match.suffix == ".feature" and "cherry picked from commit" in message: + sys.exit(f"Can not backport '{match}' as it is a feature.") print("Checking commit message for {sha}.".format(sha=sha[0:7])) @@ -61,14 +58,6 @@ def __check_changelog(issue): if issues: for issue in pattern.findall(message): __check_status(issue) - # __check_changelog(issue) -else: - if NO_ISSUE in message: - print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE)) - else: - sys.exit( - "Error: no attached issues found for {sha}. If this was intentional, add " - " '{tag}' to the commit message.".format(sha=sha[0:7], tag=NO_ISSUE) - ) + __check_changelog(issue) print("Commit message for {sha} passed.".format(sha=sha[0:7])) diff --git a/.github/workflows/scripts/before_install.sh b/.github/workflows/scripts/before_install.sh index 45adf6a..c360e1d 100755 --- a/.github/workflows/scripts/before_install.sh +++ b/.github/workflows/scripts/before_install.sh @@ -7,9 +7,20 @@ # # For more info visit https://github.com/pulp/plugin_template +# make sure this script runs at the repo root +cd "$(dirname "$(realpath -e "$0")")"/../../.. + set -mveuo pipefail # Intall requirements for ansible playbooks pip install docker netaddr boto3 ansible -ansible-galaxy collection install amazon.aws +for i in {1..3} +do + ansible-galaxy collection install "amazon.aws:8.1.0" && s=0 && break || s=$? && sleep 3 +done +if [[ $s -gt 0 ]] +then + echo "Failed to install amazon.aws" + exit $s +fi diff --git a/.github/workflows/scripts/check_commit.sh b/.github/workflows/scripts/check_commit.sh index 3d36c59..1d4ea34 100755 --- a/.github/workflows/scripts/check_commit.sh +++ b/.github/workflows/scripts/check_commit.sh @@ -7,15 +7,14 @@ # # For more info visit https://github.com/pulp/plugin_template -set -euv +# make sure this script runs at the repo root +cd "$(dirname "$(realpath -e "$0")")/../../.." -echo ::group::REQUESTS -pip3 install requests -echo ::endgroup:: +set -euv -for sha in $(curl $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g') +for SHA in $(curl -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_CONTEXT" | jq -r '.[].sha') do - python3 .ci/scripts/validate_commit_message.py $sha + python3 .ci/scripts/validate_commit_message.py "$SHA" VALUE=$? if [ "$VALUE" -gt 0 ]; then exit $VALUE diff --git a/.github/workflows/scripts/install.sh b/.github/workflows/scripts/install.sh index 8b49505..ec8d4bc 100755 --- a/.github/workflows/scripts/install.sh +++ b/.github/workflows/scripts/install.sh @@ -7,11 +7,11 @@ # # For more info visit https://github.com/pulp/plugin_template -set -euv - # make sure this script runs at the repo root cd "$(dirname "$(realpath -e "$0")")"/../../.. +set -euv + TAG="${TAG:-latest}" mkdir -p .ci/ansible/vars