Skip to content

Commit 0e9667d

Browse files
Enable nightly minor version releases
1 parent dcce388 commit 0e9667d

File tree

2 files changed

+89
-9
lines changed

2 files changed

+89
-9
lines changed

.github/workflows/build-image.yml

+30-9
Original file line numberDiff line numberDiff line change
@@ -54,30 +54,51 @@ jobs:
5454
run: |
5555
TARGET_VERSION=$(python -c 'import semver; print(semver.bump_${{ inputs.release-type }}("${{ inputs.base-version }}"))')
5656
echo "target_version=$TARGET_VERSION" >> $GITHUB_OUTPUT
57-
- name: Create new branch
57+
- name: Create or merge release branch
5858
# Note - CodeBuild depends on this branch name. Don't change without corresponding backend change.
59-
run: git checkout -b release-${{ steps.calc_target.outputs.target_version }}
59+
id: check_branch
60+
run: |
61+
git config --local user.email "github-actions[bot]@users.noreply.github.com"
62+
git config --local user.name "github-actions[bot]"
63+
if git ls-remote --exit-code --heads origin release-${{ steps.calc_target.outputs.target_version }}; then
64+
echo "Branch exists, merging latest changes in"
65+
git checkout release-${{ steps.calc_target.outputs.target_version }}
66+
git merge main
67+
git push
68+
else
69+
echo "Branch doesn't exist, creating now..."
70+
git checkout -b release-${{ steps.calc_target.outputs.target_version }}
71+
fi
6072
- name: Generate artifacts
6173
run: python ./src/main.py create-${{ inputs.release-type }}-version-artifacts --base-patch-version ${{ inputs.base-version }} --force
6274
- name: Commit .in artifacts to branch
6375
env:
6476
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
77+
# Generate the artifacts every time, only push if there are changes
6578
run: |
6679
git config --local user.email "github-actions[bot]@users.noreply.github.com"
6780
git config --local user.name "github-actions[bot]"
6881
git add ./build_artifacts
69-
git commit -m 'chore: Generate build artifacts for ${{ steps.calc_target.outputs.target_version }} release'
82+
git diff-index --quiet HEAD || git commit -m 'chore: Generate build artifacts for ${{ steps.calc_target.outputs.target_version }} release'
7083
git push --set-upstream origin release-${{ steps.calc_target.outputs.target_version }}
71-
- name: Open pull request
84+
- name: Create or fetch release PR
7285
id: get_pr_id
7386
env:
7487
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
75-
# Note - CodeBuild depends on this PR title. Don't change without corresponding backend change.
88+
# Create PR if it doesn't exist; fetch existing PR number if it does
7689
run: |
77-
URL=$(gh pr create -H release-${{ steps.calc_target.outputs.target_version }} \
78-
--title 'release: v${{ steps.calc_target.outputs.target_version }}' -F ./.github/workflows/PR_TEMPLATE.md)
79-
PR=$(echo $URL | sed 's:.*/::')
80-
echo "pr_id=$PR" >> $GITHUB_OUTPUT
90+
if gh pr list --head release-${{ steps.calc_target.outputs.target_version }} --state open --json number | grep -q '"number":'; then
91+
echo "PR exists already, just fetching ID"
92+
PR_ID=$(gh pr view release-${{ steps.calc_target.outputs.target_version }} --json number | jq -r .number)
93+
echo "pr_id=$PR_ID" >> $GITHUB_OUTPUT
94+
else
95+
echo "PR doesn't exist, creating now..."
96+
git push --set-upstream origin release-${{ steps.calc_target.outputs.target_version }}
97+
URL=$(gh pr create -H release-${{ steps.calc_target.outputs.target_version }} -B main \
98+
--title 'release: v${{ steps.calc_target.outputs.target_version }}' -F ./.github/workflows/PR_TEMPLATE.md)
99+
PR_ID=$(echo $URL | sed 's:.*/::')
100+
echo "pr_id=$PR_ID" >> $GITHUB_OUTPUT
101+
fi
81102
call-codebuild-project:
82103
runs-on: ubuntu-latest
83104
needs: open-pr
+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
name: Kickoff nightly Minor version builds
2+
run-name: Kickoff Minor nightly builds $(date +'%m-%d-%Y')
3+
on:
4+
# Run manually
5+
workflow_dispatch:
6+
# Run first day of the month at 8AM PST / 9AM PDT
7+
schedule:
8+
- cron: '0 16 1-10 * *'
9+
jobs:
10+
generate-version-matrix:
11+
name: Generate version matrix
12+
runs-on: ubuntu-latest
13+
if: github.repository == 'aws/sagemaker-distribution'
14+
outputs:
15+
matrix: ${{ steps.gen-mat.outputs.matrix }}
16+
steps:
17+
- uses: actions/checkout@v4
18+
- name: Get supported Major versions
19+
id: supported-major-versions
20+
# Check support_policy.md to determine active Major versions
21+
run: |
22+
major_versions=$(sed -n '/^### CPU Images/,/^### GPU Images/{
23+
/^### GPU Images/q
24+
/^| [0-9]/{
25+
s/^| \([0-9]\+\).*/\1/p
26+
}
27+
}' support_policy.md | sort -n | uniq | tr '\n' ',' | sed 's/,$//' | sed 's/,/","/g')
28+
echo "majors=[\"$major_versions\"]" >> $GITHUB_OUTPUT
29+
- name: Generate base patch version matrix
30+
id: gen-mat
31+
# Output looks like: matrix={"version":["1.13.1","2.5.0","3.0.0"]}
32+
# For each active Major version, get highest Minor version. Then get highest Patch
33+
# for that Minor. Use this Patch as base version.
34+
run: |
35+
versions=("{\"version\":[")
36+
for major in build_artifacts/v${{ steps.supported-major-versions.outputs.majors }}; do
37+
highest_minor=$(ls $major | sort -t. -k2n | tail -n1)
38+
highest_patch=$(ls $major/$highest_minor | sort -t. -k2n | tail -n1)
39+
versions+="\"${highest_patch#v}\""
40+
versions+=","
41+
done
42+
versions=${versions::-1}
43+
versions+="]}"
44+
echo "matrix=$versions" >> $GITHUB_OUTPUT
45+
start-minor-build:
46+
name: Start monthly minor release
47+
needs: generate-version-matrix
48+
permissions:
49+
pull-requests: write
50+
contents: write
51+
id-token: write
52+
strategy:
53+
matrix: ${{ fromJson(needs.generate-version-matrix.outputs.matrix) }}
54+
fail-fast: false
55+
uses: aws/sagemaker-distribution/.github/workflows/build-image.yml@main
56+
secrets: inherit
57+
with:
58+
release-type: "minor"
59+
base-version: ${{ matrix.version }}

0 commit comments

Comments
 (0)