Skip to content

Commit

Permalink
build: modernize build system and repo configuration (#658)
Browse files Browse the repository at this point in the history
* build: modernize build system and repo configuration

* blast radius

* add labels

* blast area

* Trigger Build

* clean up
  • Loading branch information
bachya authored Feb 3, 2025
1 parent 2ef13c2 commit 23a2e74
Show file tree
Hide file tree
Showing 21 changed files with 1,804 additions and 2,099 deletions.
18 changes: 18 additions & 0 deletions .github/actions/install-uv/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: "Install uv"
description: "Installs uv (pinned to the version used by this repo)"

runs:
using: "composite"
steps:
- name: Get uv version from pyproject.toml
shell: bash
id: uv-version
run: |
echo "version=$(grep "uv==" pyproject.toml | awk -F'==' '{print $2'} | tr -d '",')" >> $GITHUB_OUTPUT
- name: Install uv
uses: astral-sh/setup-uv@v5
with:
cache-dependency-glob: "uv.lock"
enable-cache: true
version: ${{ steps.uv-version.outputs.version }}
2 changes: 2 additions & 0 deletions .github/config/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
"release":
- base-branch: "main"
64 changes: 64 additions & 0 deletions .github/config/labels.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
---
- name: "breaking-change"
color: ee0701
description: "A breaking change for existing users"

- name: "help-wanted"
color: 0e8a16
description: "Needs a helping hang or expertise in order to resolve"

- name: "no-stale"
color: fef2c0
description: "This issue or PR is exempted from the stale bot"

- name: "release"
color: d93f0b
description: "A release of the library"

- name: "stale"
color: fef2c0
description: "There has not been activity on this issue or PR for some time"

- color: "ff2191"
description: "A bugfix"
name: "type: bugfix"

- color: "ff2191"
description: "A change to the local or production build system"
name: "type: build"

- color: "ff2191"
description: "A change to a CI/CD configuration"
name: "type: ci"

- color: "ff2191"
description: "A change that doesn't modify source or test files"
name: "type: chore"

- color: "ff2191"
description: "A documentation change"
name: "type: docs"

- color: "ff2191"
description: "A new feature or enhancement"
name: "type: feature"

- color: "ff2191"
description: "A code change that improves performance"
name: "type: performance"

- color: "ff2191"
description: "A code change that neither fixes a bug nor adds a feature"
name: "type: refactor"

- color: "ff2191"
description: "Reverts a previous commit"
name: "type: reversion"

- color: "ff2191"
description: "A change that does not affect the meaning of the code"
name: "type: style"

- color: "ff2191"
description: "Adds missing tests or corrects existing tests"
name: "type: test"
20 changes: 0 additions & 20 deletions .github/dependabot.yml

This file was deleted.

43 changes: 0 additions & 43 deletions .github/labels.yml

This file was deleted.

5 changes: 0 additions & 5 deletions .github/workflows/codeql.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,6 @@
name: CodeQL

"on":
push:
branches:
- dev
- main

pull_request:
branches:
- dev
Expand Down
7 changes: 5 additions & 2 deletions .github/workflows/publish.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,10 @@ jobs:
with:
python-version: "3.12"

- name: 🚜 Install uv
uses: ./.github/actions/install-uv

- name: 🚀 Publish to PyPi
run: |
pip install --upgrade pip poetry setuptools wheel
poetry publish --build -u __token__ -p ${{ secrets.PYPI_API_KEY }}
uv build
uv publish --token ${{ secrets.PYPI_API_KEY }}
1 change: 0 additions & 1 deletion .github/workflows/requirements.txt

This file was deleted.

134 changes: 134 additions & 0 deletions .github/workflows/scan-pull-request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,134 @@
name: Scan Pull Request

on:
pull_request:
types:
- edited
- opened
- reopened
- synchronize

workflow_dispatch:

permissions:
contents: read
pull-requests: write
repository-projects: read

jobs:
lint-pr-title:
name: 🏷️ Lint PR Title

runs-on: ubuntu-latest

steps:
- name: Lint title
uses: amannn/action-semantic-pull-request@v5
id: lint-title
env:
GITHUB_TOKEN: ${{ github.token }}

- name: Create error comment
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ always() && steps.lint-title.outputs.error_message != null }}
with:
header: lint-title-error-comment
message: |
We require pull request titles to follow the [Conventional Commits specification](https://www.conventionalcommits.org/en/v1.0.0/) and it looks like this pull request's title needs to be adjusted.
Details:
```
${{ steps.lint-title.outputs.error_message }}
```
- name: Delete error comment
uses: marocchino/sticky-pull-request-comment@v2
if: ${{ steps.lint-title.outputs.error_message == null }}
with:
header: lint-title-error-comment
delete: true

set-labels:
name: 🏷️ Set Labels

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Set labels
uses: actions/labeler@v5
with:
configuration-path: ./.github/config/labeler.yml
sync-labels: true

- name: Assign Conventional Commit label
shell: bash
env:
PR_CURRENT_LABELS_JSON: ${{ toJson(github.event.pull_request.labels) }}
PR_TITLE: ${{ github.event.pull_request.title }}
GITHUB_TOKEN: ${{ github.token }}
run: |
# Create a mapping between Conventional Commit prefixes and our labels:
label_map='{
"build": "type: build",
"chore": "type: chore",
"ci": "type: ci",
"docs": "type: docs",
"feat": "type: feature",
"fix": "type: bugfix",
"perf": "type: performance",
"refactor": "type: refactor",
"revert": "type: reversion",
"style": "type: style",
"test": "type: test"
}'
# Strip any surrounding whitespace from the sanitized PR title:
pr_title="$(echo "$PR_TITLE" | tr -d '\n' | xargs)"
# Parse the existing labels:
pr_current_labels=$(echo "$PR_CURRENT_LABELS_JSON" | jq '.[].name')
# Determine the Conventional Commit type based upon the PR title:
commit_type="$(echo "$pr_title" | cut -d: -f1 | sed 's/(.*)//g; s/!//g')"
echo "Detected Conventional Commit type: '$commit_type'"
if [[ -z "$commit_type" ]]; then
echo "Commit type could not be extracted from PR title: '$pr_title'"
exit 1
fi
# Pull the appropriate label based on the detected Conventional Commit type:
label_to_apply="$(echo "$label_map" | jq -r --arg type "$commit_type" '.[$type] // empty')"
if [[ -z "$label_to_apply" ]]; then
echo "Unrecognized Conventional Commit type: '$commit_type'"
exit 1
fi
echo "Mapping Conventional Commit type '$commit_type' to label: '$label_to_apply'"
# Determine whether any outdated Conventional Commit labels need to be
# removed:
labels_to_remove_csv=$(echo "$PR_CURRENT_LABELS_JSON" | jq -r --argjson label_map "$label_map" --arg current_label "$label_to_apply" '.[].name | select(. != $current_label and (. as $existing | $label_map | any(.[]; . == $existing)))' | paste -sd, -)
echo "Removing incorrect Conventional Commit labels: '$labels_to_remove_csv'"
# If the label to add is already applied, skip it:
labels_to_add_csv=""
if echo "$pr_current_labels" | grep -qw "$label_to_apply"; then
echo "Label already exists on the PR: '$label_to_apply'"
else
echo "Label should be added to the PR: '$label_to_apply'"
labels_to_add_csv+="$label_to_apply"
fi
# Apply the label changes:
if [[ -n "$labels_to_remove_csv" || -n "$labels_to_add_csv" ]]; then
gh pr edit \
"${{ github.event.pull_request.number }}" \
${labels_to_add_csv:+--add-label "$labels_to_add_csv"} \
${labels_to_remove_csv:+--remove-label "$labels_to_remove_csv"}
else
echo "No label changes needed"
fi
46 changes: 11 additions & 35 deletions .github/workflows/static-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,7 @@ name: Linting and Static Analysis
- dev
- main

