-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
action.yml
245 lines (230 loc) · 9.66 KB
/
action.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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
name: "Pkg Action"
description: "A GitHub Action for 'compiling' node projects into binaries using vercel/pkg or equivalent"
branding:
color: purple
icon: package
inputs:
# Required
entrypoint:
description: "The binary entrypoint path"
required: true
# Optional
arch:
description: "The architecture to build for x64|amd64|aarch64|arm64"
required: false
default: "${{ runner.arch }}"
config:
description: "The config file to use"
required: false
default: package.json
filename:
description: "The filename of the resulting binary"
required: false
default: ""
node-version:
description: "The node version to package with"
required: false
default: "20"
options:
description: "Additional options and flags to pass into pkg"
required: false
os:
description: "The operating system to build for win|linux|macos"
required: false
default: "${{ runner.os }}"
pkg:
description: "The version of pkg to use"
required: false
default: "@yao-pkg/pkg@5.16.1"
test:
description: "Hidden flag for input testing"
default: false
required: false
upload:
description: "Upload the artifact. Useful if you need to grab them for downstream things like code signing."
required: false
default: true
upload-key:
description: "Upload key for the artifact. Useful if want to override outputs.artifact-key with a specific value."
required: false
default: ""
outputs:
file:
description: "The path to the generated binary."
value: ${{ steps.pkg-action.outputs.file }}
artifact-key:
description: "The artifact upload key."
value: ${{ steps.pkg-action.outputs.artifact-key }}
runs:
using: composite
steps:
- name: Validate required inputs
shell: bash
run: |
echo "::group::Ensure entrypoint is set"
if [ "${{ inputs.entrypoint }}" == "" ]; then
echo "::error title=Entrypoint is not set!::You must specify an entrypoint file in order to run this shit."
exit 47
fi
echo "::endgroup::"
- name: Set internal outputs
shell: bash
id: pkg-action-internal
run: |
echo "::group::Setting internal outputs"
if [ "${{ inputs.os }}" == "Linux" ]; then
echo "target-os=linux" >> $GITHUB_OUTPUT
elif [ "${{ inputs.os }}" == "macOS" ]; then
echo "target-os=macos" >> $GITHUB_OUTPUT
elif [ "${{ inputs.os }}" == "Windows" ]; then
echo "target-os=win" >> $GITHUB_OUTPUT
else
echo "target-os=${{ inputs.os }}" >> $GITHUB_OUTPUT
fi
if [ "${{ runner.arch }}" == "X86" ]; then
echo "runner-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ runner.arch }}" == "X64" ]; then
echo "runner-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ runner.arch }}" == "ARM" ]; then
echo "runner-arch=arm64" >> $GITHUB_OUTPUT
elif [ "${{ runner.arch }}" == "ARM64" ]; then
echo "runner-arch=arm64" >> $GITHUB_OUTPUT
else
echo "runner-arch=${{ runner.arch }}" >> $GITHUB_OUTPUT
fi
if [ "${{ inputs.arch }}" == "X86" ]; then
echo "target-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "X64" ]; then
echo "target-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "amd64" ]; then
echo "target-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "ARM" ]; then
echo "target-arch=arm64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "ARM64" ]; then
echo "target-arch=arm64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "aarch64" ]; then
echo "target-arch=arm64" >> $GITHUB_OUTPUT
else
echo "target-arch=${{ inputs.arch }}" >> $GITHUB_OUTPUT
fi
if [[ -n "${{ inputs.filename }}" ]]; then
echo "target-output=--output=dist/${{ inputs.filename }}" >> $GITHUB_OUTPUT
else
echo "target-output=--out-path=dist" >> $GITHUB_OUTPUT
fi
echo "target-node=node${{ inputs.node-version }}" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Validate arch emulation requirements
shell: bash
run: |
if [ "${{ steps.pkg-action-internal.outputs.target-arch }}" != "${{ steps.pkg-action-internal.outputs.runner-arch }}" ]; then
if [ "${{ runner.os }}" != "Linux" ]; then
echo "::error title=Emulation only possible on Linux!::Emulating ${{ steps.pkg-action-internal.outputs.target-arch }} is only possible on Linux runners!"
exit 48
fi
fi
- name: Install node ${{ inputs.node-version }}
uses: actions/setup-node@v4
with:
node-version: ${{ inputs.node-version }}
cache: npm
- name: Install ${{ inputs.pkg }}
shell: bash
run: |
npm install -g ${{ inputs.pkg }}
if pkg --version >/dev/null; then
echo "::notice title=pkg installed::Using version $(pkg --version)"
else
echo "::error title=Cannot run pkg::Cannot seem to find the pkg binary"
fi
- name: Set outputs
shell: bash
id: pkg-action
run: |
echo "::group::Setting outputs"
if [[ -n "${{ inputs.filename }}" ]]; then
file="dist/${{ inputs.filename }}"
else
file="dist/$(node -p "require('./package.json').name")"
fi
if [ "${{ steps.pkg-action-internal.outputs.target-os }}" == "win" ]; then
file="${file}.exe"
fi
echo "file=$file" >> $GITHUB_OUTPUT
if [[ -n "${{ inputs.upload-key }}" ]]; then
echo "artifact-key=${{ inputs.upload-key }}" >> $GITHUB_OUTPUT
else
echo "artifact-key=${{ github.event.repository.name }}-${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }}-${{ github.sha }}" >> $GITHUB_OUTPUT
fi
echo "::endgroup::"
- name: Verify Outputs
shell: bash
run: |
echo "::group::Internal output information"
echo "arch=${{ steps.pkg-action-internal.outputs.target-arch }}"
echo "node=${{ steps.pkg-action-internal.outputs.target-node }}"
echo "os=${{ steps.pkg-action-internal.outputs.target-os }}"
echo "output=${{ steps.pkg-action-internal.outputs.target-output }}"
echo "::endgroup::"
echo "::group::Output information"
echo "artifact-key=${{ steps.pkg-action.outputs.artifact-key }}"
echo "file=${{ steps.pkg-action.outputs.file }}"
echo "::endgroup::"
- name: Run native ${{ steps.pkg-action-internal.outputs.target-arch }} pkg command
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == steps.pkg-action-internal.outputs.runner-arch
shell: bash
env:
RUNNER_DEBUG: ${{ env.RUNNER_DEBUG }}
run: |
if [ "$RUNNER_DEBUG" == 1 ] || [ "$RUNNER_DEBUG" == "1" ]; then
pkg \
--config ${{ inputs.config }} \
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
${{ steps.pkg-action-internal.outputs.target-output }} \
--debug \
${{ inputs.options }} \
${{ inputs.entrypoint }}
else
pkg \
--config ${{ inputs.config }} \
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
${{ steps.pkg-action-internal.outputs.target-output }} \
${{ inputs.options }} \
${{ inputs.entrypoint }}
fi
stat ${{ steps.pkg-action.outputs.file }}
- name: Run emulated ${{ steps.pkg-action-internal.outputs.target-arch }} pkg command
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == 'arm64' && steps.pkg-action-internal.outputs.runner-arch == 'x64'
uses: uraimo/run-on-arch-action@v2
with:
arch: aarch64
# @TODO: eventually we need to get this to work on ubuntu20.04 for build parity but we are using
# 18.04 because it was easier to get working, apparently there is a bug in 20.04s gpg?
distro: ubuntu18.04
githubToken: ${{ github.token }}
# We need to install node and yarn "again" because they dont exist inside our build container
install: |
apt update && apt -y install curl
curl -fsSL "https://deb.nodesource.com/setup_14.x" | bash -
apt-get install -y nodejs
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
apt update && apt -y install yarn
yarn global add ${{ inputs.pkg }} --prefix /usr/local
pkg --version
run: |
pkg \
--config ${{ inputs.config }} \
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
${{ steps.pkg-action-internal.outputs.target-output }} \
${{ inputs.options }} \
${{ inputs.entrypoint }}
stat ${{ steps.pkg-action.outputs.file }}
- name: Upload ${{ steps.pkg-action.outputs.artifact-key }}
if: inputs.test != 'true' && inputs.upload == 'true'
uses: actions/upload-artifact@v4
with:
name: ${{ steps.pkg-action.outputs.artifact-key }}
path: ${{ steps.pkg-action.outputs.file }}
if-no-files-found: error
retention-days: 1