-
Notifications
You must be signed in to change notification settings - Fork 2
80 lines (68 loc) · 2.55 KB
/
npm-publish.yml
File metadata and controls
80 lines (68 loc) · 2.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud-libraries/.github
# https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization
#
# SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors
# SPDX-License-Identifier: MIT
name: Publish
on:
release:
types: [published]
permissions:
contents: read
packages: write
jobs:
publish:
runs-on: ubuntu-latest
name: Build and publish to npm
steps:
- name: Checkout
uses: actions/checkout@08c6903cd8c0fde910a37f88322edcfb5dd907a8 # v5.0.0
with:
persist-credentials: false
- name: Read package.json
uses: nextcloud-libraries/parse-package-engines-action@122ae05d4257008180a514e1ddeb0c1b9d094bdd # v0.1.0
id: versions
- name: Set up node
uses: actions/setup-node@2028fbc5c25fe9cf00d9f06a71cc4710d4507903 # v6.0.0
with:
node-version: ${{ steps.versions.outputs.node-version }}
- name: Set up npm
run: npm i -g 'npm@${{ steps.versions.outputs.package-manager-version }}'
- name: Check tag matches package.json
run: |
VERSION=$(node -p -e "require('./package.json').version")
GH_VERSION=$(echo "$GH_VERSION" | sed s,\^v,,)
if [ "$VERSION" != "$GH_VERSION" ]; then
echo "$VERSION does not match $GH_VERSION"
exit 1;
fi;
env:
GH_VERSION: ${{ github.event.release.tag_name }}
- name: Install dependencies & build
env:
CYPRESS_INSTALL_BINARY: 0
run: |
npm ci
npm run build --if-present
- name: Fetch latest tag
id: latest-tag
run: |
TAG=$(gh release list \
--exclude-drafts \
--exclude-pre-releases \
--json isLatest,tagName \
--jq 'map(select(.isLatest == true))[].tagName' \
-R ${{ github.repository }})
echo "Latest tag is $TAG"
echo "LATEST_TAG=$TAG" >> $GITHUB_OUTPUT
env:
GH_TOKEN: ${{ github.token }}
- name: Publish
run: |
npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN
npm publish --tag $RELEASE_GROUP
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}
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') }}