From bd231efad1e033b18beae228b85a2d018ef07755 Mon Sep 17 00:00:00 2001 From: Lucas Combs Date: Tue, 9 Sep 2025 21:31:46 -0400 Subject: [PATCH 1/2] GH-127: Add PR label check --- .github/actions/setup-python/action.yml | 10 +++++ .github/workflows/build.yml | 8 +--- .github/workflows/pr-label-check.yml | 17 ++++++++ scripts/pr_label_check.py | 52 +++++++++++++++++++++++++ 4 files changed, 80 insertions(+), 7 deletions(-) create mode 100644 .github/actions/setup-python/action.yml create mode 100644 .github/workflows/pr-label-check.yml create mode 100644 scripts/pr_label_check.py diff --git a/.github/actions/setup-python/action.yml b/.github/actions/setup-python/action.yml new file mode 100644 index 0000000..f518381 --- /dev/null +++ b/.github/actions/setup-python/action.yml @@ -0,0 +1,10 @@ +name: "Setup Python" +description: "Setup the correct version of python" + +runs: + using: "composite" + steps: + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.13 diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index f7dbcb6..6f2b26e 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -20,19 +20,13 @@ jobs: steps: - uses: actions/checkout@v5 - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: 3.13 + - uses: ./.github/actions/setup-python - name: Install dependencies run: | python scripts/os_specific_requirements.py python -m pip install --upgrade pip pip install -r requirements.txt shell: bash - - name: Prepare Scripts - run: | - chmod +x scripts/* - name: Lint run: | python scripts/lint.py diff --git a/.github/workflows/pr-label-check.yml b/.github/workflows/pr-label-check.yml new file mode 100644 index 0000000..752492d --- /dev/null +++ b/.github/workflows/pr-label-check.yml @@ -0,0 +1,17 @@ +name: PR Label Check + +on: + pull_request: + types: [opened, labeled, unlabeled] + +jobs: + validate-labels: + name: Validate release label + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + - uses: ./.github/actions/setup-python + - name: Check PR has exactly one release label + run: | + python scripts/pr_label_check.py "$GITHUB_EVENT_PATH" + shell: bash diff --git a/scripts/pr_label_check.py b/scripts/pr_label_check.py new file mode 100644 index 0000000..ca54bc7 --- /dev/null +++ b/scripts/pr_label_check.py @@ -0,0 +1,52 @@ +""" + Ensure a pull request has exactly one version label +""" +import os +import sys +import json + +VALID_LABELS = {'Patch', 'Minor', 'Major', "no-release"} + +def extract_labels_from_event(event_file: str) -> set[str]: + """Extract label names from a GitHub event JSON file. + + Args: + event_file: Path to the JSON event file produced by GitHub Actions. + + Returns: + A set of label names (strings) found on the pull request. + """ + with open(event_file, 'r', encoding='utf-8') as f: + payload = json.load(f) + labels = payload.get('pull_request', {}).get('labels', []) + return {str(lbl.get('name', '')).strip() for lbl in labels} + + +def are_labels_valid(labels_on_pr: set[str]) -> bool: + """Check whether the PR has exactly one allowed version label. + + Args: + labels_on_pr: Set of label names present on the pull request. + + Returns: + True if exactly one label from VALID_LABELS is present; otherwise False. + """ + print(f"Found labels on pull request: {labels_on_pr}") + overlap = VALID_LABELS.intersection(labels_on_pr) + return len(overlap) == 1 + + +if __name__ == "__main__": + print("Checking pull request labels") + event_path = sys.argv[1] + success: bool = False + if event_path and os.path.isfile(event_path): + all_labels = extract_labels_from_event(event_path) + success = are_labels_valid(all_labels) + else: + print("No labels found") + + if not success: + print(f"Did not find exactly one of the following labels: {VALID_LABELS}") + + sys.exit(0 if success else 1) From ad8005ceded3873e4d3ebcb8bf40265a3052c919 Mon Sep 17 00:00:00 2001 From: Lucas Combs Date: Sun, 14 Sep 2025 14:36:22 -0400 Subject: [PATCH 2/2] NOGH: General pipeline cleanup --- .github/workflows/build.yml | 30 ++++++++++++++--------------- README.md | 3 --- scripts/os_specific_requirements.py | 14 -------------- 3 files changed, 15 insertions(+), 32 deletions(-) delete mode 100644 scripts/os_specific_requirements.py diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6f2b26e..cb24a85 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -10,7 +10,6 @@ on: jobs: build: - runs-on: ${{ matrix.os }} strategy: fail-fast: false @@ -21,37 +20,37 @@ jobs: steps: - uses: actions/checkout@v5 - uses: ./.github/actions/setup-python + - name: Install dependencies - run: | - python scripts/os_specific_requirements.py - python -m pip install --upgrade pip - pip install -r requirements.txt - shell: bash + run: pip install -r requirements.txt + - name: Lint - run: | - python scripts/lint.py - shell: bash + run: python scripts/lint.py + - name: Test - run: | - pytest --doctest-modules --cov=src/main/ --cov-report=xml src/test + run: pytest --doctest-modules --cov=src/main/ --cov-report=xml src/test + - name: Package - run: | - python scripts/build_executable.py + run: python scripts/build_executable.py + - uses: actions/upload-artifact@master with: name: ${{ runner.os }} path: ./dist/* + - name: Integration - run: | - pytest src/integration + run: pytest src/integration + - name: Upload code coverage to codecov if: runner.os == 'Linux' env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} run: bash <(curl -s https://codecov.io/bash) -t "$CODECOV_TOKEN" -f coverage.xml + - name: Zip binaries for release if: github.event_name == 'release' run: python scripts/zip_release.py + - name: Upload binaries to release if: github.event_name == 'release' uses: svenstaro/upload-release-action@v2 @@ -60,6 +59,7 @@ jobs: file_glob: true file: '*.zip' tag: ${{ github.ref }} + - uses: actions/setup-ruby@v1 - name: Send Webhook Notification if: failure() diff --git a/README.md b/README.md index 7067fb9..1f1a108 100644 --- a/README.md +++ b/README.md @@ -65,9 +65,6 @@ Lastly, edit this config file to your liking: * Check your [core.hooksPath](https://git-scm.com/docs/githooks) - this setting can be `--global` or by repository. Check this first. * #### The hook is having a runtime error * Please submit an issue with the terminal output you received [here](https://github.com/unthreaded/git-hooks/issues) with as much detail as possible. - -## Development details -For Mac, you must install some dependencies via brew. Simply run [`os_specific_requirements.py`](scripts/os_specific_requirements.py) and you'll be good to go! ## Contributing [How to contribute](./CONTRIBUTING.md) diff --git a/scripts/os_specific_requirements.py b/scripts/os_specific_requirements.py deleted file mode 100644 index b309cc1..0000000 --- a/scripts/os_specific_requirements.py +++ /dev/null @@ -1,14 +0,0 @@ -""" - Anything our build needs to do for a specific OS goes here -""" -import os -import platform - -if __name__ == "__main__": - OS_PREFIX: str = platform.system().lower() - - print("Running OS setup") - print(f"OS: {OS_PREFIX}") - - if OS_PREFIX == "darwin": - os.system("brew install upx")