-
Notifications
You must be signed in to change notification settings - Fork 41
186 lines (181 loc) · 6.15 KB
/
create-release.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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
name: Create Release
on:
workflow_dispatch:
inputs:
dry_run:
description: Build package but don't tag or publish.
type: boolean
required: true
default: false
jobs:
build_x86_x64:
strategy:
matrix:
os: [ ubuntu-latest, windows-latest ]
node: [ 18, 20, 22 ]
arch: [ x86, x64 ]
exclude:
# Ubuntu does not ship x86 builds.
- { os: ubuntu-latest, arch: x86 }
runs-on: ${{ matrix.os }}
name: "${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}"
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
architecture: ${{ matrix.arch }}
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/node_modules
key: "${{ matrix.os }}-${{ matrix.arch }}-node-${{ matrix.node }}-${{ hashFiles('./package.json') }}"
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.node }}"
path: prebuilds
build_macos_arm:
strategy:
matrix:
os: [ macos-14 ]
node: [ 18, 20, 22 ]
arch: [ arm64 ]
runs-on: ${{ matrix.os }}
name: "${{ matrix.os }} / Node ${{ matrix.node }} ${{ matrix.arch }}"
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/node_modules
key: "${{ matrix.os }}-${{ matrix.arch }}-node-${{ matrix.node }}-${{ hashFiles('./package.json') }}"
- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
architecture: ${{ matrix.arch }}
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: "${{ matrix.os }}-${{ matrix.arch }}-${{ matrix.node }}"
path: prebuilds
build_linux_arm:
# Skip this group if the PR doesn't originate from the main repo.
# Trying to run this on standard runners is just going to fail due to
# lack of CPU resources.
if: ${{ vars.NR_RUNNER != '' }}
strategy:
matrix:
node: [ 18, 20, 22 ]
runs-on: ${{ vars.NR_RUNNER }}
name: Linux / Node ${{ matrix.node }} arm64
timeout-minutes: 15
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Use node ${{ matrix.node }}
uses: actions/setup-node@v4
with:
node-version: ${{ matrix.node }}
- uses: actions/cache@v4
with:
path: ${{ github.workspace }}/node_modules
key: "linux-arm64-node-${{ matrix.node }}-${{ hashFiles('./package.json') }}"
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Upload artifact
uses: actions/upload-artifact@v4
with:
name: "linux-arm64-${{ matrix.node }}"
path: prebuilds
package:
needs: [ build_x86_x64, build_macos_arm, build_linux_arm ]
runs-on: ubuntu-latest
name: Create package
steps:
- uses: actions/checkout@v4
- uses: actions/setup-node@v4
- run: |
mkdir prebuilds
rm -f .gitignore
- uses: actions/download-artifact@v4
with:
path: ${{ github.workspace }}/prebuilds
merge-multiple: true
- run: echo -e "PKG_VERSION=$(jq -r .version < package.json)" >> "$GITHUB_ENV"
- run: npm pack
- uses: actions/upload-artifact@v4
with:
name: npm-module
path: newrelic-native-metrics-${{ env.PKG_VERSION }}.tgz
# Our typical flow looks like:
# 1. prepare-release workflow
# 2. create-release workflow
#
# We can't do that (easily) because access to artifacts from other workflows
# are difficult to access (requires a personal access token). See
# https://github.com/actions/download-artifact#download-artifacts-from-other-workflow-runs-or-repositories
#
# Given that, we need to replicate all of our create-release steps inline
# here.
tag_release:
if: ${{ inputs.dry_run == false }}
needs: [ package ]
runs-on: ubuntu-latest
name: Tag Release
steps:
- uses: actions/checkout@v4
# We need access to the prep scripts in the node-newrelic repo.
- uses: actions/checkout@v4
with:
repository: newrelic/node-newrelic
path: agent-repo
- uses: actions/setup-node@v4
- run: |
# Install agent-repo dependencies.
npm install --prefix agent-repo
- name: Configure GitHub Credentials
run: |
git config user.name ${GITHUB_ACTOR}
git config user.email gh-actions-${GITHUB_ACTOR}@github.com
- name: Create Release Tag
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node ./agent-repo/bin/create-release-tag.js --branch ${{ github.ref }} --repo ${{ github.repository }} --workflows prepare-release.yml
- name: Get Created Tag
id: get_tag
run: echo "latest_tag=$(git describe --tags --abbrev=0)" >> ${GITHUB_OUTPUT}
- name: Create GitHub Release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
node ./agent-repo/bin/create-github-release.js --tag ${{ steps.get_tag.outputs.latest_tag }} --repo ${{ github.repository }} --changelog CHANGELOG.md
publish:
if: ${{ inputs.dry_run == false }}
needs: [ tag_release ]
runs-on: ubuntu-latest
name: Publish Package
steps:
- uses: actions/setup-node@v4
with:
registry-url: 'https://registry.npmjs.org'
- uses: actions/download-artifact@v4
with:
name: npm-module
- run: echo -e "PKG_NAME=$(ls -1A *.tgz | head -n 1)" >> "$GITHUB_ENV"
- run: npm publish --access=public ${PKG_NAME}
env:
NODE_AUTH_TOKEN: ${{ secrets.NODE_AGENT_NPM_TOKEN }}