Skip to content

Commit c1b0331

Browse files
committed
Update CI
Try to keep the workflows a bit closer to how we setup things in the plugin repositories.
1 parent f1a4448 commit c1b0331

File tree

23 files changed

+124
-105
lines changed

23 files changed

+124
-105
lines changed
+46-45
Original file line numberDiff line numberDiff line change
@@ -1,46 +1,54 @@
1-
# WARNING: DO NOT EDIT!
2-
#
3-
# This file was generated by plugin_template, and is managed by it. Please use
4-
# './plugin-template --github pulp_file' to update this file.
5-
#
6-
# For more info visit https://github.com/pulp/plugin_template
7-
1+
import os
82
import re
9-
import requests
103
import subprocess
114
import sys
5+
import tomllib
126
from pathlib import Path
137

14-
KEYWORDS = ["fixes", "closes", "re", "ref"]
15-
NO_ISSUE = "[noissue]"
16-
STATUSES = ["NEW", "ASSIGNED", "POST", "MODIFIED"]
17-
REDMINE_URL = "https://pulp.plan.io"
18-
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc", ".deprecation"]
8+
from github import Github
9+
10+
with open("pyproject.toml", "rb") as fp:
11+
PYPROJECT_TOML = tomllib.load(fp)
12+
KEYWORDS = ["fixes", "closes"]
13+
BLOCKING_REGEX = [
14+
r"^DRAFT",
15+
r"^WIP",
16+
r"^NOMERGE",
17+
r"^DO\s*NOT\s*MERGE",
18+
r"^EXPERIMENT",
19+
r"^FIXUP",
20+
r"Apply suggestions from code review",
21+
]
22+
try:
23+
CHANGELOG_EXTS = [
24+
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"]
25+
]
26+
except KeyError:
27+
CHANGELOG_EXTS = [".feature", ".bugfix", ".doc", ".removal", ".misc"]
28+
NOISSUE_MARKER = "[noissue]"
1929

2030
sha = sys.argv[1]
21-
project = ""
2231
message = subprocess.check_output(["git", "log", "--format=%B", "-n 1", sha]).decode("utf-8")
2332

33+
if NOISSUE_MARKER in message:
34+
sys.exit(f"Do not add '{NOISSUE_MARKER}' in the commit message.")
35+
36+
if any((re.match(pattern, message, re.IGNORECASE) for pattern in BLOCKING_REGEX)):
37+
sys.exit("This PR is not ready for consumption.")
2438

25-
def __check_status(issue):
26-
response = requests.get(f"{REDMINE_URL}/issues/{issue}.json")
27-
response.raise_for_status()
28-
bug_json = response.json()
29-
status = bug_json["issue"]["status"]["name"]
30-
if status not in STATUSES:
31-
sys.exit(
32-
"Error: issue #{issue} has invalid status of {status}. Status must be one of "
33-
"{statuses}.".format(issue=issue, status=status, statuses=", ".join(STATUSES))
34-
)
39+
g = Github(os.environ.get("GITHUB_TOKEN"))
40+
repo = g.get_repo("pulp/pulp-openapi-generator")
3541

36-
if project:
37-
project_id = bug_json["issue"]["project"]["id"]
38-
project_json = requests.get(f"{REDMINE_URL}/projects/{project_id}.json").json()
39-
if project_json["project"]["identifier"] != project:
40-
sys.exit(f"Error: issue {issue} is not in the {project} project.")
4142

43+
def check_status(issue):
44+
gi = repo.get_issue(int(issue))
45+
if gi.pull_request:
46+
sys.exit(f"Error: issue #{issue} is a pull request.")
47+
if gi.closed_at:
48+
sys.exit(f"Error: issue #{issue} is closed.")
4249

43-
def __check_changelog(issue):
50+
51+
def check_changelog(issue):
4452
matches = list(Path("CHANGES").rglob(f"{issue}.*"))
4553

4654
if len(matches) < 1:
@@ -53,22 +61,15 @@ def __check_changelog(issue):
5361
print("Checking commit message for {sha}.".format(sha=sha[0:7]))
5462

5563
# validate the issue attached to the commit
56-
regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
57-
pattern = re.compile(regex, re.IGNORECASE)
58-
59-
issues = pattern.findall(message)
64+
issue_regex = r"(?:{keywords})[\s:]+#(\d+)".format(keywords=("|").join(KEYWORDS))
65+
issues = re.findall(issue_regex, message, re.IGNORECASE)
66+
cherry_pick_regex = r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$"
67+
cherry_pick = re.search(cherry_pick_regex, message, re.MULTILINE)
6068

6169
if issues:
62-
for issue in pattern.findall(message):
63-
__check_status(issue)
64-
# __check_changelog(issue)
65-
else:
66-
if NO_ISSUE in message:
67-
print("Commit {sha} has no issues but is tagged {tag}.".format(sha=sha[0:7], tag=NO_ISSUE))
68-
else:
69-
sys.exit(
70-
"Error: no attached issues found for {sha}. If this was intentional, add "
71-
" '{tag}' to the commit message.".format(sha=sha[0:7], tag=NO_ISSUE)
72-
)
70+
for issue in issues:
71+
if not cherry_pick:
72+
check_status(issue)
73+
check_changelog(issue)
7374

