Skip to content

Commit

Permalink
WIP Update CI
Browse files Browse the repository at this point in the history
Try to keep the workflows a bit closer to how we setup things in the
plugin repositories.
  • Loading branch information
mdellweg committed Dec 12, 2024
1 parent f1a4448 commit 3a1b566
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 39 deletions.
49 changes: 19 additions & 30 deletions .ci/scripts/validate_commit_message.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand All @@ -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]))
Expand All @@ -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]))
13 changes: 12 additions & 1 deletion .github/workflows/scripts/before_install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
11 changes: 5 additions & 6 deletions .github/workflows/scripts/check_commit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/scripts/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3a1b566

Please sign in to comment.