Compare commits

...

3 Commits

Author SHA1 Message Date
Ruben Talstra
f94aba4831 feat(ci): add automated release workflow
- Added GitHub Actions workflow `Create Release PR` to automate the creation of release pull requests.
  - Retrieves the last version from `package.json`.
  - Creates a new release branch and pull request with the relevant metadata.
  - Assigns a reviewer and labels the PR as a release.

- Added GitHub Actions workflow `Tag and Release` to automate tagging and releasing.
  - Extracts the last version from `package.json`.
  - Generates a changelog by retrieving merged PRs and categorizing changes.
  - Creates a version tag and pushes it to the repository.
  - Creates a GitHub Release with an auto-generated changelog.

This improves the CI/CD pipeline by streamlining the release process and ensuring structured versioning.
2025-02-10 20:32:21 +01:00
Ruben Talstra
661c6cc280 chore(ci): Improve version bump logic and remove redundant steps
- Now correctly determines the base version for version bumping:
  - Uses the version from an existing version bump PR if available.
  - Falls back to `package.json` version if no existing PR is found.
- Ensures that the version is bumped based on the labels of the newly merged PR.
- Closes an existing version bump PR before creating a new one to prevent duplicates.
- Removed the redundant branch creation step as `create-pull-request@v7` fully manages it.
- Ensures that every new version bump PR correctly increments beyond the last one.

This improves automation reliability and prevents version conflicts. 🚀
2025-02-10 19:34:30 +01:00
Ruben Talstra
0146800b66 started with implementing forced Semantic Versioning for the git repo.
issue: too long on the same version causes confusion.
2025-02-10 17:37:12 +01:00
3 changed files with 264 additions and 0 deletions

41
.github/workflows/create-release-pr.yml vendored Normal file
View File

@@ -0,0 +1,41 @@
name: Create Release PR
on:
workflow_dispatch:
jobs:
create-release-pr:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get last version from package.json
id: version
run: |
LAST_VERSION=$(jq -r '.version' package.json)
echo "Last version: $LAST_VERSION"
echo "LAST_VERSION=$LAST_VERSION" >> $GITHUB_ENV
echo "last_version=$LAST_VERSION" >> $GITHUB_OUTPUT
- name: Create New Release Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
sign-commits: true
commit-message: "chore(release): prepare for v${{ steps.version.outputs.last_version }}"
base: release
branch: release/v${{ steps.version.outputs.last_version }}
reviewers: danny-avila
title: "✨ v${{ steps.version.outputs.last_version }}"
body: |
**Release Details**:
- 🚀 **Version**: v${{ steps.version.outputs.last_version }}
- 📌 **Branch**: `main` → `release`
- 🔄 **Merging this PR will finalize the release.**
labels: "🚀 release"

110
.github/workflows/main-version-bump.yml vendored Normal file
View File

@@ -0,0 +1,110 @@
name: Semantic Version Bump (via Labels)
on:
pull_request:
types:
- closed
jobs:
versioning:
if: github.event.pull_request.merged == true && github.base_ref == 'main'
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Install dependencies
run: npm install -g semver jq
- name: Get last version from package.json
id: version
run: |
LAST_VERSION=$(jq -r '.version' package.json)
echo "Last version: $LAST_VERSION"
echo "LAST_VERSION=$LAST_VERSION" >> $GITHUB_ENV
- name: Check if an existing version bump PR exists
id: check_existing_pr
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
EXISTING_PR=$(gh pr list --state open --json number,title --jq '.[] | select(.title | contains("chore(version)")) | {number: .number, title: .title}')
EXISTING_PR_NUMBER=$(echo "$EXISTING_PR" | jq -r '.number')
EXISTING_PR_VERSION=$(echo "$EXISTING_PR" | grep -oP '\d+\.\d+\.\d+' | head -n 1)
if [[ -n "$EXISTING_PR_NUMBER" ]]; then
echo "Closing existing PR #$EXISTING_PR_NUMBER"
gh pr close "$EXISTING_PR_NUMBER" --comment "🚀 Auto-closing this PR in favor of a new version bump."
echo "EXISTING_PR_NUMBER=$EXISTING_PR_NUMBER" >> $GITHUB_ENV
fi
if [[ -n "$EXISTING_PR_VERSION" ]]; then
echo "EXISTING_PR_VERSION=$EXISTING_PR_VERSION" >> $GITHUB_ENV
fi
- name: Determine new version based on PR labels
id: bump_version
env:
PR_LABELS: ${{ join(github.event.pull_request.labels.*.name, ' ') }}
BASE_VERSION: ${{ env.EXISTING_PR_VERSION || env.LAST_VERSION }}
run: |
echo "Labels on PR: $PR_LABELS"
echo "Base version: $BASE_VERSION"
MAJOR=false
MINOR=false
PATCH=false
if echo "$PR_LABELS" | grep -qi "💥 breaking change"; then
MAJOR=true
fi
if echo "$PR_LABELS" | grep -qi "✨ feat"; then
MINOR=true
fi
if echo "$PR_LABELS" | grep -qi "🔧 fix"; then
PATCH=true
fi
NEW_VERSION=$BASE_VERSION
if [ "$MAJOR" = true ]; then
NEW_VERSION=$(semver -i major $BASE_VERSION)
elif [ "$MINOR" = true ]; then
NEW_VERSION=$(semver -i minor $BASE_VERSION)
elif [ "$PATCH" = true ]; then
NEW_VERSION=$(semver -i patch $BASE_VERSION)
fi
echo "NEW_VERSION=$NEW_VERSION" >> $GITHUB_ENV
echo "Next version: $NEW_VERSION"
- name: Update package.json version
run: |
jq --arg version "$NEW_VERSION" '.version = $version' package.json > temp.json && mv temp.json package.json
- name: Install dependencies and update package-lock.json
run: |
npm install
npm ci
- name: Create New Pull Request
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
sign-commits: true
commit-message: "chore(version): bump version to ${{ env.NEW_VERSION }}"
base: main
branch: version-bump/${{ env.NEW_VERSION }}
reviewers: danny-avila
title: "chore(version): Bump version to ${{ env.NEW_VERSION }}"
body: |
**Description**:
- 🎯 **Objective**: Update `package.json` and `package-lock.json` with the latest version bump.
- 🔍 **Details**: This PR is automatically generated upon merging PRs with the correct versioning labels.
- ✅ **Status**: Ready for review.
labels: "📦 version update"

