Skip to content

Commit 472d3b7

Browse files
Merge pull request #592 from dolthub/eric/fix-cd-from-main
Update build/release versions using PRs during release process
2 parents c5a88ff + 0c2f14b commit 472d3b7

File tree

6 files changed

+197
-18
lines changed

6 files changed

+197
-18
lines changed
Lines changed: 38 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,11 @@
11
name: Bump build version
22
description: Bumps SemVer buildVersion in the input builder-config file
33
inputs:
4-
build-config-file:
5-
description: File path to the builder config yaml file
4+
platform:
5+
description: Platform to update builder config yaml file
6+
required: true
7+
token:
8+
description: GitHub token
69
required: true
710
commit:
811
description: If true, will add and commit the new build version. Default false.
@@ -15,11 +18,17 @@ outputs:
1518
runs:
1619
using: "composite"
1720
steps:
21+
- name: Get build config file
22+
id: filepath
23+
run: |
24+
echo "build-config-file=web/build/builder-${{ inputs.platform }}-config.yaml" >> $GITHUB_OUTPUT
25+
shell: bash
26+
1827
- name: Get current build version
1928
id: current-build-version
2029
run: |
21-
version="$(yq '.buildVersion' ${{ inputs.build-config-file }})"
22-
echo "Current buildVersion in ${{ inputs.build-config-file }} is $version"
30+
version="$(yq '.buildVersion' ${{ steps.filepath.outputs.build-config-file }})"
31+
echo "Current buildVersion in ${{ steps.filepath.outputs.build-config-file }} is $version"
2332
echo "version=$version" >> $GITHUB_OUTPUT
2433
shell: bash
2534

@@ -30,15 +39,35 @@ runs:
3039
current_version: ${{ steps.current-build-version.outputs.version }}
3140
level: patch
3241

33-
- name: Update ${{ inputs.build-config-file }} buildVersion
42+
- name: Update ${{ steps.filepath.outputs.build-config-file }} buildVersion
3443
run: |
35-
yq -i '.buildVersion = "${{ steps.bump-version.outputs.new_version }}"' ${{ inputs.build-config-file }}
36-
echo "New buildVersion in ${{ inputs.build-config-file }} is ${{ steps.bump-version.outputs.new_version }}"
44+
yq -i '.buildVersion = "${{ steps.bump-version.outputs.new_version }}"' ${{ steps.filepath.outputs.build-config-file }}
45+
echo "New buildVersion in ${{ steps.filepath.outputs.build-config-file }} is ${{ steps.bump-version.outputs.new_version }}"
46+
shell: bash
47+
48+
- name: Get current branch
49+
id: current-branch
50+
run: |
51+
echo "branch=$(git branch --show-current)" >> $GITHUB_OUTPUT
3752
shell: bash
3853

