Skip to content

Commit 6a2736a

Browse files
author
rahul-infra
committed
feat!: Updated pr title check and preview release type
Made changes in terraform workflow Updated github workflows. removed github token decleration in my new version preview feat!: breaking change to workflow BREAKING CHANGE: Updated release preview mechanism fix: use PR merge ref for version preview fix: changes versionpreview.yaml fix: Updated Preview.yaml file
1 parent 5b078d7 commit 6a2736a

File tree

3 files changed

+161
-0
lines changed

3 files changed

+161
-0
lines changed

.github/workflows/pr-title.yaml

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
name: 'Validate PR title'
2+
3+
on:
4+
workflow_call:
5+
6+
jobs:
7+
main:
8+
name: Validate PR title
9+
runs-on: ubuntu-latest
10+
steps:
11+
# Please look up the latest version from
12+
# https://github.com/amannn/action-semantic-pull-request/releases
13+
- uses: amannn/action-semantic-pull-request@v6.1.1
14+
env:
15+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
16+
with:
17+
# Configure which types are allowed.
18+
# Default: https://github.com/commitizen/conventional-commit-types
19+
types: |
20+
fix
21+
feat
22+
docs
23+
ci
24+
chore
25+
# Configure that a scope must always be provided.
26+
requireScope: false
27+
# Configure additional validation for the subject based on a regex.
28+
# This example ensures the subject starts with an uppercase character.
29+
subjectPattern: ^[A-Z].+$
30+
# If `subjectPattern` is configured, you can use this property to override
31+
# the default error message that is shown when the pattern doesn't match.
32+
# The variables `subject` and `title` can be used within the message.
33+
subjectPatternError: |
34+
The subject "{subject}" found in the pull request title "{title}"
35+
didn't match the configured pattern. Please ensure that the subject
36+
starts with an uppercase character.
37+
# For work-in-progress PRs you can typically use draft pull requests
38+
# from Github. However, private repositories on the free plan don't have
39+
# this option and therefore this action allows you to opt-in to using the
40+
# special "[WIP]" prefix to indicate this state. This will avoid the
41+
# validation of the PR title and the pull request checks remain pending.
42+
# Note that a second check will be reported if this is enabled.
43+
wip: true
44+
# When using "Squash and merge" on a PR with only one commit, GitHub
45+
# will suggest using that commit message instead of the PR title for the
46+
# merge commit, and it's easy to commit this by mistake. Enable this option
47+
# to also validate the commit message for one commit PRs.
48+
validateSingleCommit: false

.github/workflows/terraform.yaml

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@ on:
66
- main
77
- master
88
pull_request_target:
9+
branches:
10+
- main
11+
- master
912
types:
1013
- opened
1114
- edited
@@ -15,6 +18,19 @@ on:
1518
- main
1619
- master
1720
jobs:
21+
prTitlecheck:
22+
name: PR title check
23+
if: ${{ github.event_name == 'pull_request_target' }}
24+
uses: ./.github/workflows/pr-title.yaml
25+
26+
versionPreview:
27+
name: Version Preview
28+
if: ${{ github.event_name == 'pull_request' }}
29+
permissions:
30+
contents: read
31+
pull-requests: write
32+
uses: ./.github/workflows/version-preview.yaml
33+
1834
preCommitCheck:
1935
name: Terraform Checks
2036
uses: ./.github/workflows/terraform-checks.yaml
Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
name: 'Version Preview'
2+
3+
on:
4+
workflow_call:
5+
6+
defaults:
7+
run:
8+
shell: bash
9+
10+
permissions:
11+
contents: read
12+
pull-requests: write
13+
14+
jobs:
15+
preview:
16+
name: Preview Release
17+
runs-on: ubuntu-latest
18+
steps:
19+
- name: Checkout
20+
uses: actions/checkout@v4
21+
with:
22+
fetch-depth: 0
23+
24+
- name: Fetch base branch
25+
run: git fetch origin ${{ github.base_ref }}
26+
27+
- name: Analyze PR Commits
28+
id: analyze
29+
run: |
30+
# Get commits from this PR
31+
COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s")
32+
echo "Commits in this PR:"
33+
echo "$COMMITS"
34+
35+
# Determine release type
36+
if echo "$COMMITS" | grep -qE "^[a-z]+(\(.+\))?!:|BREAKING CHANGE:"; then
37+
TYPE="major"
38+
elif echo "$COMMITS" | grep -qE "^feat(\(.+\))?:"; then
39+
TYPE="minor"
40+
elif echo "$COMMITS" | grep -qE "^fix(\(.+\))?:"; then
41+
TYPE="patch"
42+
else
43+
TYPE="none"
44+
fi
45+
46+
echo "release_type=$TYPE" >> $GITHUB_OUTPUT
47+
echo "Release type: $TYPE"
48+
49+
# Calculate next version if releasing
50+
if [ "$TYPE" != "none" ]; then
51+
CURRENT=$(git tag --sort=-v:refname | head -1 | sed 's/^v//')
52+
IFS='.' read -r maj min pat <<< "$CURRENT"
53+
54+
[ "$TYPE" = "major" ] && maj=$((maj + 1)) && min=0 && pat=0
55+
[ "$TYPE" = "minor" ] && min=$((min + 1)) && pat=0
56+
[ "$TYPE" = "patch" ] && pat=$((pat + 1))
57+
58+
VERSION="$maj.$min.$pat"
59+
echo "next_version=$VERSION" >> $GITHUB_OUTPUT
60+
echo "will_release=true" >> $GITHUB_OUTPUT
61+
echo "Next version: v$VERSION"
62+
63+
# Generate notes
64+
{
65+
echo "release_notes<<EOF"
66+
echo "## Changes in this PR"
67+
echo ""
68+
echo "$COMMITS" | sed 's/^/- /'
69+
echo "EOF"
70+
} >> $GITHUB_OUTPUT
71+
else
72+
echo "will_release=false" >> $GITHUB_OUTPUT
73+
fi
74+
75+
- name: Comment PR
76+
uses: actions/github-script@v7
77+
with:
78+
script: |
79+
const willRelease = '${{ steps.analyze.outputs.will_release }}';
80+
let body = '';
81+
82+
if (willRelease === 'true') {
83+
const releaseType = '${{ steps.analyze.outputs.release_type }}';
84+
const version = '${{ steps.analyze.outputs.next_version }}';
85+
const notes = `${{ steps.analyze.outputs.release_notes }}`;
86+
87+
body = `## Release Preview\n\n**Release Type:** \`${releaseType}\`\n**Next Version:** \`v${version}\`\n\n### Release Notes\n${notes}\n\n---\n*This shows what release will be created when this PR is merged.*`;
88+
} else {
89+
body = '## Release Preview\n\nNo new release will be created from this PR.\n\nThis PR does not contain conventional commits that trigger a release.';
90+
}
91+
92+
github.rest.issues.createComment({
93+
issue_number: context.issue.number,
94+
owner: context.repo.owner,
95+
repo: context.repo.repo,
96+
body: body
97+
});

0 commit comments

Comments
 (0)