-
Notifications
You must be signed in to change notification settings - Fork 7
/
action.yml
260 lines (246 loc) · 8.3 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
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: MPL-2.0
# action name
name: 'build-linux-packages'
# action author
author: 'Kyle Penfound <[email protected]>'
# action description
description: 'Packages binaries using nfpm.'
branding:
icon: package
color: purple
# action input values
inputs:
name:
description: 'Product name.'
default: ''
required: true
arch:
description: 'Build architecture.'
default: ''
required: true
version:
description: 'Product semver version.'
default: ''
required: true
maintainer:
description: 'Maintainer name.'
default: ''
required: false
vendor:
description: 'Vendor name'
default: 'HashiCorp'
required: false
description:
description: 'Product description.'
default: ''
required: false
homepage:
description: 'Product homepage.'
default: ''
required: false
license:
description: 'Product license.'
default: ''
required: false
binary:
description: 'Binary location to package.'
default: ''
required: false
bin_path:
description: 'Path to install the binary at'
default: '/usr/bin'
required: false
file_permissions:
description: 'File permissions applied to all files in the package; specify in yaml/octal format: `0o022`; if empty, permissions are unmodified.'
default: ''
required: false
user_owner:
description: 'The user name or ID that should own the files in the package; e.g.: root'
default: ''
required: false
group_owner:
description: 'The group name or ID that should own the files in the package; e.g.: root'
default: ''
required: false
config_dir:
description: 'Directory of configs in desired filesystem structure.'
default: ''
required: false
deb_depends:
description: 'Comma-separated list of deb dependencies. These prerequistes are mandatory at package install-time.'
default: ''
required: false
deb_recommends:
description: 'Comma-separated list of deb packages recommended to also be installed. These packages are optional at package install-time.'
default: ''
required: false
rpm_depends:
description: 'Comma-separated list of rpm dependencies. These prerequistes are mandatory at package install-time.'
default: ''
required: false
rpm_recommends:
description: 'Comma-separated list of rpm packages recommended to also be installed. These packages are optional at package install-time.'
default: ''
required: false
preinstall:
description: 'Preinstall script location.'
default: ''
required: false
postinstall:
description: 'Postinstall script location.'
default: ''
required: false
preremove:
description: 'Preremove script location.'
default: ''
required: false
postremove:
description: 'Postremove script location.'
default: ''
required: false
nfpm_destination:
description: "Where to install the nFPM binary (default: $HOME/bin/nfpm)"
type: string
default: "$HOME/bin/nfpm"
nfpm_template_destination:
description: "Where to install the nfpm_template binary (default: $HOME/bin/nfpm_template)"
type: string
default: "$HOME/bin/nfpm_template"
nfpm_version:
description: "The version of nFPM to install (default: latest)"
type: string
default: Latest
do_not_override_action_ref:
description: |
Don't ever override this. It's a workaround for a runner bug with composite nested actions.
See: https://github.com/actions/runner/issues/2473#issuecomment-1776051383
default: ${{ github.action_ref }}
runs:
using: composite
steps:
- uses: actions/checkout@692973e3d937129bcbf40652eb9f2f61becf3332 # v4.1.7
with:
path: nfpm_packaging
repository: hashicorp/actions-packaging-linux
ref: ${{ inputs.do_not_override_action_ref }}
- name: Install nFPM
working-directory: nfpm_packaging
shell: bash
env:
GH_TOKEN: ${{ github.token }}
NFPM_DEST: ${{ inputs.nfpm_destination }}
NFPM_VERSION: ${{ inputs.nfpm_version }}
run: |
VERSION=$(gh release list -R goreleaser/nfpm --exclude-drafts --exclude-pre-releases | grep "$NFPM_VERSION" | cut -f1)
mkdir -p "$(dirname "$NFPM_DEST")"
DESTINATION="$(readlink -f $NFPM_DEST)"
DESTINATION_DIR="$(dirname "$DESTINATION")"
echo "$DESTINATION_DIR" >> "$GITHUB_PATH"
case "$RUNNER_ARCH" in
ARM)
printf "nfpm is not built for ARM, please build packages on X86, X64, or ARM64 runners" 1>&2
exit 1
;;
X86)
printf "nfpm is not built for X86, please build packages on X64 or ARM64 runners" 1>&2
exit 1
;;
ARM64)
ARCH="arm64"
;;
X64)
ARCH="x86_64"
;;
esac
OS="$RUNNER_OS"
case "$RUNNER_OS" in
macOS)
OS="Darwin"
;;
Windows)
printf "this action must be run on Linux or macOS runner" 1>&2
exit 1
;;
esac
mkdir -p tmp/nfpm
pushd tmp/nfpm || exit 1
gh release download "$VERSION" -p "nfpm_*_${OS}_${ARCH}.tar.gz" -O nfpm.tgz -R goreleaser/nfpm
tar -xvf nfpm.tgz
mv nfpm "$DESTINATION"
popd || exit 1
#rm -rf tmp/nfpm
- name: Check for a Go compiler
id: check_go
shell: bash
run: |
go_installed="false"
if type go >/dev/null 2>&1; then
go_installed="true"
fi
echo "is_installed=${go_installed}" | tee -a "$GITHUB_OUTPUT"
- if: steps.check_go.is_installed == 'false'
uses: actions/setup-go@0a12ed9d6a96ab950c8f026ed9f722fe0da7ef32 # v5.0.2
with:
cache: false
go-version-file: go.mod
- name: Build nfpm_template binary
shell: bash
working-directory: nfpm_packaging
env:
TPL_DEST: ${{ inputs.nfpm_template_destination }}
run: |
mkdir -p "$(dirname "$TPL_DEST")"
DESTINATION="$(readlink -f $TPL_DEST)"
DESTINATION_DIR="$(dirname "$DESTINATION")"
echo "$DESTINATION_DIR" >> "$GITHUB_PATH"
go build -o nfpm_template .
mv nfpm_template "$DESTINATION"
- name: Package binary
shell: bash
env:
# These environment variables are used by the template program that generates the nfpm config
INPUT_NAME: ${{ inputs.name }}
INPUT_ARCH: ${{ inputs.arch }}
INPUT_VERSION: ${{ inputs.version }}
INPUT_MAINTAINER: ${{ inputs.maintainer }}
INPUT_VENDOR: ${{ inputs.vendor }}
INPUT_DESCRIPTION: ${{ inputs.description }}
INPUT_HOMEPAGE: ${{ inputs.homepage }}
INPUT_LICENSE: ${{ inputs.license }}
INPUT_DEPENDS: ${{ inputs.depends }}
INPUT_BINARY: ${{ inputs.binary }}
INPUT_BIN_PATH: ${{ inputs.bin_path }}
INPUT_FILEPERMISSIONS: ${{ inputs.file_permissions }}
INPUT_USEROWNER: ${{ inputs.user_owner }}
INPUT_GROUPOWNER: ${{ inputs.group_owner }}
INPUT_CONFIG_DIR: ${{ inputs.config_dir }}
INPUT_PREINSTALL: ${{ inputs.preinstall }}
INPUT_POSTINSTALL: ${{ inputs.postinstall }}
INPUT_PREREMOVE: ${{ inputs.preremove }}
INPUT_POSTREMOVE: ${{ inputs.postremove }}
INPUT_DEB_DEPENDS: ${{ inputs.deb_depends }}
INPUT_DEB_RECOMMENDS: ${{ inputs.deb_recommends }}
INPUT_RPM_DEPENDS: ${{ inputs.rpm_depends }}
INPUT_RPM_RECOMMENDS: ${{ inputs.rpm_recommends }}
run: |
if ! fileo=$(file "$INPUT_BINARY"); then
printf "could not find binary: %s\n" "$(pwd)"
ls
exit 1
else
printf "packaging binary %s\n" "$fileo"
fi
mkdir -p ./out
package() { local pkg_type="$1" deps="${2:-}" recs="${3:-}"
local config_file
config_file="nfpm_${pkg_type}_config.yml"
if ! INPUT_DEPENDS="$deps" INPUT_RECOMMENDS="$recs" nfpm_template > "$config_file"; then
printf "failed to executing nfpm_template for %s\n" "$pkg_type"
exit 1
fi
cat "$config_file"
nfpm package -f "$config_file" -p "$pkg_type" -t ./out/
}
package rpm "$INPUT_RPM_DEPENDS" "$INPUT_RPM_RECOMMENDS"
package deb "$INPUT_DEB_DEPENDS" "$INPUT_DEB_RECOMMENDS"