-
Notifications
You must be signed in to change notification settings - Fork 0
132 lines (121 loc) · 5.85 KB
/
branching.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
name: Check Branch Name and Verify JIRA ID on JIRA Board
on:
pull_request:
types: [opened, edited, synchronize, reopened, closed]
jobs:
run-script:
permissions: write-all
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
with:
fetch-depth: 0
- name: Extract base branch name
shell: bash
run: echo "branch=${GITHUB_BASE_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: base_branch
- name: Base branch
run: |
echo ${{ steps.base_branch.outputs.branch }}
- name: Extract source branch name
shell: bash
run: echo "branch=${GITHUB_HEAD_REF:-${GITHUB_REF#refs/heads/}}" >> $GITHUB_OUTPUT
id: extract_branch
- uses: winterjung/split@v2
id: split
with:
msg: ${{ steps.extract_branch.outputs.branch }}
separator: '-'
maxsplit: 1
- name: Action PR title
if: ${{ (steps.split.outputs._0 == 'feature') || (steps.split.outputs._0 == 'hotfix') }}
uses: deepakputhraya/action-pr-title@master
with:
regex: '\w+\-\w+\-\d+' # Regex the title should match.
allowed_prefixes: '' # title should start with the given prefix
disallowed_prefixes: '' # title should not start with the given prefix
prefix_case_sensitive: true # title prefix are case insensitive
min_length: 5 # Min length of the title
max_length: 200 # Max length of the title
github_token: ${{ github.token }} # Default: ${{ github.token }}
- name: Branch matcher
if: github.event.pull_request.merged != true
run: |
if [ "${{ steps.base_branch.outputs.branch }}" == "${{ github.event.repository.default_branch }}" ]
then
if [ "${{ steps.split.outputs._0 }}" == 'release' ] || [ "${{ steps.split.outputs._0 }}" == 'hotfix' ]
then
echo "This pull request targets the default branch branching strategy."
else
echo "Please check your default branch branching strategy again!"
exit 1
fi
elif [[ "${{ steps.base_branch.outputs.branch }}" == release ]]
then
if [ ${{ steps.split.outputs._0 }} == 'feature' ] || [ ${{ steps.split.outputs._0 }} == "${{ github.event.repository.default_branch }}" ]
then
echo "This pull request targets the Release branching strategy."
else
echo "Please check your Release branch branching strategy again!"
exit 1
fi
else
echo "NO conditions matched please check again!!"
exit 1
fi
- name: Verify JIRA ID on JIRA Board
if: ${{ (steps.split.outputs._0 == 'feature') || (steps.split.outputs._0 == 'hotfix') }}
id: verify-jira-id
run: |
jira_id="${{ steps.split.outputs._1 }}"
jira_url="https://bharatpe.atlassian.net/rest/api/2/issue/$jira_id"
# Replace 'your-jira-username' and 'your-jira-api-token' with your Jira credentials
curl -u ${{ secrets.JIRA_USERNAME }}:${{ secrets.JIRA_TOKEN }} -X GET -H "Content-Type: application/json" $jira_url | grep -q 'id' && echo "JIRA ID $jira_id exists on the JIRA board" || (echo "JIRA ID $jira_id does not exist on the JIRA board" && exit 1)
- name: Add tag in default branch
if: ${{ steps.base_branch.outputs.branch == github.event.repository.default_branch && github.event.pull_request.merged == true }}
run: |
echo "Tagging The following Repo"
# Fetch latest semantic versioning tag
latest_semantic_tag=$(curl -s -H "Authorization: token ${{ secrets.github_token }}" "https://api.github.com/repos/bharatpe/${{ github.event.repository.name }}/tags" | jq -r '.[].name | select(test("^v[0-9]+\\.[0-9]+\\.[0-9]+$"))' | sort -V | tail -1)
# If no semantic versioning tags are found, fallback to non-semantic versioning tags
if [ -z "$latest_semantic_tag" ]; then
latest_non_semantic_tag=$(curl -s -H "Authorization: token ${{ secrets.github_token }}" "https://api.github.com/repos/bharatpe/${{ github.event.repository.name }}/tags" | jq -r '.[].name | select(test("^v[0-9]+$"))' | sort -V | tail -1)
latest_tag=$latest_non_semantic_tag
else
latest_tag=$latest_semantic_tag
fi
current_version="$latest_tag"
echo "Current version: $current_version"
IFS='.' read -r -a version_parts <<< "$current_version"
commit_messages=$(git log -n 3)
commit_messagesTrim=$(echo "$commit_messages" | head -c 500)
git config --global user.email "[email protected]"
git config --global user.name "deployerbharatpe"
pattern="^v[0-9]+\.[0-9]+\.[0-9]+$"
if [ -z "$current_version" ] || ! [[ "$current_version" =~ $pattern ]]; then
echo "This Repo Has Not Been Tagged Yet Starting Tagging The Following Repo"
git tag -a v0.1.0 -m "$commit_messagesTrim"
git push origin v0.1.0
else
x=${version_parts[0]}
y=${version_parts[1]}
z=${version_parts[2]}
echo "$x"
echo "$y"
echo "$z"
if [[ "${{ steps.split.outputs._0 }}" == 'hotfix' ]]; then
z=$((z+1))
elif [ "$y" -lt 9 ]; then
y=$((y+1))
z=0
else
x=$((x+1))
y=0
fi
# Create the new tag
new_version="$x.$y.$z"
echo "$new_version"
echo "This Repo is already Tagging, Old_Tag : $current_tag Incrementing it to New_Tag : $new_version"
git tag -a $new_version -m "$commit_messagesTrim"
git push origin $new_version
fi