@@ -54,30 +54,51 @@ jobs:
54
54
run : |
55
55
TARGET_VERSION=$(python -c 'import semver; print(semver.bump_${{ inputs.release-type }}("${{ inputs.base-version }}"))')
56
56
echo "target_version=$TARGET_VERSION" >> $GITHUB_OUTPUT
57
- - name : Create new branch
57
+ - name : Create or merge release branch
58
58
# 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
60
72
- name : Generate artifacts
61
73
run : python ./src/main.py create-${{ inputs.release-type }}-version-artifacts --base-patch-version ${{ inputs.base-version }} --force
62
74
- name : Commit .in artifacts to branch
63
75
env :
64
76
GITHUB_TOKEN : ${{ secrets.GITHUB_TOKEN }}
77
+ # Generate the artifacts every time, only push if there are changes
65
78
run : |
66
79
git config --local user.email "github-actions[bot]@users.noreply.github.com"
67
80
git config --local user.name "github-actions[bot]"
68
81
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'
70
83
git push --set-upstream origin release-${{ steps.calc_target.outputs.target_version }}
71
- - name : Open pull request
84
+ - name : Create or fetch release PR
72
85
id : get_pr_id
73
86
env :
74
87
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
76
89
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
81
102
call-codebuild-project :
82
103
runs-on : ubuntu-latest
83
104
needs : open-pr
0 commit comments