Skip to content

Commit 722e305

Browse files
committed
add pre and post release workflows
1 parent d471c70 commit 722e305

File tree

3 files changed

+226
-0
lines changed

3 files changed

+226
-0
lines changed
File renamed without changes.
Lines changed: 120 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,120 @@
1+
name: Post Release - Prepare Main for Next Development Cycle
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version number (e.g., 1.0.1)'
8+
required: true
9+
10+
env:
11+
AWS_DEFAULT_REGION: us-east-1
12+
13+
permissions:
14+
id-token: write
15+
contents: write
16+
pull-requests: write
17+
18+
jobs:
19+
check-version:
20+
runs-on: ubuntu-latest
21+
steps:
22+
- name: Checkout main
23+
uses: actions/checkout@v2
24+
with:
25+
ref: main
26+
fetch-depth: 0
27+
28+
- name: Extract Major.Minor Version and setup Env variable
29+
run: |
30+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
31+
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
32+
33+
- name: Get current major.minor version from main branch
34+
id: get_version
35+
run: |
36+
CURRENT_VERSION=$(grep '__version__' aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | sed -E 's/__version__ = "([0-9]+\.[0-9]+)\.[0-9]+.*"/\1/')
37+
echo "CURRENT_MAJOR_MINOR_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
38+
39+
- name: Set major and minor for current version
40+
run: |
41+
echo "CURRENT_MAJOR=$(echo $CURRENT_MAJOR_MINOR_VERSION | cut -d. -f1)" >> $GITHUB_ENV
42+
echo "CURRENT_MINOR=$(echo $CURRENT_MAJOR_MINOR_VERSION | cut -d. -f2)" >> $GITHUB_ENV
43+
44+
- name: Set major and minor for input version
45+
run: |
46+
echo "INPUT_MAJOR=$(echo $MAJOR_MINOR | cut -d. -f1)" >> $GITHUB_ENV
47+
echo "INPUT_MINOR=$(echo $MAJOR_MINOR | cut -d. -f2)" >> $GITHUB_ENV
48+
49+
- name: Compare major.minor version and skip if behind
50+
run: |
51+
if [ "$CURRENT_MAJOR" -gt "$INPUT_MAJOR" ] || { [ "$CURRENT_MAJOR" -eq "$INPUT_MAJOR" ] && [ "$CURRENT_MINOR" -gt "$INPUT_MINOR" ]; }; then
52+
echo "Input version is behind main's current major.minor version, don't need to update major version"
53+
exit 1
54+
fi
55+
56+
57+
prepare-main:
58+
runs-on: ubuntu-latest
59+
needs: check-version
60+
steps:
61+
- name: Configure AWS credentials for BOT secrets
62+
uses: aws-actions/configure-aws-credentials@v4
63+
with:
64+
role-to-assume: ${{ secrets.AWS_ROLE_ARN_SECRETS_MANAGER }}
65+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
66+
67+
- name: Get Bot secrets
68+
uses: aws-actions/aws-secretsmanager-get-secrets@v1
69+
id: bot_secrets
70+
with:
71+
secret-ids: |
72+
BOT_TOKEN ,${{ secrets.BOT_TOKEN_SECRET_ARN }}
73+
parse-json-secrets: true
74+
75+
- name: Setup Git
76+
uses: actions/checkout@v2
77+
with:
78+
fetch-depth: 0
79+
token: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
80+
81+
- name: Configure Git
82+
run: |
83+
git config user.name "github-actions"
84+
git config user.email "[email protected]"
85+
86+
- name: Extract Major.Minor Version and setup Env variable
87+
run: |
88+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
89+
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
90+
91+
- name: Determine release branch and checkout
92+
run: |
93+
RELEASE_BRANCH="release/v${MAJOR_MINOR}.x"
94+
git fetch origin $RELEASE_BRANCH
95+
git checkout -b "prepare-main-for-next-dev-cycle-${VERSION}" origin/$RELEASE_BRANCH
96+
97+
- name: Update version to next development version in main
98+
run: |
99+
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
100+
sed -i'' -e "s/val adotVersion = \".*\"/val adotVersion = \"${DEV_VERSION}\"/" version.gradle.kts
101+
VERSION="${{ github.event.inputs.version }}"
102+
sed -i'' -e 's/adot-autoinstrumentation-java:v2\.[0-9]+\.[0-9]+/adot-autoinstrumentation-java:v'$VERSION'/g' .github/workflows/daily-scan.yml
103+
git add version.gradle.kts
104+
git add .github/workflows/daily-scan.yml
105+
git commit -m "Prepare main for next development cycle: Update version to $DEV_VERSION"
106+
git push --set-upstream origin "prepare-main-for-next-dev-cycle-${VERSION}"
107+
108+
- name: Create Pull Request to main
109+
env:
110+
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
111+
run: |
112+
DEV_VERSION="${{ github.event.inputs.version }}.dev0"
113+
gh pr create --title "Post release $VERSION: Update version to $DEV_VERSION" \
114+
--body "This PR prepares the main branch for the next development cycle by updating the version to $DEV_VERSION and updating the image version to be scanned to the latest released.
115+
116+
This PR should only be merge when release for version v$VERSION is success.
117+
118+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \
119+
--head prepare-main-for-next-dev-cycle-${VERSION} \
120+
--base main
Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,106 @@
1+
name: Pre Release Prepare - Update Version and Create PR
2+
3+
on:
4+
workflow_dispatch:
5+
inputs:
6+
version:
7+
description: 'Version number (e.g., 1.0.1)'
8+
required: true
9+
is_patch:
10+
description: 'Is this a patch? (true or false)'
11+
required: true
12+
default: 'false'
13+
14+
env:
15+
AWS_DEFAULT_REGION: us-east-1
16+
17+
permissions:
18+
contents: write
19+
pull-requests: write
20+
id-token: write
21+
22+
23+
jobs:
24+
update-version-and-create-pr:
25+
runs-on: ubuntu-latest
26+
steps:
27+
- name: Configure AWS credentials for BOT secrets
28+
uses: aws-actions/configure-aws-credentials@v4
29+
with:
30+
role-to-assume: ${{ secrets.AWS_ROLE_ARN_SECRETS_MANAGER }}
31+
aws-region: ${{ env.AWS_DEFAULT_REGION }}
32+
33+
- name: Get Bot secrets
34+
uses: aws-actions/aws-secretsmanager-get-secrets@v1
35+
id: bot_secrets
36+
with:
37+
secret-ids: |
38+
BOT_TOKEN ,${{ secrets.BOT_TOKEN_SECRET_ARN }}
39+
parse-json-secrets: true
40+
41+
- name: Checkout main branch
42+
uses: actions/checkout@v3
43+
with:
44+
ref: 'main'
45+
token: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
46+
47+
- name: Setup Git
48+
run: |
49+
git config user.name "github-actions"
50+
git config user.email "[email protected]"
51+
52+
- name: Extract Major.Minor Version and setup Env variable
53+
run: |
54+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
55+
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
56+
57+
- name: Create branches
58+
run: |
59+
IS_PATCH=${{ github.event.inputs.is_patch }}
60+
if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then
61+
echo "Invalid input for IS_PATCH. Must be 'true' or 'false'."
62+
exit 1
63+
fi
64+
65+
66+
if git ls-remote --heads origin release/v${MAJOR_MINOR}.x | grep -q "release/v${MAJOR_MINOR}.x"; then
67+
if [ "$IS_PATCH" = "true" ]; then
68+
git fetch origin release/v${MAJOR_MINOR}.x
69+
echo "Branch release/v${MAJOR_MINOR}.x already exists, checking out."
70+
git checkout "release/v${MAJOR_MINOR}.x"
71+
else
72+
echo "Error, release series branch release/v${MAJOR_MINOR}.x exist for non-patch release"
73+
echo "Check your input or branch"
74+
exit 1
75+
fi
76+
else
77+
if [ "$IS_PATCH" = "true" ]; then
78+
echo "Error, release series branch release/v${MAJOR_MINOR}.x NOT exist for patch release"
79+
echo "Check your input or branch"
80+
exit 1
81+
else
82+
echo "Creating branch release/v${MAJOR_MINOR}.x."
83+
git checkout -b "release/v${MAJOR_MINOR}.x"
84+
git push origin "release/v${MAJOR_MINOR}.x"
85+
fi
86+
fi
87+
88+
git checkout -b "v${VERSION}_release"
89+
git push origin "v${VERSION}_release"
90+
91+
- name: Update version in file
92+
run: |
93+
sed -i'' -e "s/val adotVersion = \".*\"/val adotVersion = \"${VERSION}\"/" version.gradle.kts
94+
git commit -am "Update version to ${VERSION}"
95+
git push origin "v${VERSION}_release"
96+
97+
- name: Create pull request against the release branch
98+
env:
99+
GITHUB_TOKEN: ${{ env.BOT_TOKEN_GITHUB_RW_PATOKEN }}
100+
run: |
101+
gh pr create --title "Pre-release: Update version to ${VERSION}" \
102+
--body "This PR updates the version to ${VERSION}.
103+
104+
By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice." \
105+
--head v${{ github.event.inputs.version }}_release \
106+
--base release/v${MAJOR_MINOR}.x

0 commit comments

Comments
 (0)