Skip to content

Commit d24fc12

Browse files
committed
Automating release
Signed-off-by: Artur Souza <[email protected]>
1 parent 92ccca5 commit d24fc12

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed

.github/scripts/create-release.sh

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
#!/usr/bin/env bash
2+
#
3+
# Copyright 2024 The Dapr Authors
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
# Unless required by applicable law or agreed to in writing, software
9+
# distributed under the License is distributed on an "AS IS" BASIS,
10+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
# See the License for the specific language governing permissions and
12+
# limitations under the License.
13+
14+
set -ue
15+
16+
script_dir=$(readlink -f $(dirname $0))
17+
current_time=$(date +"%Y-%m-%d_%H-%M-%S")
18+
19+
# Thanks to https://ihateregex.io/expr/semver/
20+
SEMVER_REGEX='^(0|[1-9]\d*)\.(0|[1-9]\d*)\.(0|[1-9]\d*)(?:-((?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+([0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$'
21+
22+
REL_VERSION=`echo $1 | sed -r 's/^[vV]?([0-9].+)$/\1/'`
23+
24+
if [ `echo $REL_VERSION | pcre2grep "$SEMVER_REGEX"` ]; then
25+
echo "$REL_VERSION is a valid semantic version."
26+
else
27+
echo "$REL_VERSION is not a valid semantic version."
28+
exit 1
29+
fi
30+
31+
MAJOR_MINOR_VERSION=`echo ${REL_VERSION}- | cut -d- -f1 | cut -d. -f1,2`
32+
MAJOR_MINOR_PATCH_VERSION=`echo ${REL_VERSION}- | cut -d- -f1 | cut -d. -f1,2,3`
33+
VARIANT=`echo ${REL_VERSION}- | cut -d- -f2`
34+
35+
if [ "$VARIANT" = "SNAPSHOT" ]; then
36+
echo "SNAPSHOT release detected, updating version in master branch to $REL_VERSION ..."
37+
if [ "$REL_VERSION" != "${MAJOR_MINOR_PATCH_VERSION}-SNAPSHOT" ]; then
38+
echo "Invalid snapshot version: $REL_VERSION"
39+
exit 3
40+
fi
41+
branch_name="automation/update_to_next_${current_time}"
42+
git checkout -b $branch_name
43+
${script_dir}/update_sdk_version.sh $REL_VERSION
44+
git clean -xdf
45+
git commit -s -m "Update master version to ${$REL_VERSION}" -a
46+
git push origin $branch_name
47+
gh pr create --repo dapr/java-sdk \
48+
--base master \
49+
--title "Update master version to ${$REL_VERSION}" \
50+
--body "Update master version to ${$REL_VERSION}"
51+
echo "Done."
52+
exit 0
53+
elif [ "$VARIANT" = "rc" ]; then
54+
echo "Release-candidate version detected: $REL_VERSION"
55+
RC_COUNT=`echo ${REL_VERSION}- | cut -d- -f3`
56+
if ! ((10#${RC_COUNT} >= 0)) 2>/dev/null || [ "$RC_COUNT" == "" ]; then
57+
echo "Invalid release-candidate count: $RC_COUNT"
58+
exit 3
59+
fi
60+
if [ "$REL_VERSION" != "${MAJOR_MINOR_PATCH_VERSION}-rc-${RC_COUNT}" ]; then
61+
echo "Invalid release-candidate version: $REL_VERSION"
62+
exit 3
63+
fi
64+
elif [ "$VARIANT" = "" ]; then
65+
echo "Release version detected: $REL_VERSION"
66+
else
67+
echo "Invalid release variant: $VARIANT"
68+
exit 3
69+
fi
70+
71+
echo "Passed all version format validations."
72+
73+
RELEASE_BRANCH="release-$MAJOR_MINOR_VERSION"
74+
RELEASE_TAG="v$REL_VERSION"
75+
76+
if [ `git rev-parse --verify origin/$RELEASE_BRANCH 2>/dev/null` ]; then
77+
echo "$RELEASE_BRANCH branch already exists, checking it out ..."
78+
git checkout $RELEASE_BRANCH
79+
else
80+
echo "$RELEASE_BRANCH does not exist, creating ..."
81+
git checkout -b $RELEASE_BRANCH
82+
git push origin $RELEASE_BRANCH
83+
fi
84+
echo "$RELEASE_BRANCH branch is ready."
85+
86+
if [ `git rev-parse --verify $RELEASE_TAG 2>/dev/null` ]; then
87+
echo "$RELEASE_TAG tag already exists, aborting ..."
88+
exit 2
89+
fi
90+
91+
${script_dir}/update_sdk_version.sh $REL_VERSION
92+
git commit -s -m "Release $REL_VERSION" -a
93+
if [ "$VARIANT" = "" ]; then
94+
echo "Generating docs ..."
95+
${script_dir}/update_docs.sh $REL_VERSION
96+
git commit -s -m "Generate updated javadocs for $REL_VERSION" -a
97+
fi
98+
git push origin $RELEASE_BRANCH
99+
100+
echo "Tagging $RELEASE_TAG ..."
101+
git tag $RELEASE_TAG
102+
echo "$RELEASE_TAG is tagged."
103+
104+
echo "Pushing $RELEASE_TAG tag ..."
105+
git push origin $RELEASE_TAG
106+
echo "$RELEASE_TAG tag is pushed."
107+
108+
if [ "$VARIANT" = "" ]; then
109+
git clean -xdf
110+
echo "Creating pull request to update docs ..."
111+
branch_name="automation/update_docs_${current_time}"
112+
git reset --hard origin/master
113+
git cherry-pick $RELEASE_TAG
114+
git push origin $branch_name
115+
fi
116+
117+
echo "Done."
File renamed without changes.
File renamed without changes.

.github/workflows/create-release.yml

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
#
2+
# Copyright 2024 The Dapr Authors
3+
# Licensed under the Apache License, Version 2.0 (the "License");
4+
# you may not use this file except in compliance with the License.
5+
# You may obtain a copy of the License at
6+
# http://www.apache.org/licenses/LICENSE-2.0
7+
# Unless required by applicable law or agreed to in writing, software
8+
# distributed under the License is distributed on an "AS IS" BASIS,
9+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
10+
# See the License for the specific language governing permissions and
11+
# limitations under the License.
12+
#
13+
14+
name: Create a release
15+
16+
on:
17+
workflow_dispatch:
18+
inputs:
19+
rel_version:
20+
description: 'Release version (examples: 1.9.0-rc-1, 1.9.1, 1.11.0-SNAPSHOT)'
21+
required: true
22+
type: string
23+
24+
jobs:
25+
create-release:
26+
name: Creates release branch and tag
27+
runs-on: ubuntu-latest
28+
steps:
29+
- name: Check out code
30+
uses: actions/checkout@v4
31+
with:
32+
fetch-depth: 0
33+
- name: Install required packages
34+
run: |
35+
sudo apt-get update
36+
sudo apt-get install pcre2-utils
37+
- name: Create release branch and tag
38+
env:
39+
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
40+
run: |
41+
git config user.email "[email protected]"
42+
git config user.name "Dapr Bot"
43+
# Update origin with token
44+
git remote set-url origin https://x-access-token:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git
45+
# Copy first to allow automation to use the latest version and not the release branch's version.
46+
cp -R ./.github/scripts ${RUNNER_TEMP}/
47+
${RUNNER_TEMP}/scripts/create-release.sh ${{ inputs.rel_version }}
48+
trigger:
49+
name: Triggers the Dapr SDK build
50+
runs-on: ubuntu-latest
51+
needs: create-release
52+
steps:
53+
- name: Triggers the build
54+
env:
55+
GITHUB_TOKEN: ${{ secrets.DAPR_BOT_TOKEN }}
56+
run: |
57+
gh workflow run build.yml --repo dapr/java-sdk --ref v$(echo '${{ inputs.rel_version }}' | sed -r 's/^[vV]?([0-9].+)$/\1/')

0 commit comments

Comments
 (0)