check changelog using nox
This commit is contained in:
parent
7180a0b77c
commit
9e04398a5e
|
@ -8,28 +8,8 @@ jobs:
|
||||||
check:
|
check:
|
||||||
name: Check changelog entry
|
name: Check changelog entry
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
if: ${{ !contains(github.event.pull_request.labels.*.name, 'CI-skip-changelog') && !startsWith(github.event.pull_request.title, 'release:') }}
|
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- uses: actions/github-script@v6
|
- uses: actions/setup-python@v4
|
||||||
id: check
|
- run: pip install nox
|
||||||
with:
|
- run: nox -s check-changelog
|
||||||
script: |
|
|
||||||
const fs = require('node:fs')
|
|
||||||
const path = require('node:path')
|
|
||||||
|
|
||||||
let found = false
|
|
||||||
const changeTypes = ['packaging', 'added', 'changed', 'removed', 'fixed']
|
|
||||||
for (changeType of changeTypes) {
|
|
||||||
const filename = path.join('newsfragments', `${context.issue.number}.${changeType}.md`)
|
|
||||||
if (fs.existsSync(filename)) {
|
|
||||||
found = true
|
|
||||||
break
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
const errorMsg = '📝 Changelog entry not found, please add one (or more) to `newsfragments` directory. For more information see https://github.com/PyO3/pyo3/blob/main/Contributing.md#documenting-changes'
|
|
||||||
core.error(errorMsg)
|
|
||||||
process.exit(1)
|
|
||||||
}
|
|
||||||
|
|
57
noxfile.py
57
noxfile.py
|
@ -1,3 +1,4 @@
|
||||||
|
import json
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
|
@ -13,6 +14,9 @@ import nox
|
||||||
nox.options.sessions = ["test", "clippy", "fmt"]
|
nox.options.sessions = ["test", "clippy", "fmt"]
|
||||||
|
|
||||||
|
|
||||||
|
PYO3_DIR = Path(__file__).parent
|
||||||
|
|
||||||
|
|
||||||
@nox.session(venv_backend="none")
|
@nox.session(venv_backend="none")
|
||||||
def test(session: nox.Session) -> None:
|
def test(session: nox.Session) -> None:
|
||||||
test_rust(session)
|
test_rust(session)
|
||||||
|
@ -159,9 +163,8 @@ def contributors(session: nox.Session) -> None:
|
||||||
|
|
||||||
class EmscriptenInfo:
|
class EmscriptenInfo:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
rootdir = Path(__file__).parent
|
self.emscripten_dir = PYO3_DIR / "emscripten"
|
||||||
self.emscripten_dir = rootdir / "emscripten"
|
self.builddir = PYO3_DIR / ".nox/emscripten"
|
||||||
self.builddir = rootdir / ".nox/emscripten"
|
|
||||||
self.builddir.mkdir(exist_ok=True, parents=True)
|
self.builddir.mkdir(exist_ok=True, parents=True)
|
||||||
|
|
||||||
self.pyversion = sys.version.split()[0]
|
self.pyversion = sys.version.split()[0]
|
||||||
|
@ -305,8 +308,48 @@ def address_sanitizer(session: nox.Session):
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
@nox.session(name="check-changelog")
|
||||||
|
def check_changelog(session: nox.Session):
|
||||||
|
event_path = os.environ.get("GITHUB_EVENT_PATH")
|
||||||
|
if event_path is None:
|
||||||
|
session.error("Can only check changelog on github actions")
|
||||||
|
|
||||||
|
with open(event_path) as event_file:
|
||||||
|
event = json.load(event_file)
|
||||||
|
|
||||||
|
if event["pull_request"]["title"].startswith("release:"):
|
||||||
|
session.skip("PR title starts with release")
|
||||||
|
|
||||||
|
for label in event["pull_request"]["labels"]:
|
||||||
|
if label["name"] == "CI-skip-changelog":
|
||||||
|
session.skip("CI-skip-changelog label applied")
|
||||||
|
|
||||||
|
issue_number = event["pull_request"]["number"]
|
||||||
|
|
||||||
|
newsfragments = PYO3_DIR / "newsfragments"
|
||||||
|
|
||||||
|
fragments = tuple(
|
||||||
|
filter(
|
||||||
|
Path.exists,
|
||||||
|
(
|
||||||
|
newsfragments / f"{issue_number}.{change_type}.md"
|
||||||
|
for change_type in ("packaging", "added", "changed", "removed", "fixed")
|
||||||
|
),
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if not fragments:
|
||||||
|
session.error(
|
||||||
|
"Changelog entry not found, please add one (or more) to `newsfragments` directory. For more information see https://github.com/PyO3/pyo3/blob/main/Contributing.md#documenting-changes"
|
||||||
|
)
|
||||||
|
|
||||||
|
print("Found newsfragments:")
|
||||||
|
for fragment in fragments:
|
||||||
|
print(fragment.name)
|
||||||
|
|
||||||
|
|
||||||
def _get_rust_target() -> str:
|
def _get_rust_target() -> str:
|
||||||
output = subprocess.check_output(["rustc", "-vV"], text=True)
|
output = _get_output("rustc", "-vV")
|
||||||
|
|
||||||
for line in output.splitlines():
|
for line in output.splitlines():
|
||||||
if line.startswith(_HOST_LINE_START):
|
if line.startswith(_HOST_LINE_START):
|
||||||
|
@ -318,7 +361,7 @@ _HOST_LINE_START = "host: "
|
||||||
|
|
||||||
def _get_coverage_env() -> Dict[str, str]:
|
def _get_coverage_env() -> Dict[str, str]:
|
||||||
env = {}
|
env = {}
|
||||||
output = subprocess.check_output(["cargo", "llvm-cov", "show-env"], text=True)
|
output = _get_output("cargo", "llvm-cov", "show-env")
|
||||||
|
|
||||||
for line in output.strip().splitlines():
|
for line in output.strip().splitlines():
|
||||||
(key, value) = line.split("=", maxsplit=1)
|
(key, value) = line.split("=", maxsplit=1)
|
||||||
|
@ -363,3 +406,7 @@ def _run_cargo_test(
|
||||||
|
|
||||||
def _run_cargo_publish(session: nox.Session, *, package: str) -> None:
|
def _run_cargo_publish(session: nox.Session, *, package: str) -> None:
|
||||||
_run(session, "cargo", "publish", f"--package={package}", external=True)
|
_run(session, "cargo", "publish", f"--package={package}", external=True)
|
||||||
|
|
||||||
|
|
||||||
|
def _get_output(*args: str) -> str:
|
||||||
|
return subprocess.run(args, capture_output=True, text=True, check=True).stdout
|
||||||
|
|
Loading…
Reference in New Issue