3954
- name: Add and commit new build version
4055
if: ${{ inputs.commit == 'true' }}
4156
uses: EndBug/add-and-commit@v9
4257
with:
43-
message: "Update ${{ inputs.build-config-file }} buildVersion to ${{ steps.bump-version.outputs.new_version }}"
44-
pull: origin
58+
message: "Update ${{ steps.filepath.outputs.build-config-file }} buildVersion to ${{ steps.bump-version.outputs.new_version }} [skip ci]"
59+
pull: ${{ steps.current-branch.outputs.branch != format('build/{0}', inputs.platform) && format('origin {0}', steps.current-branch.outputs.branch) || '' }}
60+
push: --set-upstream origin ${{ steps.current-branch.outputs.branch }}
61+
62+
- name: Raise PR and merge
63+
if: ${{ inputs.commit == 'true' }}
64+
run: |
65+
CURRENT_BRANCH=${{ steps.current-branch.outputs.branch }}
66+
if [[ $CURRENT_BRANCH == build/* ]]
67+
then
68+
gh pr create --base main --head $CURRENT_BRANCH --title "Update ${{ inputs.platform }} build version to ${{ steps.bump-version.outputs.new_version }}" --body "Increment version"
69+
gh pr merge --merge --delete-branch $CURRENT_BRANCH
70+
fi
71+
env:
72+
GITHUB_TOKEN: ${{ inputs.token }}
73+
shell: bash

.github/workflows/cd-release-dmg.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@ on:
1313
description: Github Release Version Number
1414
required: true
1515
type: string
16+
via-call:
17+
description: Determines if this workflow was called by another workflow
18+
required: false
19+
default: true
20+
type: boolean
21+
22+
env:
23+
VIA_CALL: ${{ inputs.via-call || false }}
1624

1725
jobs:
1826
build-dmg:
1927
name: Build Mac release version
2028
runs-on: macos-14
2129
steps:
30+
- name: Validate branch
31+
if: ${{ github.ref_name != 'main' }}
32+
run: |
33+
echo "This workflow can only run from 'main' (got '${{ github.ref_name }}')." >&2
34+
exit 1
35+
2236
- name: Checkout code
2337
uses: actions/checkout@v3
2438

2539
- name: Bump build version
2640
uses: ./.github/actions/bump-build-version
2741
with:
28-
build-config-file: web/build/builder-dmg-config.yaml
42+
platform: dmg
43+
token: ${{ secrets.GITHUB_TOKEN }}
2944

3045
- uses: actions/setup-node@v4
3146
with:
@@ -100,9 +115,26 @@ jobs:
100115
group: commit-build-version
101116
cancel-in-progress: false
102117
steps:
118+
- name: Get branch to checkout
119+
id: branch-to-update
120+
env:
121+
EVENT_NAME: ${{ github.event_name }}
122+
run: |
123+
if [[ ${{ env.VIA_CALL }} == 'true' ]]; then
124+
echo "branch=release/${{ inputs.release-version }}" >> $GITHUB_OUTPUT
125+
else
126+
echo "branch=build/dmg" >> $GITHUB_OUTPUT
127+
fi
128+
103129
- uses: actions/checkout@v3
130+
with:
131+
fetch-depth: 0
132+
133+
- name: Checkout correct branch
134+
run: git switch -C ${{ steps.branch-to-update.outputs.branch }}
104135

105136
- uses: ./.github/actions/bump-build-version
106137
with:
107-
build-config-file: web/build/builder-dmg-config.yaml
138+
platform: dmg
139+
token: ${{ secrets.GITHUB_TOKEN }}
108140
commit: true

.github/workflows/cd-release-linux.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,19 +13,34 @@ on:
1313
description: Github Release Version Number
1414
required: true
1515
type: string
16+
via-call:
17+
description: Determines if this workflow was called by another workflow
18+
required: false
19+
default: true
20+
type: boolean
21+
22+
env:
23+
VIA_CALL: ${{ inputs.via-call || false }}
1624

1725
jobs:
1826
build-linux:
1927
name: Build Linux release version
2028
runs-on: ubuntu-22.04
2129
steps:
30+
- name: Validate branch
31+
if: ${{ github.ref_name != 'main' }}
32+
run: |
33+
echo "This workflow can only run from 'main' (got '${{ github.ref_name }}')." >&2
34+
exit 1
35+
2236
- name: Checkout code
2337
uses: actions/checkout@v3
2438

2539
- name: Bump linux build version
2640
uses: ./.github/actions/bump-build-version
2741
with:
28-
build-config-file: web/build/builder-linux-config.yaml
42+
platform: linux
43+
token: ${{ secrets.GITHUB_TOKEN }}
2944

3045
- uses: actions/setup-node@v4
3146
with:
@@ -66,10 +81,27 @@ jobs:
6681
group: commit-build-version
6782
cancel-in-progress: false
6883
steps:
84+
- name: Get branch to checkout
85+
id: branch-to-update
86+
env:
87+
EVENT_NAME: ${{ github.event_name }}
88+
run: |
89+
if [[ ${{ env.VIA_CALL }} == 'true' ]]; then
90+
echo "branch=release/${{ inputs.release-version }}" >> $GITHUB_OUTPUT
91+
else
92+
echo "branch=build/linux" >> $GITHUB_OUTPUT
93+
fi
94+
6995
- uses: actions/checkout@v3
96+
with:
97+
fetch-depth: 0
98+
99+
- name: Checkout correct branch
100+
run: git switch -C ${{ steps.branch-to-update.outputs.branch }}
70101

71102
- uses: ./.github/actions/bump-build-version
72103
with:
73-
build-config-file: web/build/builder-linux-config.yaml
104+
platform: linux
105+
token: ${{ secrets.GITHUB_TOKEN }}
74106
commit: true
75107

.github/workflows/cd-release-mas.yaml

Lines changed: 34 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,35 @@ on:
1313
description: Github Release Version Number
1414
required: true
1515
type: string
16+
via-call:
17+
description: Determines if this workflow was called by another workflow
18+
required: false
19+
default: true
20+
type: boolean
21+
22+
env:
23+
VIA_CALL: ${{ inputs.via-call || false }}
1624

1725
jobs:
1826
build-mas:
1927
name: Build Mac App Store release version
2028
runs-on: macos-14
2129
steps:
30+
- name: Validate branch
31+
if: ${{ github.ref_name != 'main' }}
32+
run: |
33+
echo "This workflow can only run from 'main' (got '${{ github.ref_name }}')." >&2
34+
exit 1
35+
2236
- name: Checkout code
2337
uses: actions/checkout@v3
2438

2539
- name: Bump MAS build version
2640
id: bump-mas-version
2741
uses: ./.github/actions/bump-build-version
2842
with:
29-
build-config-file: web/build/builder-mas-config.yaml
43+
platform: mas
44+
token: ${{ secrets.GITHUB_TOKEN }}
3045

3146
- uses: actions/setup-node@v4
3247
with:
@@ -93,9 +108,26 @@ jobs:
93108
group: commit-build-version
94109
cancel-in-progress: false
95110
steps:
111+
- name: Get branch to checkout
112+
id: branch-to-update
113+
env:
114+
EVENT_NAME: ${{ github.event_name }}
115+
run: |
116+
if [[ ${{ env.VIA_CALL }} == 'true' ]]; then
117+
echo "branch=release/${{ inputs.release-version }}" >> $GITHUB_OUTPUT
118+
else
119+
echo "branch=build/mas" >> $GITHUB_OUTPUT
120+
fi
121+
96122
- uses: actions/checkout@v3
123+
with:
124+
fetch-depth: 0
125+
126+
- name: Checkout correct branch
127+
run: git switch -C ${{ steps.branch-to-update.outputs.branch }}
97128

98129
- uses: ./.github/actions/bump-build-version
99130
with:
100-
build-config-file: web/build/builder-mas-config.yaml
131+
platform: mas
132+
token: ${{ secrets.GITHUB_TOKEN }}
101133
commit: true

.github/workflows/cd-release-windows.yaml

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,12 +13,26 @@ on:
1313
description: Github Release Version Number
1414
required: true
1515
type: string
16+
via-call:
17+
description: Determines if this workflow was called by another workflow
18+
required: false
19+
default: true
20+
type: boolean
21+
22+
env:
23+
VIA_CALL: ${{ inputs.via-call || false }}
1624

1725
jobs:
1826
build-windows:
1927
name: Build Windows release version
2028
runs-on: windows-2022
2129
steps:
30+
- name: Validate branch
31+
if: ${{ github.ref_name != 'main' }}
32+
run: |
33+
echo "This workflow can only run from 'main' (got '${{ github.ref_name }}')." >&2
34+
exit 1
35+
2236
- name: Checkout code
2337
uses: actions/checkout@v3
2438

@@ -29,7 +43,8 @@ jobs:
2943
- name: Bump Windows build version
3044
uses: ./.github/actions/bump-build-version
3145
with:
32-
build-config-file: web/build/builder-win-config.yaml
46+
platform: win
47+
token: ${{ secrets.GITHUB_TOKEN }}
3348

3449
- uses: actions/setup-node@v4
3550
with:
@@ -78,9 +93,24 @@ jobs:
7893
group: commit-build-version
7994
cancel-in-progress: false
8095
steps:
96+
- name: Get branch to checkout
97+
id: branch-to-update
98+
run: |
99+
if [[ ${{ env.VIA_CALL }} == 'true' ]]; then
100+
echo "branch=release/${{ inputs.release-version }}" >> $GITHUB_OUTPUT
101+
else
102+
echo "branch=build/win" >> $GITHUB_OUTPUT
103+
fi
104+
81105
- uses: actions/checkout@v3
106+
with:
107+
fetch-depth: 0
108+
109+
- name: Checkout correct branch
110+
run: git switch -C ${{ steps.branch-to-update.outputs.branch }}
82111

83112
- uses: ./.github/actions/bump-build-version
84113
with:
85-
build-config-file: web/build/builder-win-config.yaml
114+
platform: win
115+
token: ${{ secrets.GITHUB_TOKEN }}
86116
commit: true

.github/workflows/cd-release.yaml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,12 @@ jobs:
3131
release_id: ${{ steps.create_release.outputs.id }}
3232
release_version: ${{ needs.format-version.outputs.version }}
3333
steps:
34+
- name: Validate branch
35+
if: ${{ github.ref_name != 'main' }}
36+
run: |
37+
echo "This workflow can only run from 'main' (got '${{ github.ref_name }}')." >&2
38+
exit 1
39+
3440
- name: Checkout code
3541
uses: actions/checkout@v3
3642

@@ -41,7 +47,8 @@ jobs:
4147
- name: Add and commit new version
4248
uses: EndBug/add-and-commit@v9
4349
with:
44-
message: "Update web/package.json version to ${{ needs.format-version.outputs.version }}"
50+
message: "Update web/package.json version to ${{ needs.format-version.outputs.version }} [skip ci]"
51+
new_branch: release/${{ needs.format-version.outputs.version }}
4552

4653
- name: Create Release
4754
id: create_release
@@ -105,3 +112,20 @@ jobs:
105112
with:
106113
release-version: ${{ needs.create-release.outputs.release_version }}
107114

115+
create-pr-and-merge:
116+
name: Create PR and merge
117+
needs: [create-release, build-mas, build-windows, build-dmg, build-linux]
118+
if: ${{ always() && needs.create-release.result == 'success' && !cancelled() }}
119+
runs-on: ubuntu-22.04
120+
steps:
121+
- uses: actions/checkout@v3
122+
123+
- name: Create PR and merge
124+
run: |
125+
gh pr create --base main --head release/${{ needs.create-release.outputs.release_version }} --title "Update versions for release ${{ needs.create-release.outputs.release_version }}" --body "Increment versions"
126+
gh pr merge --merge --delete-branch release/${{ needs.create-release.outputs.release_version }}
127+
env:
128+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
129+
130+
131+

0 commit comments

Comments
 (0)