Skip to content

<v0.1.0> Build and release #54

<v0.1.0> Build and release

<v0.1.0> Build and release #54

Workflow file for this run

# This workflow will build a golang project
# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-go
name: Build and release
run-name: <${{ github.ref_name }}> Build and release
on:
push:
tags:
- 'v*.*.*'
jobs:
context:
name: Dump context
runs-on: ubuntu-latest
steps:
- name: Dump GitHub context
env:
GITHUB_CONTEXT: ${{ toJson(github) }}
run: echo "$GITHUB_CONTEXT"
- name: Dump job context
env:
JOB_CONTEXT: ${{ toJson(job) }}
run: echo "$JOB_CONTEXT"
- name: Dump steps context
env:
STEPS_CONTEXT: ${{ toJson(steps) }}
run: echo "$STEPS_CONTEXT"
- name: Dump runner context
env:
RUNNER_CONTEXT: ${{ toJson(runner) }}
run: echo "$RUNNER_CONTEXT"
- name: Dump strategy context
env:
STRATEGY_CONTEXT: ${{ toJson(strategy) }}
run: echo "$STRATEGY_CONTEXT"
- name: Dump matrix context
env:
MATRIX_CONTEXT: ${{ toJson(matrix) }}
run: echo "$MATRIX_CONTEXT"
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Exit if not on master branch
if: github.event.base_ref && endsWith(github.event.base_ref, 'master') == false
run: exit 1
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- run: sudo apt-get update -y && sudo apt-get install tree zip -y
- name: Show directory tree before build
run: tree
- name: Set up Go
uses: actions/setup-go@v4
with:
go-version: '1.21.5'
- name: Test
run: go test -v ./...
- name: Create artifacts directory
run: mkdir artifacts
- uses: actions/setup-python@v5
with:
python-version: '3.11'
- name: Build for different platforms
run: |
PLATFORMS=($(go tool dist list | grep -E '^windows|^linux/(amd64|arm|386)|^darwin'))
SUPPORTED_EXTENSIONS=$(python scripts/compute_supported_extensions.py)
LDFLAGS="-X 'main.supported_extensions=$SUPPORTED_EXTENSIONS' -X 'main.version=$VERSION'"
for PLATFORM in "${PLATFORMS[@]}"
do
arr=(${PLATFORM//\// })
echo "${arr[0]}/${arr[1]}"
GOOS=${arr[0]} GOARCH=${arr[1]} FLAGS=$LDFLAGS bash -c '
go build -o out/ -ldflags "$FLAGS" &&
echo "$LDFLAGS" &&
cp {LICENSE,README.md} out/ &&
zip -j artifacts/${{ github.event.repository.name }}_$GOOS-$GOARCH.zip out/*
rm -rf out/*'
done
- name: Show directory tree after build
run: tree
- name: Upload Build Artifact
uses: actions/[email protected]
with:
name: build-artifact
path: ./artifacts
if-no-files-found: error
release:
name: Github release
permissions:
contents: write
runs-on: ubuntu-latest
needs: build
steps:
- name: Write release version
run: |
VERSION=${GITHUB_REF_NAME#v}
echo Version: $VERSION
echo "VERSION=$VERSION" >> $GITHUB_ENV
- name: Download Build Artifact
uses: actions/[email protected]
with:
name: build-artifact
path: ./artifacts
- name: Show directory tree before release
run: tree
- name: Create Git Release
uses: softprops/action-gh-release@v1
if: startsWith(github.ref, 'refs/tags/')
with:
files: ./artifacts/*
fail_on_unmatched_files: true
body: |
This is the release for ${{ github.ref_name }}