-
Notifications
You must be signed in to change notification settings - Fork 0
/
action.yaml
192 lines (173 loc) · 6.7 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
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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
name: Bump Version
description: Action to bump the version of a project
inputs:
pat:
description: PAT for accessing the application repo
required: true
increment:
description: The type of increment to make
required: true
default: patch
working-dir:
description: The working directory of the project
required: false
default: "."
helm:
description: The project uses Helm
required: false
default: "false"
node:
description: The project uses Node
required: false
default: "false"
python:
description: The project uses Python
required: false
default: "false"
go:
description: The project uses Go
required: false
default: "false"
go-lib:
description: The project is a Go library
required: false
default: "false"
java:
description: The project uses Java
required: false
default: "false"
dotnet:
description: The project uses Dot Net
required: false
default: "false"
runs:
using: composite
steps:
- name: Checkout
uses: actions/checkout@v2
with:
token: ${{ inputs.pat }}
- name: Check if app should be updated
run: |
if [ "${{ inputs.node }}" == 'true' ] || [ "${{ inputs.python }}" == 'true' ] || [ "${{ inputs.go }}" == 'true' ] || [ "${{ inputs.java }}" == 'true' ] || [ "${{ inputs.dotnet }}" == 'true' ]; then
echo "UPDATE_APP=true" >> $GITHUB_ENV
else
echo "UPDATE_APP=false" >> $GITHUB_ENV
fi
shell: bash
- name: Get current app version
if: ${{ env.UPDATE_APP == 'true' }}
run: |
echo "APP_VERSION=$(cat VERSION)" >> $GITHUB_ENV
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Get current chart version
if: ${{ inputs.helm == 'true' }}
run: |
echo "CHART_VERSION=$(cat ./charts/VERSION)" >> $GITHUB_ENV
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Install semver utility
run: |
npm i -g semver
shell: bash
- name: Increment App versions
if: ${{ env.UPDATE_APP == 'true' }}
run: |
echo "NEW_APP_VERSION=$(semver -i ${{ inputs.increment }} $APP_VERSION)" >> $GITHUB_ENV
shell: bash
- name: Increment Chart versions
if: ${{ inputs.helm == 'true' }}
run: |
echo "NEW_CHART_VERSION=$(semver -i ${{ inputs.increment }} $CHART_VERSION)" >> $GITHUB_ENV
shell: bash
- name: For a Go library, version should start with v
if: ${{ inputs.go == 'true' && inputs.go-lib == 'true' && !startsWith( env.NEW_APP_VERSION, 'v' ) }}
run: |
echo "NEW_APP_VERSION=v${{ env.NEW_APP_VERSION }}" >> $GITHUB_ENV
shell: bash
- name: Bump VERSION file
if: ${{ env.UPDATE_APP == 'true' }}
run: |
echo $NEW_APP_VERSION > VERSION
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Bump VERSION file in chart
if: ${{ inputs.helm == 'true' }}
run: |
echo $NEW_CHART_VERSION > ./charts/VERSION
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Bump version in helm chart
if: ${{ inputs.helm == 'true' }}
# We are using sed instead of yq as yq is not preserving empty lines. See https://github.com/mikefarah/yq/issues/515
run: |
if [ -f "./charts/Chart.yaml" ]; then
find ./charts -name "Chart.yaml" -exec sed -i -E "s/^version: [0-9\.]*/version: "$NEW_CHART_VERSION"/g" {} \;
fi
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Bump appVersion in helm chart
if: ${{ inputs.helm == 'true' && env.UPDATE_APP == 'true' }}
# We are using sed instead of yq as yq is not preserving empty lines. See https://github.com/mikefarah/yq/issues/515
run: |
if [ -f "./charts/Chart.yaml" ]; then
find ./charts -name "Chart.yaml" -exec sed -i -E "s/appVersion: [0-9\.]*/appVersion: "$NEW_APP_VERSION"/g" {} \;
fi
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Bump package.json and package-lock.json
if: ${{ inputs.node == 'true' }}
# We are using env.NEW_APP_VERSION instead of $NEW_APP_VERSION as yq does not easily substitute variables
run: |
yq -i -o=json -P '.version = "${{ env.NEW_APP_VERSION }}"' 'package.json'
if [ -f "./package-lock.json" ]; then
yq -i -o=json -P '.version = "${{ env.NEW_APP_VERSION }}" | .packages[""].version = "${{ env.NEW_APP_VERSION }}"' 'package-lock.json'
fi
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Check if app version in build.gradle is used from VERSION file
if: ${{ inputs.java == 'true' }}
run: |
if [ $(grep -E "version.*file\('VERSION'\).text.trim\(\)$" build.gradle) -eq 0 ]; then
find . -name "build.gradle" -exec sed -i -E "s/^version.*'/version = file('VERSION').text.trim()/g" {} \;
fi
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Bump AssemblyInfo.cs
if: ${{ inputs.dotnet == 'true' }}
run: |
find . -name "AssemblyInfo.cs" -exec sed -i "s/AssemblyVersion(\"[0-9\.]*\")/AssemblyVersion(\"${{ env.NEW_APP_VERSION }}.0\")/g" {} \;
find . -name "AssemblyInfo.cs" -exec sed -i "s/AssemblyFileVersion(\"[0-9\.]*\")/AssemblyFileVersion(\"${{ env.NEW_APP_VERSION }}.0\")/g" {} \;
working-directory: ${{ inputs.working-dir }}
shell: bash
# Create commit messages
- name: Commit message for only chart
if: ${{ inputs.helm == 'true' && env.UPDATE_APP == 'false' }}
run: |
echo "COMMIT_MESSAGE="feat: bump chart version to $NEW_CHART_VERSION"" >> $GITHUB_ENV
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Commit message for only app
if: ${{ inputs.helm == 'false' && env.UPDATE_APP == 'true' }}
run: |
echo "COMMIT_MESSAGE="feat: bump app version to $NEW_APP_VERSION"" >> $GITHUB_ENV
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Commit message for only chart
if: ${{ inputs.helm == 'true' && env.UPDATE_APP == 'true' }}
run: |
echo "COMMIT_MESSAGE="feat: bump chart version to $NEW_CHART_VERSION and app version to $NEW_APP_VERSION"" >> $GITHUB_ENV
working-directory: ${{ inputs.working-dir }}
shell: bash
- name: Commit Changes
env:
GIT_AUTHOR_NAME: Beez Innovation Labs
GIT_COMMITTER_NAME: Beez Innovation Labs
GIT_AUTHOR_EMAIL: [email protected]
GIT_COMMITTER_EMAIL: [email protected]
run: |
git add -A
git diff-index --quiet HEAD || git commit -m "$COMMIT_MESSAGE"
git push
shell: bash