Build backend #4
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Build backend | |
on: | |
workflow_call: | |
secrets: | |
SECRET: | |
required: true | |
workflow_dispatch: | |
pull_request: | |
paths: | |
- backend/** | |
env: | |
SECRET: ${{ secrets.SECRET }} | |
jobs: | |
build-backend-linux: | |
name: "Build backend for linux" | |
runs-on: ubuntu-latest | |
# Runs on alpine because it is easier to staticly link the library | |
container: | |
image: golang:alpine | |
env: | |
BACKEND_DIR: ./backend | |
steps: | |
- name: "Install packages" | |
run: apk update && apk add --no-cache libpcap-dev musl-dev gcc go | |
- uses: actions/checkout@v4 | |
with: | |
sparse-checkout: backend | |
- name: "Create output path" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: mkdir ./output | |
- name: "Load secret" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: | | |
./load-secret.sh "$SECRET" | |
- name: "Build (64 bit)" | |
working-directory: "${{env.BACKEND_DIR}}/cmd" | |
env: | |
CGO_ENABLED: 1 | |
GOARCH: amd64 | |
GOOS: linux | |
run: | | |
go build -ldflags '-linkmode external -extldflags "-static"' -o ../output/backend-linux-64 | |
- name: "Upload build" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-linux | |
path: "${{env.BACKEND_DIR}}/output/*" | |
retention-days: 3 | |
compression-level: 9 | |
build-backend-windows: | |
name: "Build backend for windows" | |
runs-on: windows-latest | |
env: | |
BACKEND_DIR: ".\\backend" | |
steps: | |
- uses: actions/checkout@v3 | |
- name: "Setup Go" | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.19" | |
cache-dependency-path: "${{env.BACKEND_DIR}}\\go.sum" | |
- name: "Load secret" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: | | |
echo "$env:SECRET" > ".\internal\excel\secret.json" | |
echo "$env:SECRET" > ".\internal\excel_adapter\internals\secret.json" | |
echo "$env:SECRET" > ".\pkg\excel\secret.json" | |
echo "$env:SECRET" > ".\pkg\excel_adapter\internals\secret.json" | |
- name: "Create output path" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: mkdir .\output | |
- name: "Build (64 bit)" | |
working-directory: "${{env.BACKEND_DIR}}\\cmd" | |
env: | |
CGO_ENABLED: 1 | |
GOARCH: amd64 | |
GOOS: windows | |
run: | | |
go build -o ..\output\backend-windows-64.exe | |
- name: "Upload build" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-windows | |
path: "${{env.BACKEND_DIR}}\\output\\*" | |
retention-days: 3 | |
compression-level: 9 | |
build-backend-mac: | |
name: "Build backend for macOS" | |
runs-on: macos-latest | |
env: | |
BACKEND_DIR: ./backend | |
steps: | |
- name: "Install packages" | |
run: brew install libpcap | |
- name: "Setup Go" | |
uses: actions/setup-go@v4 | |
with: | |
go-version: "1.19" | |
cache-dependency-path: "${{env.BACKEND_DIR}}/go.sum" | |
- uses: actions/checkout@v3 | |
- name: "Create output path" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: mkdir ./output | |
- name: "Load secret" | |
working-directory: "${{env.BACKEND_DIR}}" | |
run: | | |
./load-secret.sh "$SECRET" | |
- name: "Build (64 bit)" | |
working-directory: "${{env.BACKEND_DIR}}/cmd" | |
env: | |
CGO_ENABLED: 1 | |
GOARCH: amd64 | |
GOOS: darwin | |
run: | | |
go build -o ../output/backend-macos-64 | |
- name: "Build (apple 64 bit)" | |
working-directory: "${{env.BACKEND_DIR}}/cmd" | |
env: | |
CGO_ENABLED: 1 | |
GOARCH: arm64 | |
GOOS: darwin | |
run: | | |
go build -o ../output/backend-macos-m1-64 | |
- name: "Upload build" | |
uses: actions/upload-artifact@v4 | |
with: | |
name: backend-macos | |
path: "${{env.BACKEND_DIR}}/output/*" | |
retention-days: 3 | |
compression-level: 9 |