151 lines
4.0 KiB
YAML
151 lines
4.0 KiB
YAML
name: Build
|
|
|
|
on:
|
|
push:
|
|
branches:
|
|
- master
|
|
pull_request:
|
|
release:
|
|
types: [published]
|
|
|
|
jobs:
|
|
build:
|
|
runs-on: ubuntu-latest
|
|
env:
|
|
FORCE_JAVASCRIPT_ACTIONS_TO_NODE24: true
|
|
strategy:
|
|
matrix:
|
|
goos: [linux, windows, darwin]
|
|
goarch: [amd64, arm64]
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: '1.26.3'
|
|
cache: true
|
|
|
|
- name: Cache Go build cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cache/go-build
|
|
key: ${{ runner.os }}-go-build-${{ matrix.goos }}-${{ matrix.goarch }}-${{ hashFiles('go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-build-${{ matrix.goos }}-${{ matrix.goarch }}-
|
|
|
|
- name: Install dependencies
|
|
run: go mod download
|
|
|
|
- name: Build
|
|
env:
|
|
GOOS: ${{ matrix.goos }}
|
|
GOARCH: ${{ matrix.goarch }}
|
|
run: |
|
|
BINARY_NAME="tslink"
|
|
if [ "${{ matrix.goos }}" = "windows" ]; then
|
|
BINARY_NAME="${BINARY_NAME}.exe"
|
|
fi
|
|
go build -v -trimpath -buildvcs=false -o "release/${BINARY_NAME}" -ldflags="-s -w" .
|
|
|
|
- name: Compress with UPX
|
|
if: matrix.goos != 'darwin' && !(matrix.goos == 'windows' && matrix.goarch == 'arm64')
|
|
uses: crazy-max/ghaction-upx@v4
|
|
with:
|
|
files: |
|
|
release/tslink*
|
|
args: "-9"
|
|
|
|
- name: Determine version
|
|
id: version
|
|
run: |
|
|
if [ "${{ github.event_name }}" = "release" ]; then
|
|
echo "version=${{ github.ref_name }}" >> $GITHUB_OUTPUT
|
|
else
|
|
echo "version=dev$(date +'%y%m%d')" >> $GITHUB_OUTPUT
|
|
fi
|
|
|
|
- name: Upload Artifact
|
|
uses: actions/upload-artifact@v5
|
|
with:
|
|
name: tslink-${{ steps.version.outputs.version }}-${{ matrix.goos }}_${{ matrix.goarch }}
|
|
path: release/
|
|
|
|
container:
|
|
if: github.event_name == 'release'
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: read
|
|
packages: write
|
|
steps:
|
|
- uses: actions/checkout@v6
|
|
|
|
- name: Set up Go
|
|
uses: actions/setup-go@v6
|
|
with:
|
|
go-version: '1.26.3'
|
|
cache: true
|
|
|
|
- name: Cache Go build cache
|
|
uses: actions/cache@v4
|
|
with:
|
|
path: ~/.cache/go-build
|
|
key: ${{ runner.os }}-go-build-container-${{ hashFiles('go.sum') }}
|
|
restore-keys: |
|
|
${{ runner.os }}-go-build-container-
|
|
|
|
- name: Login to ghcr.io
|
|
uses: docker/login-action@v3
|
|
with:
|
|
registry: ghcr.io
|
|
username: ${{ github.repository_owner }}
|
|
password: ${{ secrets.GITHUB_TOKEN }}
|
|
|
|
- name: Install ko
|
|
run: go install github.com/google/ko@latest
|
|
|
|
- name: Build and push container image
|
|
env:
|
|
KO_DOCKER_REPO: ghcr.io/${{ github.repository_owner }}/tslink
|
|
run: |
|
|
ko build --bare ./ --platform=all \
|
|
-t latest \
|
|
-t ${{ github.ref_name }}
|
|
|
|
release:
|
|
if: github.event_name == 'release'
|
|
needs: build
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
contents: write
|
|
steps:
|
|
- uses: actions/download-artifact@v5
|
|
|
|
- name: Rename binaries
|
|
run: |
|
|
for dir in */; do
|
|
dir=${dir%/}
|
|
plat=$(echo "$dir" | grep -oE '(linux|windows|darwin)_(amd64|arm64)$')
|
|
version=$(echo "$dir" | sed "s/^tslink-//; s/-${plat}$//")
|
|
platform=$(echo "$plat" | tr '_' '-')
|
|
for bin in "$dir"/tslink "$dir"/tslink.exe; do
|
|
if [ -f "$bin" ]; then
|
|
case "$bin" in
|
|
*.exe) mv "$bin" "$dir/tslink-${version}-${platform}.exe" ;;
|
|
*) mv "$bin" "$dir/tslink-${version}-${platform}" ;;
|
|
esac
|
|
fi
|
|
done
|
|
done
|
|
|
|
- name: Generate checksums
|
|
run: |
|
|
find . -type f -name 'tslink-*' -exec sha256sum {} \; > tslink-checksums.txt
|
|
|
|
- name: Upload to release
|
|
uses: softprops/action-gh-release@v2
|
|
with:
|
|
files: |
|
|
*/tslink-*
|
|
tslink-checksums.txt
|