-
Notifications
You must be signed in to change notification settings - Fork 1
107 lines (94 loc) · 3.32 KB
/
npm-publish.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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
name: Publish Package
on:
release:
types:
- released
workflow_dispatch:
inputs:
npm:
default: "yes"
description: Publish to NPM?
required: true
gpr:
default: "yes"
description: Publish to GPR?
required: true
jobs:
prepare:
name: Prepare the source code
runs-on: ubuntu-latest
if: github.event_name == 'release' || github.event.inputs.npm == 'yes' || github.event.inputs.gpr == 'yes'
steps:
- name: Checkout source
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
ref: ${{ github.event.release.tag_name }}
- name: Set up Node.js environment
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
node-version: lts/*
cache: npm
- name: Install dependencies
run: npm ci --ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Run postinstall scripts
run: npm rebuild && npm run prepare --if-present
- name: Build
run: npm run build
- name: Create tarball
run: npm pack
- name: Save tarball
uses: actions/upload-artifact@65c4c4a1ddee5b72f698fdd19549f0f0fb45cf08 # v4
with:
name: package
path: "*.tgz"
retention-days: 1
publish:
name: Publish package
runs-on: ubuntu-latest
needs: prepare
strategy:
matrix:
registry:
- npm
- gpr
include:
- registry: npm
secret: NPM_TOKEN
registry_url: https://registry.npmjs.org/
- registry: gpr
secret: GITHUB_TOKEN
registry_url: https://npm.pkg.github.com/
steps:
- name: Set commit status to PENDING
uses: myrotvorets/set-commit-status-action@3730c0a348a2ace3c110851bed53331bc6406e9f # v2.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: pending
context: Publish to ${{ matrix.registry }}
sha: ${{ github.sha }}
if: github.event.inputs[matrix.registry] == 'yes' || github.event_name == 'release'
- name: Set up Node.js environment
if: github.event.inputs[matrix.registry] == 'yes' || github.event_name == 'release'
uses: actions/setup-node@39370e3970a6d050c480ffad4ff0ed4d3fdee5af # v4.1.0
with:
registry-url: ${{ matrix.registry_url }}
- name: Download tarball
if: github.event.inputs[matrix.registry] == 'yes' || github.event_name == 'release'
uses: actions/download-artifact@fa0a91b85d4f404e444e00e005971372dc801d16 # v4
with:
name: package
- name: Publish package
if: github.event.inputs[matrix.registry] == 'yes' || github.event_name == 'release'
run: npm publish *.tgz
env:
NODE_AUTH_TOKEN: ${{ secrets[matrix.secret] }}
- name: Set final commit status
uses: myrotvorets/set-commit-status-action@3730c0a348a2ace3c110851bed53331bc6406e9f # v2.0.1
with:
token: ${{ secrets.GITHUB_TOKEN }}
status: ${{ job.status }}
context: Publish to ${{ matrix.registry }}
sha: ${{ github.sha }}
if: always() && (github.event.inputs[matrix.registry] == 'yes' || github.event_name == 'release')