Skip to content

Commit 0ff1a03

Browse files
authored
Merge pull request #149 from github/major-minor-choices
Increment version numbers using bash script
2 parents 0ecfc1e + 5e2e8ec commit 0ff1a03

2 files changed

Lines changed: 44 additions & 11 deletions

File tree

.github/workflows/release.yml

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
name: Create release PR
22

3-
run-name: Create release PR for v${{ github.event.inputs.version }}
3+
run-name: Create release PR for new ${{ github.event.inputs.version }} version
44

55
on:
66
workflow_dispatch:
77
inputs:
88
version:
99
required: true
10-
description: "Version to bump `package.json` to (format: x.y.z)"
10+
type: choice
11+
description: "What type of release is this"
12+
options:
13+
- "major"
14+
- "minor"
15+
- "patch"
1116
update-language-server:
1217
required: true
1318
description: "Update the language server to the latest version?"
@@ -36,13 +41,17 @@ jobs:
3641
git config --global user.email "github-actions@github.com"
3742
git config --global user.name "GitHub Actions"
3843
39-
git checkout -b release/${{ inputs.version }}
44+
NEW_VERSION=$(./script/workflows/increment-version.sh ${{ inputs.version }})
4045
41-
npm version ${{ inputs.version }} --no-git-tag-version
46+
git checkout -b release/$NEW_VERSION
47+
48+
npm version $NEW_VERSION --no-git-tag-version
4249
git add package.json package-lock.json
43-
git commit -m "Release extension version ${{ inputs.version }}"
50+
git commit -m "Release extension version $NEW_VERSION"
51+
52+
git push --set-upstream origin release/$NEW_VERSION
4453
45-
git push --set-upstream origin release/${{ inputs.version }}
54+
echo "new_version=$NEW_VERSION" >> $GITHUB_ENV
4655
4756
- name: Update language server
4857
if: ${{ inputs.update-language-server }}
@@ -51,17 +60,17 @@ jobs:
5160
git checkout -- package.json
5261
npm i
5362
54-
- uses: stefanzweifel/git-auto-commit-action@v4
63+
- uses: stefanzweifel/git-auto-commit-action@3ea6ae190baf489ba007f7c92608f33ce20ef04a
5564
with:
56-
branch: release/${{ inputs.version }}
65+
branch: release/${{ env.new_version }}
5766
if: ${{ inputs.update-language-server }}
5867

5968
- name: Create PR
6069
run: |
6170
gh pr create \
62-
--title "Release version ${{ inputs.version }}" \
63-
--body "Release version ${{ inputs.version }}" \
71+
--title "Release version ${{ env.new_version }}" \
72+
--body "Release version ${{ env.new_version }}" \
6473
--base main \
65-
--head release/${{ inputs.version }}
74+
--head release/${{ env.new_version }}
6675
env:
6776
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
VERSION=$(cat package.json | jq -r '.version')
4+
5+
MAJOR=$(echo $VERSION | cut -d. -f1)
6+
MINOR=$(echo $VERSION | cut -d. -f2)
7+
PATCH=$(echo $VERSION | cut -d. -f3)
8+
9+
if [ "$1" == "major" ]; then
10+
MAJOR=$((MAJOR+1))
11+
MINOR=0
12+
PATCH=0
13+
elif [ "$1" == "minor" ]; then
14+
MINOR=$((MINOR+1))
15+
PATCH=0
16+
elif [ "$1" == "patch" ]; then
17+
PATCH=$((PATCH+1))
18+
else
19+
echo "Invalid version type. Use 'major', 'minor' or 'patch'"
20+
exit 1
21+
fi
22+
23+
NEW_VERSION="$MAJOR.$MINOR.$PATCH"
24+
echo $NEW_VERSION

0 commit comments

Comments
 (0)