Skip to content

Commit 285aa5b

Browse files
committed
feat: fork pkg-action
1 parent e56dd2d commit 285aa5b

File tree

2 files changed

+167
-2
lines changed

2 files changed

+167
-2
lines changed

.github/actions/pkg-action/action.yml

+165
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,165 @@
1+
name: "Pkg Action"
2+
description: "A GitHub Action for 'compiling' node projects into binaries using vercel/pkg."
3+
branding:
4+
color: purple
5+
icon: package
6+
inputs:
7+
# Required
8+
entrypoint:
9+
description: "The binary entrypoint path"
10+
required: true
11+
12+
# Optional
13+
arch:
14+
description: "The architecture to build for x64|amd64|aarch64|arm64"
15+
required: false
16+
default: amd64
17+
node-version:
18+
description: "The node version to package with"
19+
required: false
20+
default: node14
21+
options:
22+
description: "Additional options and flags to pass into pkg"
23+
required: false
24+
os:
25+
description: "The operating system to build for win|linux|macos"
26+
required: false
27+
default: ${{ runner.os }}
28+
pkg:
29+
description: "The version on @vercel/pkg to use"
30+
required: false
31+
default: "5.8.0"
32+
test:
33+
description: "Hidden flag for input testing"
34+
default: false
35+
required: false
36+
upload:
37+
description: "Upload the artifacts. Useful if you need to grab them for downstream for things like code signing."
38+
required: false
39+
default: true
40+
41+
outputs:
42+
file:
43+
description: "The path to the generated binary."
44+
value: ${{ steps.pkg-action.outputs.file }}
45+
artifact-key:
46+
description: "The artifact upload key."
47+
value: ${{ steps.pkg-action.outputs.artifact-key }}
48+
49+
runs:
50+
using: composite
51+
steps:
52+
- name: Validate required inputs
53+
shell: bash
54+
run: |
55+
echo "::group::Ensure entrypoint is set"
56+
if [ "${{ inputs.entrypoint }}" == "" ]; then
57+
echo "::error title=Entrypoint is not set!::You must specify an entrypoint file in order to run this shit."
58+
exit 47
59+
fi
60+
echo "::endgroup::"
61+
62+
- name: Set internal outputs
63+
shell: bash
64+
id: pkg-action-internal
65+
run: |
66+
echo "::group::Setting internal outputs"
67+
if [ "${{ inputs.os }}" == "Linux" ]; then
68+
echo "target-os=linux" >> $GITHUB_OUTPUT
69+
elif [ "${{ inputs.os }}" == "macOS" ]; then
70+
echo "target-os=macos" >> $GITHUB_OUTPUT
71+
elif [ "${{ inputs.os }}" == "Windows" ]; then
72+
echo "target-os=win" >> $GITHUB_OUTPUT
73+
else
74+
echo "target-os=${{ inputs.os }}" >> $GITHUB_OUTPUT
75+
fi
76+
77+
if [ "${{ inputs.arch }}" == "amd64" ]; then
78+
echo "target-arch=x64" >> $GITHUB_OUTPUT
79+
elif [ "${{ inputs.arch }}" == "aarch64" ]; then
80+
echo "target-arch=arm64" >> $GITHUB_OUTPUT
81+
else
82+
echo "target-arch=${{ inputs.arch }}" >> $GITHUB_OUTPUT
83+
fi
84+
85+
echo "target-node=${{ inputs.node-version }}" >> $GITHUB_OUTPUT
86+
echo "::endgroup::"
87+
88+
- name: Install node 16
89+
uses: actions/setup-node@v3
90+
with:
91+
node-version: 16
92+
cache: npm
93+
94+
- name: Install pkg ${{ inputs.pkg }}
95+
shell: bash
96+
run: |
97+
npm install -g pkg@${{ inputs.pkg }}
98+
if pkg --version >/dev/null; then
99+
echo "::notice title=pkg installed::Using version $(pkg --version)"
100+
else
101+
echo "::error title=Cannot run pkg::Cannot seem to find the pkg binary"
102+
fi
103+
104+
- name: Set outputs
105+
shell: bash
106+
id: pkg-action
107+
run: |
108+
echo "::group::Setting outputs"
109+
if [ "${{ steps.pkg-action-internal.outputs.target-os }}" == "win" ]; then
110+
echo "file=dist/$(node -p "require('./package.json').name").exe" >> $GITHUB_OUTPUT
111+
else
112+
echo "file=dist/$(node -p "require('./package.json').name")" >> $GITHUB_OUTPUT
113+
fi
114+
115+
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
116+
echo "::endgroup::"
117+
118+
- name: Run x64 pkg command
119+
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == 'x64'
120+
shell: bash
121+
run: |
122+
pkg \
123+
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
124+
--out-path dist \
125+
--debug \
126+
${{ inputs.options }} \
127+
${{ inputs.entrypoint }}
128+
stat ${{ steps.pkg-action.outputs.file }}
129+
130+
- name: Run arm64 pkg command
131+
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == 'arm64'
132+
uses: uraimo/run-on-arch-action@v2
133+
with:
134+
arch: aarch64
135+
# @TODO: eventually we need to get this to work on ubuntu20.04 for build parity but we are using
136+
# 18.04 because it was easier to get working, apparently there is a bug in 20.04s gpg?
137+
distro: ubuntu18.04
138+
githubToken: ${{ github.token }}
139+
# We need to install node and yarn "again" because they dont exist inside our build container
140+
install: |
141+
apt update && apt -y install curl
142+
curl -fsSL https://deb.nodesource.com/setup_14.x | bash -
143+
apt-get install -y nodejs
144+
curl -sL https://dl.yarnpkg.com/debian/pubkey.gpg | apt-key add -
145+
echo "deb https://dl.yarnpkg.com/debian/ stable main" | tee /etc/apt/sources.list.d/yarn.list
146+
apt update && apt -y install yarn
147+
yarn global add pkg@${{ inputs.pkg }} --prefix /usr/local
148+
pkg --version
149+
run: |
150+
pkg \
151+
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
152+
--out-path dist \
153+
--debug \
154+
${{ inputs.options }} \
155+
${{ inputs.entrypoint }}
156+
stat ${{ steps.pkg-action.outputs.file }}
157+
158+
- name: Upload ${{ steps.pkg-action.outputs.artifact-key }}
159+
if: inputs.test != 'true' && inputs.upload == 'true'
160+
uses: actions/upload-artifact@v3
161+
with:
162+
name: ${{ steps.pkg-action.outputs.artifact-key }}
163+
path: ${{ steps.pkg-action.outputs.file }}
164+
if-no-files-found: error
165+
retention-days: 1

.github/workflows/release.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,9 @@ jobs:
2626

2727
- name: Package Node.js binary with pkg
2828
id: pkg-action
29-
uses: lando/pkg-action@v2
29+
uses: ./.github/actions/pkg-action
3030
with:
31-
entrypoint: ./bin/run
31+
entrypoint: .
3232
arch: ${{ matrix.arch }}
3333
node-version: ${{ matrix.node-version }}
3434
os: ${{ matrix.os }}

0 commit comments

Comments
 (0)