Skip to content
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

chore/MSSDK-2108: check if new version is greater than the previous one #458

Closed
wants to merge 3 commits into from
Closed
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
48 changes: 48 additions & 0 deletions .github/release-drafter.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name-template: '$RESOLVED_VERSION'
tag-template: '$RESOLVED_VERSION'
categories:
- title: 'Breaking changes'
labels:
- 'breaking'
- 'breaking-change'
- title: 'New features'
labels:
- 'feat'
- title: 'Fixes'
labels:
- 'fix'
- title: 'Improvements & Maintenance'
labels:
- 'chore'
- 'docs'
- 'refactor'
- 'style'
- 'test'
version-resolver:
major:
labels:
- 'breaking'
- 'breaking-change'
minor:
labels:
- 'feat'
patch:
labels:
- 'chore'
- 'docs'
- 'refactor'
- 'style'
- 'test'
default: patch

change-template: '- $TITLE ([#$NUMBER]($URL)) by @$AUTHOR'
sort-by: 'title'
template: |
## What's Changed

$CHANGES

**Full Changelog**: https://github.com/$OWNER/$REPOSITORY/compare/$PREVIOUS_TAG...v$RESOLVED_VERSION

exclude-labels:
- 'skip-changelog'
90 changes: 90 additions & 0 deletions .github/workflows/auto-release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
name: Auto Release

on:
push:
branches:
- main
workflow_dispatch:
inputs:
version:
description: 'Version to release (x.y.z)'
required: false

jobs:
release:
if: ${{ (github.event_name == 'workflow_dispatch') || (startsWith(github.event.head_commit.message, 'Merge pull request') && (contains(github.event.head_commit.message, 'release/') || contains(github.event.head_commit.message, 'hotfix/'))) }}
runs-on: ubuntu-latest
permissions:
contents: write
packages: write

steps:
- uses: actions/checkout@v3
with:
fetch-depth: 0

- name: Extract and validate version
id: extract_version
run: |
if [[ "${{ github.event_name }}" == "workflow_dispatch" && "${{ github.event.inputs.version }}" != "" ]]; then
VERSION="${{ github.event.inputs.version }}"
else
COMMIT_MSG="${{ github.event.head_commit.message }}"
if [[ $COMMIT_MSG =~ from\ [^/]*/([0-9]+\.[0-9]+\.[0-9]+) ]]; then
VERSION=${BASH_REMATCH[1]}
else
echo "Error: Invalid branch name format" && exit 1
fi
fi

# Get current version from git tags
PREV_VERSION=$(git describe --tags --abbrev=0 2>/dev/null || echo "0.0.0")

# Strict semver validation
if ! [[ $VERSION =~ ^(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\+([0-9a-zA-Z-]+(\.[0-9a-zA-Z-]+)*))?$ ]]; then
echo "Error: Version $VERSION does not follow semver" && exit 1
fi

# Compare versions
if ! npx semver $VERSION -g $PREV_VERSION; then
echo "Error: New version $VERSION must be greater than previous version $PREV_VERSION" && exit 1
fi

# Validate against package.json
CURRENT_VERSION=$(node -p "require('./package.json').version")
if ! [[ "$VERSION" > "$CURRENT_VERSION" ]]; then
echo "Error: New version $VERSION must be greater than current version $CURRENT_VERSION" && exit 1
fi

echo "version=$VERSION" >> $GITHUB_OUTPUT

- name: Create Git Tag
run: |
git tag -a ${{ steps.extract_version.outputs.version }} -m "Release ${{ steps.extract_version.outputs.version }}"
git push origin ${{ steps.extract_version.outputs.version }}

- name: Generate Release Draft
uses: release-drafter/release-drafter@v5
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
version: ${{ steps.extract_version.outputs.version }}
prerelease: false

- name: Publish Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
gh release edit ${{ steps.extract_version.outputs.version }} --draft=false

