|
1 | 1 | # This workflow is provided via the organization template repository |
2 | 2 | # |
3 | | -# https://github.com/nextcloud/.github |
| 3 | +# https://github.com/nextcloud-libraries/.github |
4 | 4 | # https://docs.github.com/en/actions/learn-github-actions/sharing-workflows-with-your-organization |
5 | 5 | # |
6 | 6 | # SPDX-FileCopyrightText: 2021-2024 Nextcloud GmbH and Nextcloud contributors |
|
14 | 14 |
|
15 | 15 | permissions: |
16 | 16 | contents: read |
| 17 | + packages: write |
17 | 18 |
|
18 | 19 | jobs: |
19 | 20 | publish: |
20 | 21 | runs-on: ubuntu-latest |
21 | | - |
22 | 22 | name: Build and publish to npm |
23 | | - permissions: |
24 | | - packages: write |
25 | 23 |
|
26 | 24 | steps: |
27 | | - - name: Check actor permission level |
28 | | - uses: skjnldsv/check-actor-permission@69e92a3c4711150929bca9fcf34448c5bf5526e7 # v3.0 |
29 | | - with: |
30 | | - require: write |
31 | | - |
32 | 25 | - name: Checkout |
33 | 26 | uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 |
34 | 27 | with: |
35 | 28 | persist-credentials: false |
36 | 29 |
|
37 | | - - name: Read package.json node and npm engines version |
38 | | - uses: skjnldsv/read-package-engines-version-actions@06d6baf7d8f41934ab630e97d9e6c0bc9c9ac5e4 # v3 |
39 | | - id: versions |
40 | | - with: |
41 | | - fallbackNode: '^20' |
42 | | - fallbackNpm: '^10' |
43 | | - |
44 | | - - name: Set up node ${{ steps.versions.outputs.nodeVersion }} |
| 30 | + - name: Set up node |
45 | 31 | uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.4.0 |
46 | 32 | with: |
47 | | - node-version: ${{ steps.versions.outputs.nodeVersion }} |
| 33 | + node-version-file: 'package.json' |
48 | 34 |
|
49 | | - - name: Set up npm ${{ steps.versions.outputs.npmVersion }} |
50 | | - 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 }} |
51 | 45 |
|
52 | 46 | - name: Install dependencies & build |
53 | 47 | env: |
|
56 | 50 | npm ci |
57 | 51 | npm run build --if-present |
58 | 52 |
|
| 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 | + |
59 | 67 | - name: Publish |
60 | 68 | run: | |
61 | 69 | npm config set //registry.npmjs.org/:_authToken=$NODE_AUTH_TOKEN |
62 | | - npm publish |
| 70 | + npm publish --tag $RELEASE_GROUP |
63 | 71 | env: |
64 | 72 | 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