push:
branches:
- dev
- main
workflow_dispatch:

jobs:
lint:
Expand All @@ -28,41 +25,20 @@ jobs:
with:
python-version: "3.12"

- name: ⤵️ Get pip cache directory
id: pip-cache
run: |
echo "dir=$(pip cache dir)" >> $GITHUB_OUTPUT
- name: ⤵️ Establish pip cache
uses: actions/cache@v4
with:
path: ${{ steps.pip-cache.outputs.dir }}
key: "${{ runner.os }}-pip-\
${{ hashFiles('.github/workflows/requirements.txt') }}"
restore-keys: |
${{ runner.os }}-pip-
- name: 🚜 Install uv
uses: ./.github/actions/install-uv

- name: 🏗 Install workflow dependencies
run: |
pip install --upgrade pip setuptools wheel
pip install -r .github/workflows/requirements.txt
poetry config virtualenvs.create true
poetry config virtualenvs.in-project true
uv sync --extra lint
- name: ⤵️ Establish poetry cache
uses: actions/cache@v4
- name: Get all changed files
id: changed-files
uses: tj-actions/[email protected]
with:
path: .venv
key: "venv-${{ steps.setup-python.outputs.python-version }}-\
${{ hashFiles('poetry.lock') }}"
restore-keys: |
venv-${{ steps.setup-python.outputs.python-version }}-
fetch_depth: 0

- name: 🏗 Install package dependencies
- name: Run pre-commit hooks
run: |
poetry install --no-interaction
- name: 🚀 Run pre-commit hooks
uses: pre-commit/[email protected]
env:
SKIP: no-commit-to-branch,pytest
uv run pre-commit run \
--files ${{ steps.changed-files.outputs.all_changed_files }}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ name: Sync Labels
"on":
push:
branches:
- main
- dev
paths:
- .github/labels.yml
- .github/config/labels.yml
- .github/config/labeler.yml

workflow_dispatch:

Expand All @@ -20,5 +21,7 @@ jobs:

- name: 🚀 Run Label Syncer
uses: micnncim/[email protected]
with:
manifest: .github/config/labels.yml
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Loading

0 comments on commit 23a2e74

Please sign in to comment.