44 workflow_dispatch :
55 inputs :
66 bump :
7- description : Version bump from the latest published version (prerelease publishes <next>-tp.N to the next dist-tag, without a bump PR)
7+ description : Version bump
88 required : true
99 default : patch
1010 type : choice
1111 options :
1212 - patch
1313 - minor
1414 - major
15- - prerelease
1615
1716permissions :
1817 contents : read
1918
20- concurrency :
21- group : publish
22- cancel-in-progress : false
23-
2419jobs :
2520 publish :
21+ if : github.ref == 'refs/heads/master'
2622 runs-on : ubuntu-latest
2723 permissions :
2824 contents : write
2925 id-token : write
3026 env :
3127 BUMP : ${{ inputs.bump }}
3228 steps :
33- - name : Require master
34- if : github.ref != 'refs/heads/master'
35- run : |
36- echo "::error::run this workflow from master"
37- exit 1
38-
3929 - uses : actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
4030 with :
4131 fetch-depth : 0
42- persist-credentials : false
4332
4433 # No registry-url: setup-node would write an .npmrc token line that shadows OIDC.
4534 - uses : actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
@@ -48,56 +37,19 @@ jobs:
4837
4938 - run : npm install -g npm@11.21.0
5039
51- - name : Set version
52- run : |
53- name=$(node -p 'require("./package.json").name')
54- [ "$name" = browserstack-local ] || { echo "::error::package $name != browserstack-local"; exit 1; }
55- # Start from whichever is higher: npm latest or master, since master can lag until the bump PR merges.
56- published=$(npm view browserstack-local dist-tags.latest)
57- local_version=$(node -p 'require("./package.json").version')
58- base=$(node -e 'const p=v=>v.split("-")[0].split(".").map(Number),[a,b]=process.argv.slice(1),x=p(a),y=p(b);for(let i=0;i<3;i++){if(x[i]!==y[i]){console.log(x[i]>y[i]?a:b);process.exit()}}console.log(a)' "$published" "$local_version")
59- npm version "$base" --no-git-tag-version --allow-same-version > /dev/null
60- if [ "$BUMP" = prerelease ]; then
61- npm version prerelease --preid tp --no-git-tag-version > /dev/null
62- # Skip -tp.N numbers that are already on npm.
63- while [ "$(curl -s -o /dev/null -w '%{http_code}' "https://registry.npmjs.org/browserstack-local/$(node -p 'require("./package.json").version')")" != 404 ]; do
64- npm version prerelease --preid tp --no-git-tag-version > /dev/null
65- done
66- echo "DIST_TAG=next" >> "$GITHUB_ENV"
67- else
68- npm version "$BUMP" --no-git-tag-version > /dev/null
69- echo "DIST_TAG=latest" >> "$GITHUB_ENV"
70- fi
71- version=$(node -p 'require("./package.json").version')
72- code=$(curl -s -o /dev/null -w '%{http_code}' "https://registry.npmjs.org/browserstack-local/$version")
73- [ "$code" = 404 ] || { echo "::error::browserstack-local@$version already exists on npm (HTTP $code)"; exit 1; }
74- if git ls-remote --exit-code --tags origin "refs/tags/v$version" > /dev/null; then
75- echo "::error::tag v$version already exists"
76- exit 1
77- fi
78- echo "VERSION=$version" >> "$GITHUB_ENV"
79- echo "Publishing $version (base $base: npm latest $published, master $local_version) to dist-tag $([ "$BUMP" = prerelease ] && echo next || echo latest)"
80-
81- - name : Commit and tag
40+ - name : Upgrade version
8241 run : |
8342 git config user.name "github-actions[bot]"
8443 git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
85- git commit -qam "$VERSION"
86- git tag -a "v$VERSION" -m "$VERSION"
44+ npm version "$BUMP"
8745
8846 - name : Publish
89- run : npm publish --tag "$DIST_TAG" -- access public
47+ run : npm publish --access public
9048
91- - name : Push tag
92- env :
93- GH_TOKEN : ${{ github.token }}
94- run : git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "refs/tags/v$VERSION"
95-
96- - name : Push version bump branch
97- if : env.DIST_TAG == 'latest'
98- env :
99- GH_TOKEN : ${{ github.token }}
49+ - name : Push tag and version bump branch
10050 run : |
101- branch="release-v$VERSION-$(date +%s)"
102- git push "https://x-access-token:${GH_TOKEN}@github.com/${GITHUB_REPOSITORY}.git" "HEAD:refs/heads/$branch"
51+ version=$(node -p 'require("./package.json").version')
52+ branch="release-v$version-$(date +%s)"
53+ git push origin "v$version"
54+ git push origin "HEAD:refs/heads/$branch"
10355 echo "Open the version bump PR: $GITHUB_SERVER_URL/$GITHUB_REPOSITORY/compare/master...$branch?expand=1" | tee -a "$GITHUB_STEP_SUMMARY"
0 commit comments