-
Notifications
You must be signed in to change notification settings - Fork 0
feat: extend linter config, add auto-changelog workflow and Conventional Commits guidelines #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
bczech
wants to merge
24
commits into
main
Choose a base branch
from
GDR-1014
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
ecabb4b
feat: extend linter config and add auto-changelog workflow
bczech 0e5ec6c
docs: add CONTRIBUTING.md with Conventional Commits guidelines and no…
bczech a32516e
chore: bump version to 1.11.3 and update NEWS.md
bczech 5cdd0ca
docs: update style_guide.Rmd with new linting rules and fix SemVer de…
bczech a48c980
chore: remove CONTRIBUTING.md in favor of style_guide.Rmd vignette
bczech f4430e4
chore: update NEWS.md
bczech 10b08ef
feat: add testthat linters and document all active linting rules in s…
bczech a5faedf
chore: simplify NEWS.md entry for 1.11.3
bczech cda7a66
refactor: unify linter config by bumping lintr requirement to >= 3.2.0
bczech d71fe13
fix: resolve shell injection in auto-changelog and stale CONTRIBUTING…
bczech ec809ed
fix: avoid f-string interpolation of diff content in auto-changelog
bczech 6f8a853
feat: add lintNewsEntries to enforce NEWS.md entry style
bczech 68a3d78
chore: revert version bump, add NEWS entry to 1.11.3
bczech 8f773f5
feat: set max_chars=120 and add max_bullets=3 rule per NEWS section
bczech b60626b
feat: forbid Jira ticket references in NEWS.md entries
bczech 68042cf
feat: forbid nrow/ncol in favor of NROW/NCOL
bczech 9c87422
fix: add cyclocomp to Imports to ensure cyclocomp_linter works
bczech 19dd60e
ci: trigger build
bczech 754dcf2
fix: export lintNewsEntries, fix self-lint violations, allow <<-/:::
bczech 4a4dba7
ci: trigger build
bczech 15a61f5
chore: bump version and update NEWS.md
bczech d390c4d
ci: trigger build
bczech 52c1b2a
refactor: revert cyclocomp refactoring, defer to separate PR
bczech 38d0f32
docs: update NEWS.md entry wording
bczech File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,154 @@ | ||
| name: auto-changelog | ||
|
|
||
| on: | ||
| workflow_call: | ||
| secrets: | ||
| ANTHROPIC_API_KEY: | ||
| required: true | ||
| PRIVATE_ACCESS_TOKEN: | ||
| required: true | ||
|
|
||
| jobs: | ||
| auto-changelog: | ||
| runs-on: ubuntu-24.04 | ||
| permissions: | ||
| contents: write | ||
| steps: | ||
| - uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 0 | ||
| token: ${{ secrets.PRIVATE_ACCESS_TOKEN }} | ||
| ref: ${{ github.head_ref }} | ||
|
|
||
| - name: Check if version bump and NEWS.md entry are present | ||
| id: check | ||
| run: | | ||
| PKG_NAME=$(grep "^Package:" DESCRIPTION | sed 's/Package: //') | ||
| CURRENT_VERSION=$(grep "^Version:" DESCRIPTION | sed 's/Version: //') | ||
| MAIN_VERSION=$(git show origin/main:DESCRIPTION | grep "^Version:" | sed 's/Version: //') | ||
|
|
||
| echo "pkg_name=$PKG_NAME" >> "$GITHUB_OUTPUT" | ||
| echo "current_version=$CURRENT_VERSION" >> "$GITHUB_OUTPUT" | ||
| echo "main_version=$MAIN_VERSION" >> "$GITHUB_OUTPUT" | ||
|
|
||
| VERSION_BUMPED=false | ||
| NEWS_OK=false | ||
|
|
||
| if [ "$CURRENT_VERSION" != "$MAIN_VERSION" ]; then | ||
| VERSION_BUMPED=true | ||
| fi | ||
|
|
||
| if grep -q "^## $PKG_NAME $CURRENT_VERSION" NEWS.md; then | ||
| NEWS_OK=true | ||
| fi | ||
|
|
||
| if [ "$VERSION_BUMPED" = "true" ] && [ "$NEWS_OK" = "true" ]; then | ||
| echo "skip=true" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "skip=false" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: Generate version bump and NEWS entry via Claude | ||
| if: steps.check.outputs.skip == 'false' | ||
| id: claude | ||
| env: | ||
| ANTHROPIC_API_KEY: ${{ secrets.ANTHROPIC_API_KEY }} | ||
| run: | | ||
| PKG_NAME="${{ steps.check.outputs.pkg_name }}" | ||
| MAIN_VERSION="${{ steps.check.outputs.main_version }}" | ||
|
|
||
| # Limit diff to 6000 chars to stay within token limits; write to file to avoid shell injection | ||
| git diff origin/main...HEAD -- . \ | ||
| ':(exclude)NEWS.md' \ | ||
| ':(exclude)DESCRIPTION' \ | ||
| ':(exclude)*.lock' \ | ||
| ':(exclude)*.rdb' \ | ||
| | head -c 6000 > /tmp/pr_diff.txt | ||
|
|
||
| PKG_NAME_ENV="$PKG_NAME" MAIN_VERSION_ENV="$MAIN_VERSION" python3 - <<PYEOF | ||
| import os, json, urllib.request | ||
|
|
||
| pkg_name = os.environ["PKG_NAME_ENV"] | ||
| main_version = os.environ["MAIN_VERSION_ENV"] | ||
|
|
||
| with open("/tmp/pr_diff.txt") as f: | ||
| diff = f.read() | ||
|
|
||
| prompt = ( | ||
| f"You are a changelog writer for an R package called '{pkg_name}'" | ||
| f" (current version on main: {main_version}).\n\n" | ||
| "Based on the following git diff from a pull request, determine:\n" | ||
| "1. The version bump type: patch (bug fixes, docs, refactoring)," | ||
| " minor (new features), major (breaking changes)\n" | ||
| "2. One short, clear bullet point for NEWS.md describing what changed" | ||
| " (start with a verb, no period at end)\n\n" | ||
| 'Respond ONLY with valid JSON, no other text:\n' | ||
| '{"bump_type": "patch|minor|major", "entry": "short description"}\n\n' | ||
| "Git diff:\n" + diff[:5000] | ||
| ) | ||
|
|
||
| payload = json.dumps({ | ||
| "model": "claude-haiku-4-5-20251001", | ||
| "max_tokens": 256, | ||
| "messages": [{"role": "user", "content": prompt}] | ||
| }).encode() | ||
|
|
||
| req = urllib.request.Request( | ||
| "https://api.anthropic.com/v1/messages", | ||
| data=payload, | ||
| headers={ | ||
| "x-api-key": os.environ["ANTHROPIC_API_KEY"], | ||
| "anthropic-version": "2023-06-01", | ||
| "content-type": "application/json" | ||
| } | ||
| ) | ||
|
|
||
| with urllib.request.urlopen(req) as resp: | ||
| result = json.loads(resp.read()) | ||
|
|
||
| parsed = json.loads(result["content"][0]["text"]) | ||
| bump_type = parsed["bump_type"] | ||
| entry = parsed["entry"] | ||
|
|
||
| with open(os.environ["GITHUB_OUTPUT"], "a") as f: | ||
| f.write(f"bump_type={bump_type}\n") | ||
| f.write(f"entry={entry}\n") | ||
|
|
||
| print(f"bump_type={bump_type}, entry={entry}") | ||
| PYEOF | ||
|
|
||
| - name: Bump version in DESCRIPTION and prepend NEWS.md entry | ||
| if: steps.check.outputs.skip == 'false' | ||
| run: | | ||
| PKG_NAME="${{ steps.check.outputs.pkg_name }}" | ||
| MAIN_VERSION="${{ steps.check.outputs.main_version }}" | ||
| BUMP_TYPE="${{ steps.claude.outputs.bump_type }}" | ||
| ENTRY="${{ steps.claude.outputs.entry }}" | ||
| DATE=$(date +%Y-%m-%d) | ||
|
|
||
| MAJOR=$(echo "$MAIN_VERSION" | cut -d. -f1) | ||
| MINOR=$(echo "$MAIN_VERSION" | cut -d. -f2) | ||
| PATCH=$(echo "$MAIN_VERSION" | cut -d. -f3) | ||
|
|
||
| if [ "$BUMP_TYPE" = "major" ]; then | ||
| NEW_VERSION="$((MAJOR + 1)).0.0" | ||
| elif [ "$BUMP_TYPE" = "minor" ]; then | ||
| NEW_VERSION="${MAJOR}.$((MINOR + 1)).0" | ||
| else | ||
| NEW_VERSION="${MAJOR}.${MINOR}.$((PATCH + 1))" | ||
| fi | ||
|
|
||
| sed -i "s/^Version: .*/Version: $NEW_VERSION/" DESCRIPTION | ||
| sed -i "s/^Date: .*/Date: $DATE/" DESCRIPTION | ||
|
|
||
| printf '## %s %s - %s\n* %s\n\n' "$PKG_NAME" "$NEW_VERSION" "$DATE" "$ENTRY" \ | ||
| | cat - NEWS.md > NEWS.md.tmp && mv NEWS.md.tmp NEWS.md | ||
|
|
||
| - name: Commit and push | ||
| if: steps.check.outputs.skip == 'false' | ||
| run: | | ||
| git config user.name "github-actions[bot]" | ||
| git config user.email "github-actions[bot]@users.noreply.github.com" | ||
| git add DESCRIPTION NEWS.md | ||
| git commit -m "chore: bump version and update NEWS.md" | ||
| git push |
This file contains hidden or 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,23 @@ | ||
| name: conventional-commit-check | ||
|
|
||
| on: | ||
| workflow_call: | ||
|
|
||
| jobs: | ||
| check-pr-title: | ||
| runs-on: ubuntu-24.04 | ||
| steps: | ||
| - name: Check PR title format | ||
| env: | ||
| PR_TITLE: ${{ github.event.pull_request.title }} | ||
| run: | | ||
| PATTERN='^(feat|fix|refactor|docs|test|chore|ci|perf|build|revert)(\([^)]+\))?: .+' | ||
| if echo "$PR_TITLE" | grep -qE "$PATTERN"; then | ||
| echo "PR title follows Conventional Commits: '$PR_TITLE'" | ||
| else | ||
| echo "::warning::PR title '$PR_TITLE' does not follow Conventional Commits format." | ||
| echo "::warning::Expected: <type>: <description> (e.g. 'feat: add new linter')" | ||
| echo "::warning::Valid types: feat, fix, refactor, docs, test, chore, ci, perf, build, revert" | ||
| echo "::warning::See the style guide vignette for details. This check is informational only." | ||
| fi | ||
| exit 0 | ||
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.