publish:
needs: release
uses: ./.github/workflows/call-publish.yml
permissions:
contents: read
packages: write
with:
access: public
registry: registry.npmjs.org
secrets:
TOKEN: ${{ secrets.NPM_AUTH_TOKEN }}
21 changes: 21 additions & 0 deletions .github/workflows/on-pull-request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,28 @@ on:
types: [opened, synchronize]

jobs:
validate-version:
if: startsWith(github.head_ref, 'release/')
runs-on: ubuntu-latest
steps:
- name: Validate release version format
run: |
if [[ ! "${{ github.head_ref }}" =~ ^release/[0-9]+\.[0-9]+\.[0-9]+$ ]]; then
echo "Invalid release branch format. Must be 'release/x.y.z' where x,y,z are numbers. Please follow the semantic versioning rules."
exit 1
fi
- name: Validate PR title matches branch name
run: |
if [ "${{ github.head_ref }}" != "${{ github.event.pull_request.title }}" ]; then
echo "PR title must match branch name exactly"
echo "Branch name: ${{ github.head_ref }}"
echo "PR title: ${{ github.event.pull_request.title }}"
exit 1
fi

publish:
needs: validate-version
if: ${{ !startsWith(github.head_ref, 'release/') || success() }}
uses: ./.github/workflows/call-publish.yml
permissions:
contents: read
Expand Down
17 changes: 0 additions & 17 deletions .github/workflows/on-release.yml

This file was deleted.

3 changes: 0 additions & 3 deletions .husky/commit-msg
Original file line number Diff line number Diff line change
@@ -1,5 +1,2 @@
#!/usr/bin/env sh
. "$(dirname -- "$0")/_/husky.sh"

commit_message=$(cat $1)
sh .husky/scripts/verify_commit_message "$commit_message"
6 changes: 3 additions & 3 deletions .husky/scripts/verify_branch_name
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

branch_name_regex='^(chore|docs|feat|fix|refactor|style|test)\/MSSDK-([[:digit:]]|external)+((-[[:alnum:]]+)+)'
branch_name_regex='^(chore|docs|feat|fix|refactor|style|test|breaking|breaking-change)\/MSSDK-([[:digit:]]|external)+((-[[:alnum:]]+)+)'
current_branch_name="$(git rev-parse --abbrev-ref HEAD)"
branch_template="<type>/<jira-ticket-id>-<brief-description>"
external_branch_template="<MSSDK-external>-<brief-description>"
Expand All @@ -11,7 +11,7 @@ invalid_branch_message="\nI'm sorry, Dave. I'm afraid I can't do that.
The branch name \033[1;31m$current_branch_name\033[0m does not adhere to the semantic naming convention. It should match this regular expression:
\t\033[1;34m$branch_name_regex\033[0m
In human terms that's:
\t\033[1;34m$branch_template\033[0m
\t\033[1;34m$branch_template\033[0m
eg. \033[1;32m$branch_example\033[0m

Oh, and if you're an external contributor, use the following template: \033[1;35m$external_branch_template\033[0m e.g. \033[1;32m$external_branch_example\033[0m
Expand All @@ -24,4 +24,4 @@ then
exit 1
fi

exit 0;
exit 0;
2 changes: 1 addition & 1 deletion .husky/scripts/verify_commit_message
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ jira_id_regex="MSSDK-([[:digit:]]|external)+"
jira_id=$(printf "$current_branch_name" | grep -Eo $jira_id_regex)

current_commit_name=$1
commit_name_regex="^(chore|docs|feat|fix|refactor|style|test)\/$jira_id:[[:space:]][[:alnum:]]+"
commit_name_regex="^(chore|docs|feat|fix|refactor|style|test|breaking|breaking-change)\/$jira_id:[[:space:]][[:alnum:]]+"
merge_name_regex="^Merge[[:space:]]branch[[:space:]].*"
commit_template="<type>/<jira-ticket-id>: <brief description>"
external_commit_template="<type>/<MSSDK-external>: <brief-description>"
Expand Down