-
Notifications
You must be signed in to change notification settings - Fork 2
206 lines (181 loc) · 8.96 KB
/
build.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
name: BuildPublish
on:
push:
branches: [ "main" ]
pull_request:
branches: [ "main" ]
workflow_dispatch:
jobs:
linuxwindows:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.extract_version.outputs.version }}
name: Ubuntu runner for Linux and Windows
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true
- name: Check out code
uses: actions/checkout@v3
- name: Install prereqs
run: sudo apt-get install build-essential devscripts debhelper dh-make
shell: bash
- name: Extract version from root.go
id: extract_version
run: |
VERSION=$(grep 'Version[[:space:]]*string' cmd/root.go | awk -F'"' '{ print $2 }')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "::set-output name=version::${VERSION}"
echo "VERSION=$VERSION"
shell: bash
- name: Build Windows binary
env:
GOOS: windows
GOARCH: amd64
run: |
go build -ldflags "-s -w -X cmd.Version=${{ env.VERSION }}" -o ./opnsense.exe
- name: Build Linux binary
env:
GOOS: linux
GOARCH: amd64
CGO_ENABLED: 0
run: |
go build -ldflags "-s -w -X cmd.Version=${{ env.VERSION }}" -o ./opnsense-linux
- name: package linux binary into .deb
run: |
mkdir -p opnsense/DEBIAN && mkdir -p opnsense/usr/local/bin
chmod +x ./opnsense-linux
cp ./opnsense-linux opnsense/usr/local/bin/opnsense
echo -e "Package: opnsense-cli\nVersion: ${VERSION}\nSection: base\nPriority: optional\nArchitecture: amd64\nMaintainer: Miha Kralj <[email protected]>\nDescription: opnsense is a command-line utility for managing, configuring, and monitoring OPNsense firewall systems. It facilitates non-GUI administration, both directly in the shell and remotely via an SSH tunnel. All interactions with OPNsense utilize the same mechanisms as the Web GUI, including staged modifications of config.xml and execution of available configd commands." > opnsense/DEBIAN/control
dpkg-deb -Zxz --build opnsense
shell: bash
- name: Upload all artifacts
uses: actions/upload-artifact@v3
with:
name: bin
path: |
./opnsense.deb
./opnsense.exe
macbsd:
runs-on: macos-12
name: MacOS runner with FreeBSD virtualbox
steps:
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.20'
check-latest: true
- name: Check out code
uses: actions/checkout@v3
- name: Extract version from root.go
id: extract_version
run: |
VERSION=$(grep 'Version[[:space:]]*string' cmd/root.go | awk -F'"' '{ print $2 }')
echo "VERSION=$VERSION" >> $GITHUB_ENV
echo "::set-output name=version::${VERSION}"
echo "VERSION=$VERSION"
shell: bash
- name: Select XCode
uses: BoundfoxStudios/action-xcode-select@v1
with:
version: 14.2
- name: Import app certificate
run: |
security create-keychain -p ${{ secrets.APPLE_CERTPWD }} build.keychain
security default-keychain -s build.keychain
security unlock-keychain -p ${{ secrets.APPLE_CERTPWD }} build.keychain
echo "${{ secrets.APPLE_APPCERT }}" | base64 --decode -o apple_certificate.p12
security import apple_certificate.p12 -k build.keychain -P ${{ secrets.APPLE_CERTPWD }} -T /usr/bin/codesign
security set-key-partition-list -S apple-tool:,apple:,codesign: -s -k ${{ secrets.APPLE_CERTPWD }} build.keychain
echo "${{ secrets.APPLE_INSTCERT }}" | base64 --decode -o apple_instcert.p12
security import apple_instcert.p12 -k build.keychain -P ${{ secrets.APPLE_CERTPWD }} -T /usr/bin/productsign
security set-key-partition-list -S apple-tool:,apple:,productsign: -s -k ${{ secrets.APPLE_CERTPWD }} build.keychain
security find-identity -v
- name: Build macOS binary
env:
GOOS: darwin
GOARCH: amd64
run: |
mkdir -p ./opnsense/usr/local/bin
go build -ldflags "-s -w -X cmd.Version=${{ env.VERSION }}" -o ./opnsense/usr/local/bin/opnsense
chmod +x ./opnsense/usr/local/bin/opnsense
- name: sign binary
run: |
APPSIGNING_IDENTITY=$(security find-identity -v -p codesigning | grep "Application" | awk '{print $2}')
codesign --deep --force --verify --verbose --timestamp --options runtime --sign $APPSIGNING_IDENTITY ./opnsense/usr/local/bin/opnsense
cp ./opnsense/usr/local/bin/opnsense ./opnsense-macos
- name: build component package
run: |
pkgbuild --root ./opnsense --identifier com.github.mihakralj.opnsense --version "${{ env.VERSION }}" ./component-opnsense.pkg
productbuild --synthesize --package ./component-opnsense.pkg ./distribution.xml
productbuild --distribution ./distribution.xml --package-path ./ ./opnsense.pkg
- name: sign the distribution package
run: |
INSTSIGNING_IDENTITY=$(security find-identity -v -p basic | grep "Installer" | awk '{print $2}')
productsign --keychain build.keychain --sign $INSTSIGNING_IDENTITY ./opnsense.pkg ./signed-opnsense.pkg
mv ./signed-opnsense.pkg ./opnsense-macos.pkg
- name: notarize
run: |
xcrun notarytool submit ./opnsense-macos.pkg --wait --apple-id ${{ secrets.APPLE_NOTARIZATION_USERNAME }} --password ${{ secrets.APPLE_NOTARIZATION_PASSWORD }} --team-id ${{ secrets.APPLE_TEAM_NAME }}
xcrun stapler staple ./opnsense-macos.pkg
- name: Compile .txz package in FreeBSD
id: compile
uses: vmactions/[email protected]
with:
envs: 'VERSION=${{ env.VERSION }}'
usesh: true
prepare: |
pkg install -y curl wget
name=$(curl -s https://go.dev/dl/ | grep 'freebsd-amd64' | sed -n 's/.*href="\([^"]*\)".*/\1/p' | head -n 1 | xargs basename)
wget -q "https://dl.google.com/go/$name"
tar -C /usr/local -xzf "$name"
run: |
mkdir ~/.gopkg
export GOPATH=/root/.gopkg
export PATH=$PATH:/usr/local/go/bin:/root/.gopkg/bin
mkdir -p /Users/runner/work/opnsense-cli/opnsense-cli/work-dir/usr/local/bin
go build -gcflags='-trimpath' -ldflags="-s -w -X cmd.Version=${VERSION}" -o /Users/runner/work/opnsense-cli/opnsense-cli/work-dir/usr/local/bin/opnsense opnsense.go
cp /Users/runner/work/opnsense-cli/opnsense-cli/work-dir/usr/local/bin/opnsense /usr/local/bin/opnsense
checksum=$(sha256 -q /Users/runner/work/opnsense-cli/opnsense-cli/work-dir/usr/local/bin/opnsense)
flatsize=$(stat -f%z /Users/runner/work/opnsense-cli/opnsense-cli/work-dir/usr/local/bin/opnsense)
echo "/usr/local/bin/opnsense: ${checksum}" > /Users/runner/work/opnsense-cli/opnsense-cli/sha256checksum
echo "/usr/local/bin/opnsense" > /Users/runner/work/opnsense-cli/opnsense-cli/plist
echo -e "name: opnsense-cli\nversion: ${VERSION}\norigin: net-mgmt/opnsense-cli\ncomment: \"CLI to manage and monitor OPNsense firewall configuration, check status, change settings, and execute commands.\"\ndesc: \"opnsense is a command-line utility for managing, configuring, and monitoring OPNsense firewall systems. It facilitates non-GUI administration, both directly in the shell and remotely via an SSH tunnel. All interactions with OPNsense utilize the same mechanisms as the Web GUI, including staged modifications of config.xml and execution of available configd commands.\"\nmaintainer: \"[email protected]\"\nwww: \"https://github.com/mihakralj/opnsense-cli\"\nabi: \"FreeBSD:*:amd64\"\nprefix: /usr/local\nflatsize: ${flatsize}" > /Users/runner/work/opnsense-cli/opnsense-cli/manifest
echo -e "files: {\n \"/usr/local/bin/opnsense\": \"${checksum}\",\n}" >> /Users/runner/work/opnsense-cli/opnsense-cli/manifest
pkg create -M /Users/runner/work/opnsense-cli/opnsense-cli/manifest -o /Users/runner/work/opnsense-cli/opnsense-cli/ -f txz
ls -l
- name: Upload all artifacts
uses: actions/upload-artifact@v3
with:
name: bin
path: |
./opnsense-macos
./opnsense*.txz
./opnsense.pkg
./opnsense-cli-*.pkg
release:
needs: [linuxwindows, macbsd]
runs-on: ubuntu-latest
steps:
- name: Download all artifacts
uses: actions/download-artifact@v2
with:
path: .
- name: list downloaded files
run: |
ls -l ./bin
shell: bash
- name: Create Beta Release and Upload Assets
id: create_release
uses: softprops/action-gh-release@v1
with:
prerelease: true
draft: false
tag_name: ${{ env.VERSION }}
name: opnsense-cli ${{ env.VERSION }}
files: ./bin/opnsense*
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
VERSION: ${{ needs.linuxwindows.outputs.version }}