Skip to content

Commit

Permalink
Merge pull request #24 from lemois-1337/2023_github_workflow
Browse files Browse the repository at this point in the history
[Fix] GitHub workflow for automatic and deterministic builds
  • Loading branch information
lemois-1337 committed Dec 25, 2023
2 parents 561ec97 + 7421617 commit 3909ca2
Showing 1 changed file with 64 additions and 26 deletions.
90 changes: 64 additions & 26 deletions .github/workflows/deploy.yaml
Expand Up @@ -9,57 +9,95 @@ jobs:
strategy:
fail-fast: false
matrix:
os: [ ubuntu-latest, windows-latest, macos-latest ]
name: Building, ${{ matrix.os }}
include:
- os: ubuntu-latest
TARGET: linux/x86_64
- os: ubuntu-latest
TARGET: linux/aarch64
- os: ubuntu-latest
TARGET: windows/x64
- os: macos-latest
TARGET: macos/x64
name: Building, ${{ matrix.TARGET }}
steps:
- name: Fix CRLF on Windows
if: runner.os == 'Windows'
run: git config --global core.autocrlf false

- name: Check out code into the Go module directory
uses: actions/checkout@v2


- name: Setup Go
uses: actions/setup-go@v2
with:
go-version: 1.21

- name: Build on Linux
if: runner.os == 'Linux'
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
- name: Update sources
if: matrix.TARGET == 'linux/aarch64' || matrix.TARGET == 'windows/x64'
run: sudo apt-get update -y

- name: Install compilers
if: matrix.TARGET == 'linux/aarch64' || matrix.TARGET == 'windows/x64'
run: sudo apt-get install gcc-aarch64-linux-gnu gcc-mingw-w64-x86-64-win32 -y

- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'linux/x86_64'
run: |
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
archive="bin/karlsend-${{ github.event.release.tag_name }}-linux-x86_64.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-linux-x86_64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'linux/aarch64'
env:
CGO_ENABLED: 1
CC: aarch64-linux-gnu-gcc
GOOS: linux
GOARCH: arm64
run: |
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
archive="bin/karlsend-${{ github.event.release.tag_name }}-linux.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-linux.zip"
archive="bin/karlsend-${{ github.event.release.tag_name }}-linux-aarch64.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-linux-aarch64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on Windows
if: runner.os == 'Windows'
shell: bash
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'windows/x64'
env:
CGO_ENABLED: 1
CC: x86_64-w64-mingw32-gcc
GOOS: windows
GOARCH: amd64
run: |
go build -v -ldflags="-s -w" -o bin/ . ./cmd/...
archive="bin/karlsend-${{ github.event.release.tag_name }}-win64.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-win64.zip"
powershell "Compress-Archive bin/* \"${archive}\""
# `-extldflags=-static` - means static link everything,
# `-tags netgo,osusergo` means use pure go replacements for "os/user" and "net"
# `-s -w` strips the binary to produce smaller size binaries
go build -v -ldflags="-s -w -extldflags=-static" -tags netgo,osusergo -o ./bin/ . ./cmd/...
archive="bin/karlsend-${{ github.event.release.tag_name }}-windows-x64.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-windows-x64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Build on MacOS
if: runner.os == 'macOS'
- name: Build on Linux for ${{ matrix.TARGET }}
if: matrix.TARGET == 'macos/x64'
run: |
go build -v -ldflags="-s -w" -o ./bin/ . ./cmd/...
archive="bin/karlsend-${{ github.event.release.tag_name }}-osx.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-osx.zip"
archive="bin/karlsend-${{ github.event.release.tag_name }}-macos-x64.zip"
asset_name="karlsend-${{ github.event.release.tag_name }}-macos-x64.zip"
zip -r "${archive}" ./bin/*
echo "archive=${archive}" >> $GITHUB_ENV
echo "asset_name=${asset_name}" >> $GITHUB_ENV
- name: Upload release asset
uses: actions/upload-release-asset@v1
env:
Expand Down

0 comments on commit 3909ca2

Please sign in to comment.