Skip to content

Commit aa1c592

Browse files
committed
ci: update ci
1 parent c34fef1 commit aa1c592

File tree

1 file changed

+28
-5
lines changed

1 file changed

+28
-5
lines changed

.github/workflows/build.yml

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,23 @@ jobs:
3838
- name: Set Preview Version for Beta Branch
3939
if: "github.ref == 'refs/heads/beta'"
4040
run: |
41-
# get current version
41+
# get current version from package.json
4242
CURRENT_VERSION=$(node -p "require('./package.json').version")
43+
echo "Current version from package.json: $CURRENT_VERSION"
44+
45+
# get latest tag from git (if any)
46+
LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "")
47+
if [ -n "$LATEST_TAG" ]; then
48+
# remove v prefix (if any)
49+
LATEST_TAG=${LATEST_TAG#v}
50+
echo "Latest git tag version: $LATEST_TAG"
51+
52+
# compare version, take the larger one
53+
if [ "$(printf '%s\n' "$LATEST_TAG" "$CURRENT_VERSION" | sort -V | tail -n1)" = "$LATEST_TAG" ]; then
54+
CURRENT_VERSION=$LATEST_TAG
55+
echo "Using git tag version as it's newer: $CURRENT_VERSION"
56+
fi
57+
fi
4358
4459
# parse version components
4560
MAJOR=$(echo $CURRENT_VERSION | cut -d. -f1)
@@ -50,17 +65,24 @@ jobs:
5065
if [ $((MINOR % 2)) -eq 0 ]; then
5166
# if it is even, add 1 to make it odd (preview version)
5267
NEW_MINOR=$((MINOR + 1))
68+
# reset PATCH to 0
69+
PATCH=0
5370
else
54-
# if it is odd, keep it
71+
# if it is odd, keep it, but add 1 to PATCH
5572
NEW_MINOR=$MINOR
73+
PATCH=$((PATCH + 1))
5674
fi
5775
5876
# build new preview version
5977
PREVIEW_VERSION="$MAJOR.$NEW_MINOR.$PATCH"
78+
echo "New preview version: $PREVIEW_VERSION"
6079
6180
# update package.json
6281
node -e "const fs=require('fs');const pkg=JSON.parse(fs.readFileSync('./package.json'));pkg.version='${PREVIEW_VERSION}';fs.writeFileSync('./package.json',JSON.stringify(pkg,null,2));"
6382
83+
# create a new git tag
84+
git tag "v$PREVIEW_VERSION"
85+
6486
echo "Set preview version to ${PREVIEW_VERSION}"
6587
6688
- name: Publish
@@ -70,23 +92,24 @@ jobs:
7092
OVSX_TOKEN: ${{secrets.OVSX_TOKEN}}
7193
IS_PREVIEW: ${{ github.ref == 'refs/heads/beta' && 'true' || 'false' }}
7294

73-
- name: Git commit
95+
- name: Git commit and tag
7496
id: commit
7597
run: |
7698
git config --local user.email github-actions[bot]@users.noreply.github.com
7799
git config --local user.name github-actions[bot]
78100
git config --global core.autocrlf true
79101
git config --global core.safecrlf false
80102
git add .
81-
git commit -m "chore: ci build" -a
103+
git commit -m "chore: ci build [skip ci]" -a
82104
continue-on-error: true
83105

84-
- name: Git push
106+
- name: Git push with tags
85107
uses: ad-m/github-push-action@master
86108
if: ${{ steps.commit.outcome == 'success' }}
87109
with:
88110
github_token: ${{ secrets.GITHUB_TOKEN }}
89111
branch: ${{ github.ref }}
112+
tags: true
90113

91114
- name: Log
92115
if: ${{ steps.commit.outcome != 'success' }}

0 commit comments

Comments
 (0)