-
Notifications
You must be signed in to change notification settings - Fork 0
151 lines (149 loc) · 5.64 KB
/
release.yml
File metadata and controls
151 lines (149 loc) · 5.64 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: Release a Node.js package
on:
workflow_call:
inputs:
github-app-id:
description: >
The id of a GitHub app used to publish the release. The `github-app-key`
secret is mandatory when this is set.
type: string
required: false
npm:
description: >
Pass `true` to enable the npm publish steps. In that case, the `npm-token`
or `github-token` (or both) secret is mandatory.
type: boolean
default: false
required: false
node-version:
description: Version of Node.js used to run the npm publish steps.
type: string
default: 24.x
required: false
npm-setup-command:
description: Command used to setup the package before publishing to npm.
type: string
default: <auto>
required: false
public:
description: >
This option only affects scoped packages.
Whether the package will be published to the public npm registry. If `false`,
the package will be published only to the GitHub Package Registry (GPR).
When publishing to GPR, the `github-token` must have the `packages: write` permission.
type: boolean
default: false
required: false
release-type:
description: >
Option passed to the release-please action.
Set to the empty string to use a release manifest config.
type: string
default: node
required: false
secrets:
github-token:
required: false
github-app-key:
required: false
npm-token:
required: false
jobs:
release-please:
runs-on: ubuntu-slim
timeout-minutes: 5
outputs:
release_created: ${{ steps.release.outputs.release_created }}
npm-final-setup-command: ${{ steps.get-command.outputs.npm-final-setup-command }}
publish_github: ${{ steps.extract-registries.outputs.publish_github }}
publish_npm: ${{ steps.extract-registries.outputs.publish_npm }}
steps:
- uses: actions/checkout@v6
- name: Get package name
run: echo "PACKAGE_NAME=$(jq .name package.json | tr -d '"')" >> $GITHUB_ENV
- name: Generate a token for release-please
if: ${{ inputs.github-app-id }}
id: generate-token
uses: actions/create-github-app-token@v2
with:
app-id: ${{ inputs.github-app-id }}
private-key: ${{ secrets.github-app-key }}
permission-contents: write
permission-issues: write
permission-pull-requests: write
- uses: googleapis/release-please-action@v5
id: release
with:
token: ${{ steps.generate-token.outputs.token || secrets.github-token }}
release-type: ${{ inputs.release-type }}
- name: Get npm setup command
id: get-command
if: ${{ steps.release.outputs.release_created }}
run: |
SETUP_COMMAND="${{ inputs.npm-setup-command }}"
if [ "$SETUP_COMMAND" = "<auto>" ]; then
if [ -f "package-lock.json" ]; then
SETUP_COMMAND="npm ci"
else
SETUP_COMMAND="npm install"
fi
fi
echo "npm-final-setup-command=$SETUP_COMMAND" >> $GITHUB_OUTPUT
- name: Extract registries to publish
id: extract-registries
if: ${{ steps.release.outputs.release_created }}
env:
IS_PUBLIC: ${{ inputs.public }}
run: |
# If the PACKAGE_NAME starts with @, it's a scoped package.
# In that case, we need to publish to the GitHub Package Registry and
# optionally to the public npm registry (when IS_PUBLIC is true).
if [[ $PACKAGE_NAME == @* ]]; then
if [ "$IS_PUBLIC" = "true" ]; then
echo "publish_github=true" >> $GITHUB_OUTPUT
echo "publish_npm=true" >> $GITHUB_OUTPUT
else
echo "publish_github=true" >> $GITHUB_OUTPUT
fi
else
echo "publish_npm=true" >> $GITHUB_OUTPUT
fi
publish-package:
needs: release-please
if: ${{ needs.release-please.outputs.release_created && inputs.npm && (needs.release-please.outputs.publish_npm=='true' || needs.release-please.outputs.publish_github=='true') }}
runs-on: ubuntu-slim
timeout-minutes: 10
strategy:
fail-fast: false
matrix:
include:
- id: npm
enabled: ${{ needs.release-please.outputs.publish_npm=='true' }}
registry-url: 'https://registry.npmjs.org'
- id: github
enabled: ${{ needs.release-please.outputs.publish_github=='true' }}
registry-url: 'https://npm.pkg.github.com'
name: publish-package-${{ matrix.id }}
steps:
- uses: actions/checkout@v6
if: ${{ matrix.enabled }}
- uses: actions/setup-node@v6
if: ${{ matrix.enabled }}
with:
node-version: ${{ inputs.node-version }}
registry-url: ${{ matrix.registry-url }}
- name: Run npm setup command
if: ${{ matrix.enabled }}
run: ${{ needs.release-please.outputs.npm-final-setup-command }}
env:
NODE_AUTH_TOKEN: ${{ matrix.id=='github' && secrets.github-token || '' }}
- name: Publish package to npm
if: ${{ matrix.enabled && matrix.id=='npm' }}
run: npm publish --no-ignore-scripts --access public
env:
NODE_AUTH_TOKEN: ${{ secrets.npm-token }}
- name: Publish package to GitHub Package Registry
if: ${{ matrix.enabled && matrix.id=='github' }}
run: npm publish --no-ignore-scripts
env:
NODE_AUTH_TOKEN: ${{ secrets.github-token }}