Skip to content

Commit c2030c3

Browse files
authored
Merge pull request #139 from nextcloud-libraries/feat/workflow-auto-update-npm-publish.yml
2 parents 69c1daa + cbe8d19 commit c2030c3

File tree

1 file changed

+33
-20
lines changed

1 file changed

+33
-20
lines changed

.github/workflows/npm-publish.yml

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# This workflow is provided via the organization template repository
22
#
3-
# https://github.com/nextcloud/.github
3+
# https://github.com/nextcloud-libraries/.github
44
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
55
#
66
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
@@ -19,31 +19,29 @@ permissions:
1919
jobs:
2020
publish:
2121
runs-on: ubuntu-latest
22-
2322
name: Build and publish to npm
24-
steps:
25-
- name: Check actor permission level
26-
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
27-
with:
28-
require: admin
2923

24+
steps:
3025
- name: Checkout
31-
uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4
32-
33-
- name: Read package.json node and npm engines version
34-
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
35-
id: versions
26+
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
3627
with:
37-
fallbackNode: '^20'
38-
fallbackNpm: '^10'
28+
persist-credentials: false
3929

40-
- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
41-
uses: actions/setup-node@60edb5dd545a775178f52524783378180af0d1f8 # v3
30+
- name: Set up node
31+
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
4232
with:
43-
node-version: ${{ steps.versions.outputs.nodeVersion }}
33+
node-version-file: 'package.json'
4434

45-
- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
46-
run: npm i -g npm@"${{ steps.versions.outputs.npmVersion }}"
35+
- name: Check tag matches package.json
36+
run: |
37+
VERSION=$(node -p -e "require('./package.json').version")
38+
GH_VERSION=$(echo "$GH_VERSION" | sed s,\^v,,)
39+
if [ "$VERSION" != "$GH_VERSION" ]; then
40+
echo "$VERSION does not match $GH_VERSION"
41+
exit 1;
42+
fi;
43+
env:
44+
GH_VERSION: ${{ github.event.release.tag_name }}
4745

4846
- name: Install dependencies & build
4947
env:
@@ -52,9 +50,24 @@ jobs:
5250
npm ci
5351
npm run build --if-present
5452
53+
- name: Fetch latest tag
54+
id: latest-tag
55+
run: |
56+
TAG=$(gh release list \
57+
--exclude-drafts \
58+
--exclude-pre-releases \
59+
--json isLatest,tagName \
60+
--jq 'map(select(.isLatest == true))[].tagName' \
61+
-R ${{ github.repository }})
62+
echo "Latest tag is $TAG"
63+
echo "LATEST_TAG=$TAG" >> $GITHUB_OUTPUT
64+
env:
65+
GH_TOKEN: ${{ github.token }}
66+
5567
- name: Publish
5668
run: |
5769
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
58-
npm publish
70+
npm publish --tag $RELEASE_GROUP
5971
env:
6072
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
73+
RELEASE_GROUP: ${{ (contains(github.ref, 'rc') || contains(github.ref, 'beta') || contains(github.ref, 'alpha')) && 'next' || ((steps.latest-tag.outputs.LATEST_TAG != github.event.release.tag_name) && 'stable' || 'latest') }}

0 commit comments

Comments
 (0)