-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathaction.yml
More file actions
165 lines (152 loc) · 5.87 KB
/
action.yml
File metadata and controls
165 lines (152 loc) · 5.87 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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
name: "Pkg Action"
description: "A GitHub Action for 'compiling' node projects into binaries using vercel/pkg."
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: amd64
node-version:
description: "The node version to package with"
required: false
default: node14
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 on @vercel/pkg to use"
required: false
default: "5.8.0"
test:
description: "Hidden flag for input testing"
default: false
required: false
upload:
description: "Upload the artifacts. Useful if you need to grab them for downstream for things like code signing."
required: false
default: true
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 [ "${{ inputs.arch }}" == "amd64" ]; then
echo "target-arch=x64" >> $GITHUB_OUTPUT
elif [ "${{ inputs.arch }}" == "aarch64" ]; then
echo "target-arch=arm64" >> $GITHUB_OUTPUT
else
echo "target-arch=${{ inputs.arch }}" >> $GITHUB_OUTPUT
fi
echo "target-node=${{ inputs.node-version }}" >> $GITHUB_OUTPUT
echo "::endgroup::"
- name: Install node 16
uses: actions/setup-node@v3
with:
node-version: 16
cache: npm
- name: Install pkg ${{ inputs.pkg }}
shell: bash
run: |
npm install -g pkg@${{ 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 [ "${{ steps.pkg-action-internal.outputs.target-os }}" == "win" ]; then
echo "file=dist/hackmd-cli.exe" >> $GITHUB_OUTPUT
else
echo "file=dist/hackmd-cli" >> $GITHUB_OUTPUT
fi
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
echo "::endgroup::"
- name: Run x64 pkg command
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == 'x64'
shell: bash
run: |
pkg \
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
--out-path dist \
--debug \
${{ inputs.options }} \
${{ inputs.entrypoint }}
stat ${{ steps.pkg-action.outputs.file }}
- name: Run arm64 pkg command
if: inputs.test != 'true' && steps.pkg-action-internal.outputs.target-arch == 'arm64'
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 pkg@${{ inputs.pkg }} --prefix /usr/local
pkg --version
run: |
pkg \
--target=${{ steps.pkg-action-internal.outputs.target-node }}-${{ steps.pkg-action-internal.outputs.target-os }}-${{ steps.pkg-action-internal.outputs.target-arch }} \
--out-path dist \
--debug \
${{ 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@v3
with:
name: ${{ steps.pkg-action.outputs.artifact-key }}
path: ${{ steps.pkg-action.outputs.file }}
if-no-files-found: error
retention-days: 1