-
Notifications
You must be signed in to change notification settings - Fork 0
162 lines (152 loc) · 5.39 KB
/
publish_node_package.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
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
152
153
154
155
156
157
158
159
160
161
162
name: Build and publish npm package
on:
workflow_call:
inputs:
branch_name:
description: 'Name of the branch to build the package from'
type: string
required: false
default: 'main'
build_package:
description: 'Build package before publishing'
required: false
type: boolean
default: false
disable_ignore_scripts_on_publish:
description: 'If false, add --ignore-scripts flag to npm publish command'
required: false
type: boolean
default: false
node_version:
description: 'Node.js version'
required: false
type: string
default: '18'
npm_registry_url:
description: 'NPM registry URL'
required: false
type: string
default: 'https://registry.npmjs.org/'
package_dependencies:
description: 'List of dependencies to update'
type: string
required: false
default: ''
package_name:
description: 'Name of the package to publish'
type: string
required: true
publish_package:
description: 'Publish package to private registry'
required: false
type: boolean
default: false
release_name:
description: 'Name of the release.'
type: string
required: false
repository_name:
description: 'Name of the repository to build the package from'
type: string
required: false
default: ${{ github.repository }}
working_directory:
description: 'Working directory'
required: false
type: string
default: '.'
secrets:
npm_registry_token:
description: 'NPM registry authentication token'
required: true
sentry_auth_token:
description: 'Sentry authentication token'
required: false
sentry_organisation:
description: 'Sentry organisation name'
required: false
sentry_project:
description: 'Sentry project name'
required: false
outputs:
release_name:
description: 'Name of the release.'
value: ${{ jobs.buildAndPublish.outputs.release_name }}
jobs:
buildAndPublish:
runs-on: ubuntu-latest
permissions:
contents: read
packages: write
outputs:
release_name: ${{ env.release_name }}
steps:
- name: Checkout
uses: actions/checkout@v4
with:
repository: ${{ inputs.repository_name }}
ref: ${{ inputs.branch_name }}
- name: Set release name
id: set_release_name
run: |
if [ -z "${{ inputs.release_name }}" ]; then
echo "release_name=nightly" >> $GITHUB_ENV
else
echo "release_name=${{ inputs.release_name }}" >> $GITHUB_ENV
fi
- name: "Set package version"
working-directory: ${{ inputs.working_directory }}
run: |
npm version prerelease --preid `git rev-parse --short HEAD`-`date +%Y%m%d%H%M` --no-git-tag-version
- name: Set dependecies versions
if: ${{ inputs.package_dependencies != '' }}
working-directory: ${{ inputs.working_directory }}
run: |
echo "## Dependencies used to build package" >> $GITHUB_STEP_SUMMARY
for dependency in $(echo "${{ inputs.package_dependencies }}" | tr '\n' ' ')
do
dependency_name=$(echo $dependency | cut -d'=' -f1)
dependency_version=$(echo $dependency | cut -d'=' -f2)
if [ "$dependency_name" == "$dependency_version" ]; then
dependency_version="nightly"
fi
dependency_semver=$(npm view $dependency_name dist-tags --json | jq -r --arg version "$dependency_version" '.[$version]')
echo "Setting $dependency_name to $dependency_version"
npm pkg set dependencies.$dependency_name=$dependency_semver
echo "### :package: $dependency_name version: $dependency_semver" >> $GITHUB_STEP_SUMMARY
done
cat package.json
- name: Configure node
if: |
inputs.publish_package ||
inputs.build_package
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node_version }}
registry-url: '${{ inputs.npm_registry_url }}'
scope: '@flowforge'
always-auth: true
- name: Build package
if: ${{ inputs.build_package }}
working-directory: ${{ inputs.working_directory }}
run: |
npm install --@flowforge:registry=${{ inputs.npm_registry_url }}
npm run build
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_registry_token }}
SENTRY_AUTH_TOKEN: ${{ secrets.sentry_auth_token }}
SENTRY_ORG: ${{ secrets.sentry_organisation }}
SENRTY_PROJECT: ${{ secrets.sentry_project }}
- name: Set package publish parameters
if: ${{ inputs.publish_package }}
run: |
if [ ${{ inputs.disable_ignore_scripts_on_publish }} == 'false' ]; then
echo "NPM_PUBLISH_PARAMETERS=--ignore-scripts" >> $GITHUB_ENV
fi
- name: Publish package
if: ${{ inputs.publish_package }}
working-directory: ${{ inputs.working_directory }}
run: |
npm publish ${{ env.NPM_PUBLISH_PARAMETERS }} --tag ${{ env.release_name }}
env:
NODE_AUTH_TOKEN: ${{ secrets.npm_registry_token }}