-
Notifications
You must be signed in to change notification settings - Fork 0
93 lines (80 loc) · 2.97 KB
/
npm_publish_release.yml
File metadata and controls
93 lines (80 loc) · 2.97 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
81
82
83
84
85
86
87
88
89
90
91
92
93
name: 🔩 Publish Release (Auto)
on:
workflow_call:
inputs:
branch:
type: string
default: main
description: "The branch to publish the release from."
version-prefix:
type: string
default: "v"
description: "The prefix to use for version tags"
permissions:
contents: write
id-token: write
pull-requests: read
issues: read
jobs:
release:
runs-on: ubuntu-latest
timeout-minutes: 30
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Get Current Version from package.json
id: new_version
shell: bash
run: |
VERSION=$(jq -r .version package.json)
VERSION_WITH_PREFIX="${{ inputs.version-prefix }}$VERSION"
echo "Current Version: $VERSION"
echo "Current Version with prefix: $VERSION_WITH_PREFIX"
echo "version=$VERSION" >> $GITHUB_OUTPUT
echo "version-with-prefix=$VERSION_WITH_PREFIX" >> $GITHUB_OUTPUT
- name: Create GitHub Release
id: release
uses: box-id/github-actions-oss/.github/actions/create-github-release@main
with:
branch: ${{ inputs.branch }}
version: ${{ steps.new_version.outputs.version }}
version-prefix: ${{ inputs.version-prefix }}
github-token: ${{ secrets.GITHUB_TOKEN }}
- uses: volta-cli/action@v4
with:
registry-url: https://registry.npmjs.org
env:
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN_READ_ALL }}
- name: Get npm version
id: npm-version
run: echo "npm=$(npm -v)" >> $GITHUB_OUTPUT
- name: Compare npm version >= 11.5.1
uses: madhead/semver-utils@v4
id: npm_version_check
with:
version: ${{ steps.npm-version.outputs.npm }}
satisfies: ">=11.5.1"
- name: Check if npm version is compatible with OIDC trusted publisher
if: steps.npm_version_check.outputs.satisfies == 'false'
run: |
echo "npm version does not support OIDC trusted publisher. Please upgrade npm to 11.5.1 or higher."
exit 1
- name: Install Dependencies
if: steps.release.outputs.version_has_changed == 'true'
run: npm ci
- name: Build Project
if: steps.release.outputs.version_has_changed == 'true'
run: npm run compile
- name: Create empty npmrc for publish (OIDC)
if: steps.release.outputs.version_has_changed == 'true'
run: |
: > "${NPM_CONFIG_USERCONFIG}"
env:
NPM_CONFIG_USERCONFIG: ${{ github.workspace }}/.npmrc.publish
- name: Publish to npm (OIDC trusted publisher)
if: steps.release.outputs.version_has_changed == 'true'
# publish authentication is done by the trusted provider OIDC setting within the NPM package settings
run: npm publish --access restricted
env:
NODE_AUTH_TOKEN: ""
NPM_CONFIG_USERCONFIG: ${{ github.workspace }}/.npmrc.publish