-
Notifications
You must be signed in to change notification settings - Fork 9
172 lines (143 loc) · 5.76 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
160
161
162
163
164
165
166
167
168
169
170
171
172
name: 'Release'
on:
workflow_dispatch:
inputs:
future_release:
description: 'Tag for the future release (d.d.d)'
required: true
permissions:
contents: write
env:
release_yml_branch: "release-push-protected-linda"
src_branch: "source-protected-branch"
dst_branch: "destination-protected-branch"
jobs:
validate_arguments:
name: 'Validate arguments'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Validate source branch
run: |
if [ "${GITHUB_REF#refs/heads/}" != "${release_yml_branch}" ]; then
echo "Invalid branch. This workflow can only be ran on ${src_branch} branch. Got ${GITHUB_REF#refs/heads/}."
exit 1
fi
- name: Validate release version value
run: |
if ! echo ${{ github.event.inputs.future_release }} | grep -E '^([0-9]{1,3}\.){2}[0-9]{1,3}$'; then
echo "Future release should be in the format of x.y.z where x, y & z are all numbers"
exit 1
fi
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.src_branch }}
- name: Validate tag availability
run: |
! git rev-parse ${{ github.event.inputs.future_release }}
- name: Check source branch is "fast-forward" mergale
run: |
git merge-base --is-ancestor origin/${dst_branch} ${src_branch}
update_versions:
name: 'Update versions in examples and READMEs'
needs: validate_arguments
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout code
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.src_branch }}
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
- name: Setup Terraform
uses: hashicorp/setup-terraform@v2
with:
terraform_wrapper: false
terraform_version: ~1.6.0
- name: Format version for zip file name
run: |
version="${{ github.event.inputs.future_release }}"
formatted_version=${version//./_}
echo "FORMATTED_VERSION=$formatted_version" >> $GITHUB_OUTPUT
id: format-version
- name: Update modules' versions in examples
run: |
find ./examples/ -type f -exec sed -i 's;.*latest release tag.*;version="'${{ github.event.inputs.future_release }}'" # latest release tag;' {} \;
- name: Update READMEs
run: |
echo "Formatted version: ${{ steps.format-version.outputs.FORMATTED_VERSION }}"
find . -type f -name 'README.md' -exec sed -E -i 's;github.com/imperva/dsfkit/tree/([0-9]*\.){2}[0-9]*;github.com/imperva/dsfkit/tree/'${{ github.event.inputs.future_release }}';g' {} \;
find . -type f -name 'README.md' -exec sed -E -i 's;github.com/imperva/dsfkit/raw/([0-9]*\.){2}[0-9]*;github.com/imperva/dsfkit/raw/'${{ github.event.inputs.future_release }}';g' {} \;
find . -type f -name 'README.md' -exec sed -E -i '/\/examples\// s;([0-9]+_){2}[0-9]+\.zip;${{ steps.format-version.outputs.FORMATTED_VERSION }}\.zip;g' {} \;
- name: Update installer machine link
run: |
sed -E -i 's;github.com/imperva/dsfkit/blob/([0-9]*\.){2}[0-9]*/installer_machine;github.com/imperva/dsfkit/blob/'${{ github.event.inputs.future_release }}'/installer_machine;g' ./README.md
- name: Run terraform linter
run: |
terraform fmt -recursive
- name: Zip per examples, remove old version zip
run: |
for d in $(find ./examples -type d -links 2); do
_d=$(dirname ${d})
_b=$(basename ${d})
pushd $_d
rm ${_b}/*.zip
mv ${_b} ${_b}_${{ steps.format-version.outputs.FORMATTED_VERSION }}
zip -FSr ${_b}_${{ steps.format-version.outputs.FORMATTED_VERSION }}/${_b}_${{ steps.format-version.outputs.FORMATTED_VERSION }}.zip ${_b}_${{ steps.format-version.outputs.FORMATTED_VERSION }}
mv ${_b}_${{ steps.format-version.outputs.FORMATTED_VERSION }} ${_b}
popd
done
- name: Zip Sonar python upgrader, remove old version zip
run: |
rm modules/sonar_python_upgrader_*.zip
pushd modules/aws/sonar-upgrader
mv python_upgrader sonar_python_upgrader_${{ steps.format-version.outputs.FORMATTED_VERSION }}
zip -FSr ../../sonar_python_upgrader_${{ steps.format-version.outputs.FORMATTED_VERSION }}.zip sonar_python_upgrader_${{ steps.format-version.outputs.FORMATTED_VERSION }}
mv sonar_python_upgrader_${{ steps.format-version.outputs.FORMATTED_VERSION }} python_upgrader
popd
- name: Commit changes to git repo
uses: stefanzweifel/git-auto-commit-action@v4
with:
commit_message: Automatic commit before release [release=${{ github.event.inputs.future_release }}] | [skip actions]
merge:
name: 'Merge'
needs: update_versions
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.dst_branch }}
token: ${{ secrets.PUSH_TO_PROTECTED_BRANCH }}
- name: Merge
run: |
git merge origin/${src_branch} --ff-only
git push
tag_branch:
needs: merge
name: 'Tag release'
runs-on: ubuntu-latest
defaults:
run:
shell: bash
steps:
- name: Checkout
uses: actions/checkout@v3
with:
fetch-depth: 0
ref: ${{ env.dst_branch }}
- name: tag
run: |
git tag ${{ github.event.inputs.future_release }} ${{ env.dst_branch }}
git push origin ${{ github.event.inputs.future_release }}