113
.github/workflows/tag-and-release.yml vendored Normal file
View File

@@ -0,0 +1,113 @@
name: Tag and Release
on:
push:
branches:
- release
jobs:
create-tag-release:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Get last version from package.json
id: version
run: |
# Extract the version using jq (make sure jq is installed)
LAST_VERSION=$(jq -r '.version' package.json)
echo "Last version: $LAST_VERSION"
echo "LAST_VERSION=$LAST_VERSION" >> $GITHUB_ENV
- name: Generate Changelog
id: changelog
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
# Get previous tag (if none exists, use a placeholder)
PREV_VERSION=$(git tag --sort=-v:refname | head -n 1)
if [ -z "$PREV_VERSION" ]; then
PREV_VERSION="Initial_Commit"
fi
# Start building the changelog file
{
echo "## What's Changed"
echo ""
echo "## [v${LAST_VERSION}](https://github.com/${{ github.repository }}/releases/tag/v${LAST_VERSION})"
echo ""
if [ "$PREV_VERSION" != "Initial_Commit" ]; then
echo "Updates since v${PREV_VERSION} include:"
echo "- https://github.com/${{ github.repository }}/compare/v${PREV_VERSION}...v${LAST_VERSION}"
else
echo "This is the first release."
fi
echo ""
echo "### ✨ New Features"
gh pr list --state merged --search "feat" --json title,number,url --jq \
'.[] | "* 🚀 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No new features."
echo ""
echo "### 🖼️ Style"
gh pr list --state merged --search "style" --json title,number,url --jq \
'.[] | "* 🎨 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No style updates."
echo ""
echo "### 👐 Accessibility"
gh pr list --state merged --search "a11y" --json title,number,url --jq \
'.[] | "* 👐 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No accessibility updates."
echo ""
echo "### 🌍 Internationalization"
gh pr list --state merged --search "i18n" --json title,number,url --jq \
'.[] | "* 🌏 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No internationalization updates."
echo ""
echo "### ⚙️ Other Changes"
gh pr list --state merged --search "chore OR refactor OR docs" --json title,number,url --jq \
'.[] | "* 📦 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No other changes."
echo ""
echo "### 🔧 Fixes"
gh pr list --state merged --search "fix" --json title,number,url --jq \
'.[] | "* 🔧 [\(.title) by @\(.url | split("/")[-2])](\(.url))"' || echo "* No fixes."
echo ""
echo "## New Contributors"
# Use jqs unique_by to get one PR per new author along with its URL
gh pr list --state merged --json author,url --jq \
'unique_by(.author.login)[] | "* @" + .author.login + " made their first contribution in " + .url' \
|| echo "* No new contributors."
echo ""
echo "**Full Changelog**: https://github.com/${{ github.repository }}/compare/v${PREV_VERSION}...v${LAST_VERSION}"
} > changelog.md
# Output the changelog for logging purposes
cat changelog.md
# Save the changelog as a multiline environment variable
echo "CHANGELOG<<EOF" >> $GITHUB_ENV
cat changelog.md >> $GITHUB_ENV
echo "EOF" >> $GITHUB_ENV
- name: Create Git Tag
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
git tag v${LAST_VERSION}
git push origin v${LAST_VERSION}
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release create v${LAST_VERSION} \
--title "Release v${LAST_VERSION}" \
--notes "$CHANGELOG"