7475
print("Commit message for {sha} passed.".format(sha=sha[0:7]))

.github/workflows/ci.yml

+51-27
Original file line numberDiff line numberDiff line change
@@ -1,56 +1,63 @@
11
---
2-
name: pulp-openapi-generator PR CI
3-
on: pull_request
2+
name: "pulp-openapi-generator PR CI"
3+
on:
4+
pull_request:
45

5-
jobs:
6+
concurrency:
7+
group: ${{ github.ref_name }}-${{ github.workflow }}
8+
cancel-in-progress: true
69

7-
lint:
8-
runs-on: ubuntu-latest
10+
defaults:
11+
run:
12+
working-directory: "pulp-openapi-generator"
913

14+
jobs:
15+
check-commits:
16+
runs-on: "ubuntu-latest"
1017
steps:
11-
- uses: actions/checkout@v2
18+
- uses: "actions/checkout@v4"
1219
with:
13-
# by default, it uses a depth of 1
14-
# this fetches all history so that we can read each commit
1520
fetch-depth: 0
16-
17-
- uses: actions/setup-python@v2
21+
path: "pulp-openapi-generator"
22+
- uses: "actions/setup-python@v5"
1823
with:
19-
python-version: "3.8"
20-
21-
- name: Check commit message
24+
python-version: "3.11"
25+
- name: "Install python dependencies"
26+
run: |
27+
pip install requests pygithub
28+
- name: "Check commit message"
2229
if: github.event_name == 'pull_request'
2330
env:
24-
GITHUB_CONTEXT: ${{ github.event.pull_request.commits_url }}
31+
PY_COLORS: "1"
32+
ANSIBLE_FORCE_COLOR: "1"
33+
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
34+
GITHUB_CONTEXT: "${{ github.event.pull_request.commits_url }}"
2535
run: |
26-
pip install requests
27-
sh .github/workflows/scripts/check_commit.sh
36+
.github/workflows/scripts/check_commit.sh
2837
2938
docs:
30-
uses: "./.github/workflows/docs-ci.yml"
39+
uses: "./.github/workflows/docs.yml"
3140

32-
pulp:
33-
runs-on: ubuntu-latest
41+
test:
42+
runs-on: "ubuntu-latest"
3443
# run only after lint and docs finishes
3544
needs:
36-
- lint
37-
- docs
45+
- "docs"
3846
strategy:
3947
fail-fast: false
4048
matrix:
4149
env:
42-
- TEST: pulp
50+
- TEST: "pulp"
4351

4452
steps:
45-
- uses: actions/checkout@v2
53+
- uses: "actions/checkout@v4"
4654
with:
47-
# by default, it uses a depth of 1
48-
# this fetches all history so that we can read each commit
4955
fetch-depth: 0
56+
path: "pulp-openapi-generator"
5057

51-
- uses: actions/setup-python@v2
58+
- uses: "actions/setup-python@v5"
5259
with:
53-
python-version: "3.8"
60+
python-version: "3.11"
5461

