@@ -104,62 +104,49 @@ jobs:
104104 run : npm run testenv:stop
105105 if : always()
106106
107- build-publish :
108- permissions :
109- contents : write
110- id-token : write
111- issues : write
112- pull-requests : write
107+ version :
113108 runs-on : ubuntu-latest
114- needs :
115- - lint
116- - test
109+ needs : [test]
110+ outputs :
111+ next_version : ${{ steps.calc.outputs.next_version }}
117112 steps :
118- - name : Generate release bot app token
119- id : generate_token
120- uses : actions/create-github-app-token@v2
121- with :
122- app-id : ${{ secrets.HIROSYSTEMS_RELEASE_BOT_ID }}
123- private-key : ${{ secrets.HIROSYSTEMS_RELEASE_BOT_PEM }}
124-
125113 - uses : actions/checkout@v6
126114 with :
127115 fetch-depth : 0
128- persist-credentials : false
129-
130- - name : Get bot user ID
131- id : bot-user-id
132- run : |
133- echo "user-id=$(gh api "/users/${{ steps.generate_token.outputs.app-slug }}[bot]" --jq .id)" >> "$GITHUB_OUTPUT"
134- env :
135- GH_TOKEN : ${{ steps.generate_token.outputs.token }}
136116
137- - uses : actions/setup-node@v6
117+ - name : Use Node.js
118+ uses : actions/setup-node@v6
138119 with :
139- node-version-file : .nvmrc
140-
141- - name : Upgrade to latest npm
142- run : |
143- npm install -g npm@latest
144- npm -v
120+ node-version-file : ' .nvmrc'
145121
146- - name : Install deps
147- run : npm ci --audit=false
122+ - name : Install version tools
123+ run : npm install -g conventional-recommended-bump conventional-changelog-conventionalcommits semver
148124
149- - name : Build
150- run : npm run build
151-
152- - name : Semantic Release
153- uses : cycjimmy/semantic-release-action@b12c8f6015dc215fe37bc154d4ad456dd3833c90 # v6
154- # Only run on non-PR events or only PRs that aren't from forks
155- if : github.event_name != 'pull_request' || github.event.pull_request.head.repo.full_name == github.repository
156- env :
157- GITHUB_TOKEN : ${{ steps.generate_token.outputs.token }}
158- SEMANTIC_RELEASE_PACKAGE : ${{ github.event.repository.name }}
159- GIT_AUTHOR_EMAIL : " ${{ steps.bot-user-id.outputs.user-id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com"
160- GIT_COMMITTER_EMAIL : " ${{ steps.bot-user-id.outputs.user-id }}+${{ steps.generate_token.outputs.app-slug }}[bot]@users.noreply.github.com"
161- with :
162- extra_plugins : |
163- @semantic-release/changelog@6.0.3
164- @semantic-release/git@10.0.1
165- conventional-changelog-conventionalcommits@9.1.0
125+ - name : Calculate next version
126+ id : calc
127+ run : |
128+ BRANCH="${GITHUB_HEAD_REF:-$GITHUB_REF_NAME}"
129+ LATEST_TAG=$(git describe --tags --abbrev=0 2>/dev/null || echo "v0.0.0")
130+ LATEST_VERSION=${LATEST_TAG#v}
131+
132+ if [ "$BRANCH" = "master" ]; then
133+ BUMP=$(npx conventional-recommended-bump -p conventionalcommits)
134+ NEXT_VERSION=$(npx semver "$LATEST_VERSION" -i "$BUMP")
135+ elif [ "$BRANCH" = "alpha" ] || [ "$BRANCH" = "beta" ]; then
136+ CHANNEL="$BRANCH"
137+ if echo "$LATEST_VERSION" | grep -qE "\-${CHANNEL}\.[0-9]+$"; then
138+ NEXT_VERSION=$(npx semver "$LATEST_VERSION" -i prerelease --preid "$CHANNEL")
139+ else
140+ BUMP=$(npx conventional-recommended-bump -p conventionalcommits)
141+ BASE=$(npx semver "$LATEST_VERSION" -i "$BUMP")
142+ NEXT_VERSION="${BASE}-${CHANNEL}.0"
143+ fi
144+ else
145+ echo "Skipping version calculation for branch '$BRANCH'"
146+ echo "next_version=" >> "$GITHUB_OUTPUT"
147+ exit 0
148+ fi
149+
150+ echo "next_version=$NEXT_VERSION" >> "$GITHUB_OUTPUT"
151+ echo "## Next Version: \`$NEXT_VERSION\`" >> "$GITHUB_STEP_SUMMARY"
152+ echo "Based on branch \`$BRANCH\`, latest tag \`$LATEST_TAG\`" >> "$GITHUB_STEP_SUMMARY"
0 commit comments