4242 - uses : actions/checkout@v4
4343 - uses : mamba-org/setup-micromamba@v1
4444 with :
45- environment-file : ./environment.yml
45+ environment-file : ./environment.lock
4646 environment-name : sagemaker-distribution
4747 init-shell : bash
4848 - name : Free up disk space
@@ -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
0 commit comments