Skip to content

Commit 5816a0d

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 fix: updated versions-preview workflow making it edit the existing release preview refactor: simplify version preview using semantic-release action fix: configure semantic-release to analyze PR branches fix: use semantic-release with proper branch configuration fix: create branch instead of renaming in detached HEAD debug: add logging to see what semantic-release sees fix: pass PR number as input to version-preview workflow fix: made changes in version-preivew for using sematic release.
1 parent 5b078d7 commit 5816a0d

File tree

3 files changed

+141
-0
lines changed

3 files changed

+141
-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: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
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: Analyze PR commits
25+
id: semantic
26+
run: |
27+
git fetch origin ${{ github.base_ref }}
28+
29+
COMMITS=$(git log origin/${{ github.base_ref }}..HEAD --pretty=format:"%s")
30+
31+
if echo "$COMMITS" | grep -qE "^[a-z]+(\(.+\))?!:|BREAKING CHANGE:"; then
32+
TYPE="major"
33+
elif echo "$COMMITS" | grep -qE "^feat(\(.+\))?:"; then
34+
TYPE="minor"
35+
elif echo "$COMMITS" | grep -qE "^fix(\(.+\))?:"; then
36+
TYPE="patch"
37+
else
38+
TYPE="none"
39+
fi
40+
41+
if [ "$TYPE" != "none" ]; then
42+
CURRENT=$(git tag --sort=-v:refname | head -1 | sed 's/^v//')
43+
IFS='.' read -r maj min pat <<< "$CURRENT"
44+
45+
[ "$TYPE" = "major" ] && maj=$((maj + 1)) && min=0 && pat=0
46+
[ "$TYPE" = "minor" ] && min=$((min + 1)) && pat=0
47+
[ "$TYPE" = "patch" ] && pat=$((pat + 1))
48+
49+
echo "new_release_published=true" >> $GITHUB_OUTPUT
50+
echo "new_release_version=$maj.$min.$pat" >> $GITHUB_OUTPUT
51+
echo "new_release_type=$TYPE" >> $GITHUB_OUTPUT
52+
echo "new_release_notes<<EOF" >> $GITHUB_OUTPUT
53+
echo "## Changes in this PR" >> $GITHUB_OUTPUT
54+
echo "$COMMITS" | sed 's/^/- /' >> $GITHUB_OUTPUT
55+
echo "EOF" >> $GITHUB_OUTPUT
56+
else
57+
echo "new_release_published=false" >> $GITHUB_OUTPUT
58+
fi
59+
60+
- name: Comment PR
61+
if: always()
62+
uses: marocchino/sticky-pull-request-comment@v2
63+
with:
64+
header: release-preview
65+
message: |
66+
## Release Preview
67+
68+
${{ steps.semantic.outputs.new_release_published == 'true' && format('**Release Type:** `{0}`
69+
**Next Version:** `v{1}`
70+
71+
### Release Notes
72+
{2}
73+
74+
---
75+
*This shows what release will be created when this PR is merged.*', steps.semantic.outputs.new_release_type, steps.semantic.outputs.new_release_version, steps.semantic.outputs.new_release_notes) || 'No new release will be created from this PR.
76+
77+
This PR does not contain conventional commits that trigger a release.' }}

0 commit comments

Comments
 (0)