Skip to content

Commit 1c8b497

Browse files
authored
Pre/Post release workflow update for Safety in Patch release (#144)
*Description of changes:* 1. For post release version bump, if the released version is a older major.minor version (e.g. patch for 1.0.0 -> 1.0.1, but main in 1.1.0.dev0), it won't trigger https://github.com/XinRanZhAWS/aws-otel-python-instrumentation/actions/runs/8619606136 2. For pre release, update the step for checkout release/v branches, make it safe for patch release (in this case the release/v branch already exist), and test to make sure it consume version number (and changes) from release/v not main in this case https://github.com/XinRanZhAWS/aws-otel-python-instrumentation/actions/runs/8619568106 https://github.com/XinRanZhAWS/aws-otel-python-instrumentation/pull/9/files By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.
1 parent c45eac0 commit 1c8b497

File tree

2 files changed

+72
-2
lines changed

2 files changed

+72
-2
lines changed

.github/workflows/post_release_version_bump.yml

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,47 @@ permissions:
1212
pull-requests: write
1313

1414
jobs:
15+
check-version:
16+
runs-on: ubuntu-latest
17+
steps:
18+
- name: Checkout main
19+
uses: actions/checkout@v2
20+
with:
21+
ref: main
22+
fetch-depth: 0
23+
24+
- name: Extract Major.Minor Version and setup Env variable
25+
run: |
26+
echo "VERSION=${{ github.event.inputs.version }}" >> $GITHUB_ENV
27+
echo "MAJOR_MINOR=$(echo ${{ github.event.inputs.version }} | sed -E 's/([0-9]+\.[0-9]+)\.[0-9]+/\1/')" >> $GITHUB_ENV
28+
29+
- name: Get current major.minor version from main branch
30+
id: get_version
31+
run: |
32+
CURRENT_VERSION=$(grep '__version__' aws-opentelemetry-distro/src/amazon/opentelemetry/distro/version.py | sed -E 's/__version__ = "([0-9]+\.[0-9]+)\.[0-9]+.*"/\1/')
33+
echo "CURRENT_MAJOR_MINOR_VERSION=$CURRENT_VERSION" >> $GITHUB_ENV
34+
35+
- name: Set major and minor for current version
36+
run: |
37+
echo "CURRENT_MAJOR=$(echo $CURRENT_MAJOR_MINOR_VERSION | cut -d. -f1)" >> $GITHUB_ENV
38+
echo "CURRENT_MINOR=$(echo $CURRENT_MAJOR_MINOR_VERSION | cut -d. -f2)" >> $GITHUB_ENV
39+
40+
- name: Set major and minor for input version
41+
run: |
42+
echo "INPUT_MAJOR=$(echo $MAJOR_MINOR | cut -d. -f1)" >> $GITHUB_ENV
43+
echo "INPUT_MINOR=$(echo $MAJOR_MINOR | cut -d. -f2)" >> $GITHUB_ENV
44+
45+
- name: Compare major.minor version and skip if behind
46+
run: |
47+
if [ "$CURRENT_MAJOR" -gt "$INPUT_MAJOR" ] || { [ "$CURRENT_MAJOR" -eq "$INPUT_MAJOR" ] && [ "$CURRENT_MINOR" -gt "$INPUT_MINOR" ]; }; then
48+
echo "Input version is behind main's current major.minor version, don't need to update major version"
49+
exit 1
50+
fi
51+
52+
1553
prepare-main:
1654
runs-on: ubuntu-latest
55+
needs: check-version
1756
steps:
1857
- name: Setup Git
1958
uses: actions/checkout@v2

.github/workflows/pre_release_prepare.yml

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,10 @@ on:
66
version:
77
description: 'Version number (e.g., 1.0.1)'
88
required: true
9+
is_patch:
10+
description: 'Is this a patch? (true or false)'
11+
required: true
12+
default: 'false'
913

1014
permissions:
1115
contents: write
@@ -33,8 +37,35 @@ jobs:
3337
3438
- name: Create branches
3539
run: |
36-
git checkout -b "release/${MAJOR_MINOR}.x"
37-
git push origin "release/${MAJOR_MINOR}.x"
40+
IS_PATCH=${{ github.event.inputs.is_patch }}
41+
if [[ "$IS_PATCH" != "true" && "$IS_PATCH" != "false" ]]; then
42+
echo "Invalid input for IS_PATCH. Must be 'true' or 'false'."
43+
exit 1
44+
fi
45+
46+
47+
if git ls-remote --heads origin release/${MAJOR_MINOR}.x | grep -q "release/${MAJOR_MINOR}.x"; then
48+
if [ "$IS_PATCH" = "true" ]; then
49+
git fetch origin release/${MAJOR_MINOR}.x
50+
echo "Branch release/${MAJOR_MINOR}.x already exists, checking out."
51+
git checkout "release/${MAJOR_MINOR}.x"
52+
else
53+
echo "Error, release series branch release/${MAJOR_MINOR}.x exist for non-patch release"
54+
echo "Check your input or branch"
55+
exit 1
56+
fi
57+
else
58+
if [ "$IS_PATCH" = "true" ]; then
59+
echo "Error, release series branch release/${MAJOR_MINOR}.x NOT exist for patch release"
60+
echo "Check your input or branch"
61+
exit 1
62+
else
63+
echo "Creating branch release/${MAJOR_MINOR}.x."
64+
git checkout -b "release/${MAJOR_MINOR}.x"
65+
git push origin "release/${MAJOR_MINOR}.x"
66+
fi
67+
fi
68+
3869
git checkout -b "${VERSION}_release"
3970
git push origin "${VERSION}_release"
4071

0 commit comments

Comments
 (0)