generated from ikmdev/repo-seed
-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
111 lines (96 loc) · 3.9 KB
/
action.yaml
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
name: Git Shared Action Release Action
description: Utilized for creating releases of shared actions
# Inputs
inputs:
ikmdevops_pat:
description: "PAT TOKEN for IKMDevops User"
required: true
ikmdevops_email:
description: "Email For IKMDevops User"
default: 'devops@ikm.dev'
github_token:
description: "GitHub Token"
required: true
release_type:
description: "Release Type Inputed"
required: true
runs:
using: "composite"
steps:
- name: Checkout Repository
uses: actions/checkout@v4.2.2
with:
token: ${{inputs.ikmdevops_pat}}
fetch-depth: 0
- name: List Latest Release Tag
id: listLatestTag
shell: bash
run: |
git fetch --tags
echo "TAG=$(git describe --tags `git rev-list --tags --max-count=1`)" >> $GITHUB_OUTPUT
echo "TAG: " $TAG
- name: Get Latest Release tag
id: getLatestTag
if: always()
shell: bash
run: |
if [ $NO_TAGS_FAILURE == 'failure' ]; then
echo "LATEST_TAG=0.0.0" >> $GITHUB_OUTPUT
else
echo "LATEST_TAG=$(echo "$TAG" | sed "s/v//")" >> $GITHUB_OUTPUT
fi
env:
NO_TAGS_FAILURE: ${{steps.listLatestTag.outcome}}
TAG: ${{steps.listLatestTag.outputs.TAG}}
- name: Split Tag String
uses: xom9ikk/split@v1.1
id: splitTagString
with:
string: ${{steps.getLatestTag.outputs.LATEST_TAG}}
separator: .
limit: -1
- name: "[${{inputs.release_type}}] Increment Tag Version"
id: incrementedTagVersion
shell: bash
run: |
if [ $RELEASE_TYPE == 'Major' ]; then
echo "NEW_RELEASE_TAG=$(($MAJOR_STRING + 1)).0.0" >> $GITHUB_OUTPUT
elif [ $RELEASE_TYPE == 'Minor' ]; then
echo "NEW_RELEASE_TAG=${MAJOR_STRING}.$(($MINOR_STRING + 1)).0" >> $GITHUB_OUTPUT
else
echo "NEW_RELEASE_TAG=${MAJOR_STRING}.${MINOR_STRING}.$(($PATCH_STRING + 1))" >> $GITHUB_OUTPUT
fi
env:
RELEASE_TYPE: ${{inputs.release_type}}
MAJOR_STRING: ${{steps.splitTagString.outputs._0}}
MINOR_STRING: ${{steps.splitTagString.outputs._1}}
PATCH_STRING: ${{steps.splitTagString.outputs._2}}
- name: "[${{inputs.release_type}}] Create & Push New Tag -- ${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}"
shell: bash
run: |
git remote set-url origin https://git:${{inputs.ikmdevops_pat}}@github.com/${{github.repository}}.git
git pull -p
git config user.name "ikmdevops"
git config user.email devops@ikm.dev
git tag -a v$NEW_RELEASE_TAG -m"Release Version $NEW_RELEASE_TAG"
git push --tags origin
env:
NEW_RELEASE_TAG: ${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}
- name: "[${{inputs.release_type}}] Create Release -- ${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}"
shell: bash
run: |
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{inputs.github_token}}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/${{github.repository}}/releases \
-d '{"tag_name":"v${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}","name":"v${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}","body":"Release v${{steps.incrementedTagVersion.outputs.NEW_RELEASE_TAG}}","draft":false,"prerelease":false,"generate_release_notes":false}'
- name: Delete existing tag
shell: bash
if: inputs.release_type != 'Major'
run: |
git tag -d v${{steps.splitTagString.outputs._0}}.0.0
git push origin :refs/tags/v${{steps.splitTagString.outputs._0}}.0.0
git tag v${{steps.splitTagString.outputs._0}}.0.0
git push -f origin v${{steps.splitTagString.outputs._0}}.0.0