Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 33 additions & 20 deletions .github/workflows/npm-publish.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# This workflow is provided via the organization template repository
#
# https://github.com/nextcloud/.github
# 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
Expand All @@ -19,31 +19,29 @@ permissions:
jobs:
publish:
runs-on: ubuntu-latest

name: Build and publish to npm
steps:
- name: Check actor permission level
uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0
with:
require: write

steps:
- name: Checkout
uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7

- name: Read package.json node and npm engines version
uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3
id: versions
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fallbackNode: '^20'
fallbackNpm: '^10'
persist-credentials: false

- name: Set up node ${{ steps.versions.outputs.nodeVersion }}
uses: actions/setup-node@1e60f620b9541d16bece96c5465dc8ee9832be0b # v4.0.3
- name: Set up node
uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0
with:
node-version: ${{ steps.versions.outputs.nodeVersion }}
node-version-file: 'package.json'

- name: Set up npm ${{ steps.versions.outputs.npmVersion }}
run: npm i -g 'npm@${{ steps.versions.outputs.npmVersion }}'
- 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:
Expand All @@ -52,9 +50,24 @@ jobs:
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
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') }}