-
Notifications
You must be signed in to change notification settings - Fork 36
87 lines (74 loc) · 2.34 KB
/
reusable-npm.yml
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
name: Reusable workflow for npm packages
on:
workflow_call:
inputs:
package_workspace:
required: true
type: string
description: The package's workspace path relative to the node directory.
secrets:
npm-token:
required: true
permissions:
contents: read
id-token: write
jobs:
build:
runs-on: ubuntu-latest
if: github.event_name == 'pull_request'
defaults:
run:
working-directory: ./node
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- uses: actions/setup-node@v4
with:
node-version: 20
- name: Install dependencies
run: |
sudo apt-get install libsecret-1-dev
npm ci
- name: Build package
run: npm run build -w ${{ inputs.package_workspace }}
publish:
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'release'
defaults:
run:
working-directory: ./node
steps:
- name: Checkout Repository
uses: actions/checkout@v4
- name: Check version (only for push events)
if: github.event_name == 'push'
id: version_check
run: |
VERSION=$(cd ${{ inputs.package_workspace }} && node --print "require('./package.json').version")
echo "Package version: ${VERSION}"
if [[ $VERSION == *"-next" ]]; then
echo "is_next_version=true" >> $GITHUB_OUTPUT
else
echo "is_next_version=false" >> $GITHUB_OUTPUT
fi
- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: 20
registry-url: "https://registry.npmjs.org"
- name: Install dependencies
run: |
sudo apt-get install libsecret-1-dev
npm ci
- name: Publish next version
if: github.event_name == 'push' && steps.version_check.outputs.is_next_version == 'true'
run: npm run publish:next -w ${{ inputs.package_workspace }}
env:
NODE_AUTH_TOKEN: ${{ secrets.npm-token }}
NPM_CONFIG_PROVENANCE: true
- name: Publish latest version
if: github.event_name == 'release'
run: npm run publish:latest -w ${{ inputs.package_workspace }}
env:
NODE_AUTH_TOKEN: ${{ secrets.npm-token }}
NPM_CONFIG_PROVENANCE: true