5562
- uses: ruby/setup-ruby@v1
5663
with:
@@ -93,3 +100,20 @@ jobs:
93100
docker logs pulp || true
94101
docker exec pulp ls -latr /etc/yum.repos.d/ || true
95102
docker exec pulp cat /etc/yum.repos.d/* || true
103+
104+
ready-to-ship:
105+
# This is a dummy dependent task to have a single entry for the branch protection rules.
106+
runs-on: "ubuntu-latest"
107+
needs:
108+
- "check-commits"
109+
- "test"
110+
- "docs"
111+
if: "always()"
112+
steps:
113+
- name: "Collect needed jobs results"
114+
working-directory: "."
115+
run: |
116+
echo '${{toJson(needs)}}' | jq -r 'to_entries[]|select(.value.result!="success")|.key + ": " + .value.result'
117+
echo '${{toJson(needs)}}' | jq -e 'to_entries|map(select(.value.result!="success"))|length == 0'
118+
echo "CI says: Looks good!"
119+
...

.github/workflows/docs-ci.yml renamed to .github/workflows/docs.yml

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,6 @@ jobs:
1515
- name: "Install Test Dependencies"
1616
run: |
1717
pip install -r doc_requirements.txt
18-
- name: Build docs
19-
run: make docs
18+
- name: "Build docs"
19+
run: |
20+
make docs

.github/workflows/scripts/before_install.sh

+12-1
Original file line numberDiff line numberDiff line change
@@ -7,9 +7,20 @@
77
#
88
# For more info visit https://github.com/pulp/plugin_template
99

10+
# make sure this script runs at the repo root
11+
cd "$(dirname "$(realpath -e "$0")")"/../../..
12+
1013
set -mveuo pipefail
1114

1215
# Intall requirements for ansible playbooks
1316
pip install docker netaddr boto3 ansible
1417

15-
ansible-galaxy collection install amazon.aws
18+
for i in {1..3}
19+
do
20+
ansible-galaxy collection install "amazon.aws:8.1.0" && s=0 && break || s=$? && sleep 3
21+
done
22+
if [[ $s -gt 0 ]]
23+
then
24+
echo "Failed to install amazon.aws"
25+
exit $s
26+
fi
+4-16
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,11 @@
11
#!/bin/bash
22

3-
# WARNING: DO NOT EDIT!
4-
#
5-
# This file was generated by plugin_template, and is managed by it. Please use
6-
# './plugin-template --github pulp_file' to update this file.
7-
#
8-
# For more info visit https://github.com/pulp/plugin_template
3+
# make sure this script runs at the repo root
4+
cd "$(dirname "$(realpath -e "$0")")/../../.."
95

106
set -euv
117

12-
echo ::group::REQUESTS
13-
pip3 install requests
14-
echo ::endgroup::
15-
16-
for sha in $(curl $GITHUB_CONTEXT | jq '.[].sha' | sed 's/"//g')
8+
for SHA in $(curl -H "Authorization: token $GITHUB_TOKEN" "$GITHUB_CONTEXT" | jq -r '.[].sha')
179
do
18-
python3 .ci/scripts/validate_commit_message.py $sha
19-
VALUE=$?
20-
if [ "$VALUE" -gt 0 ]; then
21-
exit $VALUE
22-
fi
10+
python3 .ci/scripts/validate_commit_message.py "$SHA"
2311
done

.github/workflows/scripts/install.sh

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
#
88
# For more info visit https://github.com/pulp/plugin_template
99

10-
set -euv
11-
1210
# make sure this script runs at the repo root
1311
cd "$(dirname "$(realpath -e "$0")")"/../../..
1412

13+
set -euv
14+
1515
TAG="${TAG:-latest}"
1616

1717
mkdir -p .ci/ansible/vars

.github/workflows/scripts/test_bindings.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,7 @@ def upload_file_in_chunks(file_path):
152152
pprint(repository_version_1)
153153

154154
# Create an artifact from a local file
155-
file_path = os.path.join(os.environ["GITHUB_WORKSPACE"], ".github/workflows/scripts/test_bindings.py")
156-
artifact = artifacts.create(file=file_path)
155+
artifact = artifacts.create(file=__file__)
157156
pprint(artifact)
158157

159158
# Create a FileContent from the artifact

.github/workflows/scripts/test_bindings.rb

+5-10
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@ def monitor_task(task_href)
4040
#
4141
# Returns:
4242
# list[str]: List of hrefs that identify resource created by the task
43-
completed = []
4443
task = @tasks_api.read(task_href)
4544
until ["completed", "failed", "canceled"].include? task.state
4645
sleep(2)
@@ -86,8 +85,8 @@ def upload_file_in_chunks(file_path)
8685
filechunk.write(chunk)
8786
filechunk.flush()
8887
actual_chunk_size = File.size(filechunk)
89-
response = @uploads_api.update(content_range(offset, offset + actual_chunk_size -1, total_size), upload_href, filechunk)
90-
offset += actual_chunk_size -1
88+
response = @uploads_api.update(content_range(offset, offset + actual_chunk_size - 1, total_size), upload_href, filechunk)
89+
offset += actual_chunk_size - 1
9190
ensure
9291
filechunk.close
9392
filechunk.unlink
@@ -100,7 +99,7 @@ def upload_file_in_chunks(file_path)
10099
end
101100

102101

103-
artifact = upload_file_in_chunks(File.join(ENV['GITHUB_WORKSPACE'], 'README.rst'))
102+
artifact = upload_file_in_chunks(File.new(File.expand_path(__FILE__)))
104103

105104
# Create a File Remote
106105
remote_url = 'https://fixtures.pulpproject.org/file/PULP_MANIFEST'
@@ -120,12 +119,8 @@ def upload_file_in_chunks(file_path)
120119

121120
repository_version_1 = @repoversions_api.read(created_resources[0])
122121

123-
# Create an artifact from a local file
124-
file_path = File.join(ENV['GITHUB_WORKSPACE'], '.github/workflows/scripts/test_bindings.rb')
125-
artifact = @artifacts_api.create(File.new(file_path))
126-
127-
# Create a FileContent from the artifact
128-
filecontent_response = @filecontent_api.create('foo.tar.gz', {artifact: artifact.pulp_href})
122+
# Create a FileContent from a local file
123+
filecontent_response = @filecontent_api.create('foo.tar.gz', {file: File.new(File.expand_path(__FILE__))})
129124

130125
created_resources = monitor_task(filecontent_response.task)
131126

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

pyproject.toml

Whitespace-only changes.

0 commit comments

Comments
 (0)