-
Notifications
You must be signed in to change notification settings - Fork 51
159 lines (154 loc) · 6.22 KB
/
release.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
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
# Copyright 2020 EPAM Systems
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
name: release
on:
push:
branches:
- master
paths-ignore:
- '.github/**'
- README.md
- CHANGELOG.md
env:
versionFileName: 'VERSION'
versionFragmentFileName: 'version_fragment'
changelogFileName: 'CHANGELOG.md'
jobs:
calculate-version:
runs-on: ubuntu-latest
outputs:
releaseVersion: ${{ steps.exposeVersion.outputs.releaseVersion }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Read version
id: readVersion
run: |
read -r version < ${{ env.versionFileName }}
echo "Snapshot version: $version";
version=$(echo $version | sed 's/-SNAPSHOT//');
echo $version;
echo "::set-output name=version::$version"
read -r versionFragment < ${{ env.versionFragmentFileName }}
echo $versionFragment
if [[ "$versionFragment" == "minor" ]]; then
versionFragment=feature
echo "Minor version will be used"
elif [[ "$versionFragment" == "major" ]]; then
echo "Major version will be used"
else
versionFragment=patch
echo "Patch version will be used"
fi
echo "::set-output name=versionFragment::$versionFragment"
- name: Bump release version if needed according to version fragment
if: steps.readVersion.outputs.versionFragment != 'patch'
id: bumpVersion
uses: christian-draeger/[email protected]
with:
current-version: ${{ steps.readVersion.outputs.version }}
version-fragment: ${{ steps.readVersion.outputs.versionFragment }}
- name: Expose release version
id: exposeVersion
run: |
versionFragment=${{ steps.readVersion.outputs.versionFragment }}
if [[ "$versionFragment" != "patch" ]]; then
echo "::set-output name=releaseVersion::${{ steps.bumpVersion.outputs.next-version }}"
else
echo "::set-output name=releaseVersion::${{ steps.readVersion.outputs.version }}"
fi
create-tag:
needs: calculate-version
runs-on: ubuntu-latest
outputs:
versionInfo: ${{ steps.readChangelogEntry.outputs.log_entry }}
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Setup NodeJS
uses: actions/setup-node@v3
with:
node-version: '12'
- name: Configure git
run: |
git config --global user.email "reportportal.io"
git config --global user.name "reportportal.io"
git remote set-url origin https://${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }}
- name: Update VERSION file
run: |
echo "${{ needs.calculate-version.outputs.releaseVersion }}" > ${{ env.versionFileName }}
git status
git add ${{ env.versionFileName }}
git commit -m "Update VERSION file with ${{ needs.calculate-version.outputs.releaseVersion }}"
- name: Create tag
run: |
git tag -a v${{ needs.calculate-version.outputs.releaseVersion }} -m ${{ needs.calculate-version.outputs.releaseVersion }}
npm version from-git
git push origin master
- name: Update version in changelog file
run: |
releaseDate=$(date +'%Y-%m-%d')
echo "Release date: $releaseDate"
versionInfo="## [${{ needs.calculate-version.outputs.releaseVersion }}] - $releaseDate"
sed -i '1s/^/\n'"$versionInfo"'\n/' ${{ env.changelogFileName }}
git status
git add ${{ env.changelogFileName }}
git commit -m "Mention ${{ needs.calculate-version.outputs.releaseVersion }} version in changelog file"
git push origin master
- name: Read changelog Entry
id: readChangelogEntry
uses: mindsers/[email protected]
with:
version: ${{ needs.calculate-version.outputs.releaseVersion }}
path: ./${{ env.changelogFileName }}
- name: Bump snapshot version
id: bumpSnapshotVersion
uses: christian-draeger/[email protected]
with:
current-version: ${{ needs.calculate-version.outputs.releaseVersion }}
version-fragment: 'bug'
- name: Update develop with snapshot version
run: |
git fetch
git checkout develop
git merge master -Xtheirs --allow-unrelated-histories
echo "${{ steps.bumpSnapshotVersion.outputs.next-version }}-SNAPSHOT" > ${{ env.versionFileName }}
echo "patch" > ${{ env.versionFragmentFileName }}
git status
git add ${{ env.versionFileName }}
git add ${{ env.versionFragmentFileName }}
git commit -m "${{ needs.calculate-version.outputs.releaseVersion }} -> ${{ steps.bumpSnapshotVersion.outputs.next-version }}-SNAPSHOT"
git push origin develop
create-release:
needs: [calculate-version, create-tag]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3
- name: Create Release
id: createRelease
uses: actions/create-release@v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ needs.calculate-version.outputs.releaseVersion }}
release_name: Release v${{ needs.calculate-version.outputs.releaseVersion }}
body: ${{ needs.create-tag.outputs.versionInfo }}
draft: false
prerelease: false
- name: Trigger the publish workflow
if: success()
uses: peter-evans/repository-dispatch@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
event-type: version-released