Skip to content

feat: add changelog action and conventional commits #1471

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
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
79 changes: 79 additions & 0 deletions .github/workflows/changelog.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
name: Generate Changelog

on:
push:
branches: [main]
pull_request:
types: [closed]
branches: [main]

jobs:
generate-changelog:
if: github.event.pull_request.merged == true || github.event_name == 'push'
runs-on: ubuntu-latest
steps:
- name: Checkout Repo
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Pull
run: git pull

- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: 20

- name: Install Dependencies
run: npm install

- name: Set Git identity
run: |
git config user.name "julia-rabello"
git config user.email "[email protected]"


- name: Find next available version tag and bump if needed
id: bump_tag
run: |
BASE_VERSION=$(npx standard-version --dry-run | grep -Eo 'v[0-9]+\.[0-9]+\.[0-9]+' | head -1)
if [ -z "$BASE_VERSION" ]; then
echo "Could not determine base version. Exiting."
exit 1
fi
VERSION=$BASE_VERSION
MAJOR=$(echo $VERSION | cut -d. -f1 | tr -d 'v')
MINOR=$(echo $VERSION | cut -d. -f2)
PATCH=$(echo $VERSION | cut -d. -f3)
while git ls-remote --tags origin | grep -q "refs/tags/$VERSION"; do
PATCH=$((PATCH + 1))
VERSION="v${MAJOR}.${MINOR}.${PATCH}"
done
echo "Using version: $VERSION"
echo "RELEASE_VERSION=$VERSION" >> $GITHUB_ENV

- name: Generate Changelog
run: |
npx standard-version --release-as $RELEASE_VERSION

- name: Get created tag name
id: get_tag
run: |
TAG=$(git describe --tags --abbrev=0)
echo "TAG=$TAG" >> $GITHUB_ENV

- name: Push Changes
run: |
git push --force --follow-tags origin main

- name: Cleanup tag on failure
if: failure()
run: |
if [ -n "$TAG" ]; then
echo "Deleting tag $TAG locally and remotely..."
git tag -d "$TAG" || true
git push --delete origin "$TAG" || true
else
echo "No tag to clean up."
fi
2 changes: 1 addition & 1 deletion .github/workflows/portman.yml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ jobs:
if: ${{ steps.get-changed-files.outputs.any_changed == 'true' }}
run: |
git add PostmanCollections/*
git commit -m "Update generated files by portman"
git commit -m "chore: update postman files"
git pull --rebase origin "${{ github.head_ref }}"

- name: Push changes
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
node_modules/
43 changes: 43 additions & 0 deletions .versionrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
"skip": {
"bump": false,
"commit": false,
"tag": false
},
"types": [
{
"type": "new",
"section": "✨ New APIs, endpoints, or parameters"
},
{
"type": "update",
"section": "📝 Updates"
},
{
"type": "fix",
"section": "🔧 Fixes and improvements"
},
{
"type": "remove",
"section": "🗑️ Removed content"
},
{
"type": "docs",
"section": "📄 Repository documentation"
},
{
"type": "chore",
"section": "🔨 Chores",
"hidden": true
},
{
"type": "test",
"section": "🧪 Tests",
"hidden": true
},
{
"type": "feat",
"section": "⚙️ Repository features"
}
]
}
49 changes: 49 additions & 0 deletions commitlint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
module.exports = {
extends: ['@commitlint/config-conventional'],
plugins: ['commitlint-plugin-function-rules'],
rules: {
'type-enum': [
2,
'always',
['new', 'fix', 'update', 'remove', 'docs', 'feat', 'test', 'chore']
],
'scope-case': [2, 'always', 'kebab-case'],
'scope-empty': [
2,
'never',
['new'] // "new" requires scope
],
'scope-empty': [
0,
'always',
['fix'] // "fix" and "media" allow optional scopes
],
'function-rules/scope-enum': [
2,
'always',
(parsed) => {
const allowedScopes = {
new: ['api', 'endpoint', 'parameter'],
fix: ['typo', 'broken-link', 'markdown']
};

const { type, scope } = parsed;

// Only validate scopes for "new" and "fix"
if (!allowedScopes[type]) return [true];

// Validate "new" scopes
if (type === 'new' && !allowedScopes.new.includes(scope)) {
return [false, `new() scope must be one of: ${allowedScopes.new.join(', ')}`];
}

// Validate "fix" scopes (if used)
if (type === 'fix' && scope && !allowedScopes.fix.includes(scope)) {
return [false, `fix() scope must be one of: ${allowedScopes.fix.join(', ')}`];
}

return [true];
}
]
}
};
Loading
Loading