generated from SAP/repository-template
-
Notifications
You must be signed in to change notification settings - Fork 6
196 lines (168 loc) · 7.94 KB
/
prepare-release.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
193
194
195
196
name: "Prepare Release"
on:
workflow_dispatch:
inputs:
branch:
description: "The Branch to Release From"
required: false
default: "main"
release-version:
description: "The Version to Release"
required: false
env:
MVN_MULTI_THREADED_ARGS: --batch-mode --no-transfer-progress --fail-at-end --show-version --threads 1C
JAVA_VERSION: 17
jobs:
bump-version:
name: "Bump Version"
outputs:
current-version: ${{ steps.determine-versions.outputs.CURRENT_SNAPSHOT }}
release-version: ${{ steps.determine-versions.outputs.RELEASE_VERSION }}
new-version: ${{ steps.determine-versions.outputs.NEW_SNAPSHOT }}
release-branch: ${{ steps.prepare-release.outputs.BRANCH_NAME }}
release-commit: ${{ steps.prepare-release.outputs.RELEASE_COMMIT_ID }}
release-tag: ${{ steps.prepare-release.outputs.TAG_NAME }}
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Determine Versions"
id: determine-versions
run: python .pipeline/scripts/get-release-versions.py
env:
INPUT_VERSION: ${{ github.event.inputs.release-version }}
- run: "echo Release Version: ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
- run: "echo Current Version: ${{ steps.determine-versions.outputs.CURRENT_SNAPSHOT }}"
- run: "echo New Version: ${{ steps.determine-versions.outputs.NEW_SNAPSHOT }}"
- name: "Set Release Version to ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
id: prepare-release
run: |
# NOTE: If you change this pattern here, also adjust perform_release.yml:
BRANCH_NAME=RELEASE-${{ steps.determine-versions.outputs.RELEASE_VERSION }}
echo "BRANCH_NAME=$BRANCH_NAME" >> $GITHUB_OUTPUT
git switch --create $BRANCH_NAME
python .pipeline/scripts/set-release-versions.py --version ${{ steps.determine-versions.outputs.RELEASE_VERSION }}
git add .
git commit -m "Update to version ${{ steps.determine-versions.outputs.RELEASE_VERSION }}"
# We need to get the commit id, and push the branch so the release tag will point at the right commit afterwards
RELEASE_COMMIT_ID=$(git log -1 --pretty=format:"%H")
echo "RELEASE_COMMIT_ID=$RELEASE_COMMIT_ID" >> $GITHUB_OUTPUT
TAG_NAME=rel/${{ steps.determine-versions.outputs.RELEASE_VERSION }}
git tag $TAG_NAME $RELEASE_COMMIT_ID
echo "TAG_NAME=$TAG_NAME" >> $GITHUB_OUTPUT
git push origin $BRANCH_NAME
git push origin $TAG_NAME
create-release:
name: "Create GitHub Release"
needs: [ bump-version ]
outputs:
release-name: ${{ steps.create-release.outputs.RELEASE_NAME }}
release-url: ${{ steps.create-release.outputs.RELEASE_URL }}
permissions:
contents: write # needed to create a new release
actions: read # needed to download the artifacts from the CI workflow
runs-on: ubuntu-latest
steps:
- name: "Checkout repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.release-branch }}
- name: "Setup java"
uses: actions/setup-java@v4
with:
distribution: "temurin"
java-version: ${{ env.JAVA_VERSION }}
cache: 'maven'
- name: "Build SDK"
run: |
MVN_ARGS="${{ env.MVN_MULTI_THREADED_ARGS }} clean install -DskipTests"
mvn $MVN_ARGS
- name: "Create Release"
id: create-release
run: |
# Create a tarball of the whole repository into release-artifacts.tar.gz
tar --exclude=./release-artifacts.tar.gz -czf release-artifacts.tar.gz *
RELEASE_NAME="rel/${{ needs.bump-version.outputs.release-version }}"
echo "RELEASE_NAME=$RELEASE_NAME" >> $GITHUB_OUTPUT
RELEASE_URL=$(gh release create "$RELEASE_NAME" \
--target ${{ needs.bump-version.outputs.release-commit }} \
--title "Release ${{ needs.bump-version.outputs.release-version }}" \
--draft --generate-notes \
release-artifacts.tar.gz)
echo "RELEASE_URL=$RELEASE_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
create-code-pr:
name: "Create Code PR"
needs: [ bump-version, create-release ]
outputs:
pr-url: ${{ steps.create-code-pr.outputs.PR_URL }}
runs-on: ubuntu-latest
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ needs.bump-version.outputs.release-branch }}
token: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }} # this is needed so that the same token is used when pushing our changes later. Otherwise, our on: push workflows (i.e. our continuous integration) won't be triggered.
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Set New Version"
run: |
python .pipeline/scripts/set-release-versions.py --version ${{ needs.bump-version.outputs.new-version }}
git add .
git commit -m "Update to version ${{ needs.bump-version.outputs.new-version }}"
git push
- name: "Create Code PR"
run: |
COMMIT_URL=${{ github.event.repository.html_url }}/commit/${{ needs.bump-version.outputs.release-commit }}
PR_URL=$(gh pr create --title "Release ${{ needs.bump-version.outputs.release-version }}" --body "## TODOs
- [ ] Review the changes in [the release commit]($COMMIT_URL)
- [ ] Update the Release notes
- [ ] Review the [Draft Release](${{ needs.create-release.outputs.release-url }})
- [ ] Review **and approve** this PR
- [ ] Trigger the [Perform Release Workflow](${{ github.event.repository.html_url }}/actions/workflows/perform-release.yml)
- [ ] Once the `Perform Release` workflow is through, head over to the [Central Sonatype](https://central.sonatype.com/publishing/deployments) and log in with the credentials in the Team Password Safe. There should be a published release.")
echo "PR_URL=$PR_URL" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
handle-failure:
runs-on: ubuntu-latest
needs: [ bump-version, create-release, create-code-pr ]
permissions:
contents: write # needed to delete the GitHub release
if: ${{ failure() }}
steps:
- name: "Checkout Repository"
uses: actions/checkout@v4
with:
ref: ${{ github.event.inputs.branch }}
- name: "Prepare git"
run: |
git config --global user.email "[email protected]"
git config --global user.name "SAP Cloud SDK Bot"
- name: "Delete Release"
if: ${{ needs.create-release.outputs.release-url != '' }}
run: gh release delete --repo "${{ github.repository }}" ${{ needs.create-release.outputs.release-name }} --yes
env:
GH_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true
- name: "Delete Release Branch"
if: ${{ needs.bump-version.outputs.release-branch != '' }}
run: git push --delete origin ${{ needs.bump-version.outputs.release-branch }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true
- name: "Delete Release Tag"
if: ${{ needs.bump-version.outputs.release-tag != '' }}
run: git push --delete origin ${{ needs.bump-version.outputs.release-tag }}
env:
GITHUB_TOKEN: ${{ secrets.BOT_SDK_JS_FOR_DOCS_REPO_PR }}
continue-on-error: true