-
Notifications
You must be signed in to change notification settings - Fork 55
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #668 from gerrod3/patchback/backports/3.49/c130256…
…b4add3c49e20269b3795ba60f2680ecd6/pr-666 Backport [3.49] Streamline CI
- Loading branch information
Showing
4 changed files
with
156 additions
and
31 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
#!/bin/env python3 | ||
|
||
# This script is running with elevated privileges from the main branch against pull requests. | ||
|
||
import re | ||
import sys | ||
import tomllib | ||
from pathlib import Path | ||
|
||
from git import Repo | ||
|
||
|
||
def main(): | ||
assert len(sys.argv) == 3 | ||
|
||
with open("pyproject.toml", "rb") as fp: | ||
PYPROJECT_TOML = tomllib.load(fp) | ||
BLOCKING_REGEX = re.compile(r"DRAFT|WIP|NO\s*MERGE|DO\s*NOT\s*MERGE|EXPERIMENT") | ||
ISSUE_REGEX = re.compile(r"(?:fixes|closes)[\s:]+#(\d+)") | ||
CHERRY_PICK_REGEX = re.compile(r"^\s*\(cherry picked from commit [0-9a-f]*\)\s*$") | ||
try: | ||
CHANGELOG_EXTS = { | ||
f".{item['directory']}" for item in PYPROJECT_TOML["tool"]["towncrier"]["type"] | ||
} | ||
except KeyError: | ||
CHANGELOG_EXTS = {"feature", "bugfix", "doc", "removal", "misc"} | ||
|
||
repo = Repo(".") | ||
|
||
base_commit = repo.commit(sys.argv[1]) | ||
head_commit = repo.commit(sys.argv[2]) | ||
|
||
pr_commits = list(repo.iter_commits(f"{base_commit}..{head_commit}")) | ||
|
||
labels = { | ||
"multi-commit": len(pr_commits) > 1, | ||
"cherry-pick": False, | ||
"no-issue": False, | ||
"no-changelog": False, | ||
"wip": False, | ||
} | ||
for commit in pr_commits: | ||
labels["wip"] |= BLOCKING_REGEX.search(commit.summary) is not None | ||
no_issue = ISSUE_REGEX.search(commit.message, re.IGNORECASE) is None | ||
labels["no-issue"] |= no_issue | ||
cherry_pick = CHERRY_PICK_REGEX.search(commit.message) is not None | ||
labels["cherry-pick"] |= cherry_pick | ||
changelog_snippets = [ | ||
k | ||
for k in commit.stats.files | ||
if k.startswith("CHANGES/") and Path(k).suffix in CHANGELOG_EXTS | ||
] | ||
labels["no-changelog"] |= not changelog_snippets | ||
|
||
print("ADD_LABELS=" + ",".join((k for k, v in labels.items() if v))) | ||
print("REMOVE_LABELS=" + ",".join((k for k, v in labels.items() if not v))) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
# WARNING: DO NOT EDIT! | ||
# | ||
# This file was generated by plugin_template and copied over to this repository :) | ||
# | ||
# For more info visit https://github.com/pulp/plugin_template | ||
|
||
--- | ||
name: "Pulp-OCI-Images PR static checks" | ||
on: | ||
pull_request_target: | ||
types: ["opened", "synchronize", "reopened"] | ||
|
||
# This workflow runs with elevated permissions. | ||
# Do not even think about running a single bit of code from the PR. | ||
# Static analysis should be fine however. | ||
|
||
concurrency: | ||
group: "${{ github.event.pull_request.number }}-${{ github.workflow }}" | ||
cancel-in-progress: true | ||
|
||
jobs: | ||
apply_labels: | ||
runs-on: "ubuntu-latest" | ||
name: "Label PR" | ||
permissions: | ||
pull-requests: "write" | ||
steps: | ||
- uses: "actions/checkout@v4" | ||
with: | ||
fetch-depth: 0 | ||
- uses: "actions/setup-python@v5" | ||
with: | ||
python-version: "3.11" | ||
- name: "Determine PR labels" | ||
run: | | ||
pip install GitPython==3.1.42 | ||
git fetch origin ${{ github.event.pull_request.head.sha }} | ||
python .ci/scripts/pr_labels.py "origin/${{ github.base_ref }}" "${{ github.event.pull_request.head.sha }}" >> "$GITHUB_ENV" | ||
- uses: "actions/github-script@v7" | ||
name: "Apply PR Labels" | ||
with: | ||
script: | | ||
const { ADD_LABELS, REMOVE_LABELS } = process.env; | ||
if (REMOVE_LABELS.length) { | ||
for await (const labelName of REMOVE_LABELS.split(",")) { | ||
try { | ||
await github.rest.issues.removeLabel({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
name: labelName, | ||
}); | ||
} catch(err) { | ||
} | ||
} | ||
} | ||
if (ADD_LABELS.length) { | ||
await github.rest.issues.addLabels({ | ||
issue_number: context.issue.number, | ||
owner: context.repo.owner, | ||
repo: context.repo.repo, | ||
labels: ADD_LABELS.split(","), | ||
}); | ||
} | ||
... |