Skip to content

.github: Update setup-go@v5 to adopt node20 #45

.github: Update setup-go@v5 to adopt node20

.github: Update setup-go@v5 to adopt node20 #45

# This is a build and release workflow.
name: Build-and-Release
# Controls when the workflow will run
on:
push:
branches: [ "master" ]
tags: [ "v*.*.*" ]
workflow_call: {}
# Allows you to run this workflow manually from the Actions tab
# workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # for all history and tags
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Set up Go environment values
run: echo "GOPATH=$(go env GOPATH)" >> "$GITHUB_ENV"
- name: Go dependency
run: go mod download
- name: Testing
run: go test -v ./...
- name: Create built path
run: mkdir -p ./build
- name: Cross build for linux, windows (and macOS).
run: bash scripts/cross -o ./build
# Runs built binary (currently linux only)
- name: Run built binary to confirm it works
run: find ./build -name "*_linux_*" -exec "{}" --version ";"
# Need to tar packing to maintain execute permissions.
# See https://github.com/actions/download-artifact#maintaining-file-permissions-and-case-sensitive-files
- name: Packing binary
run: |
chmod +x ./build/*
tar zcf ./cross-binaries.tar.gz ./build/*
- name: Upload built binaries
uses: actions/upload-artifact@v4
with:
name: cross-binaries
path: ./cross-binaries.tar.gz
retention-days: 7 # for 1 week
if-no-files-found: error
# Build mobile library
build-mobile:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # for all history and tags
- name: Create archive path
run: mkdir -p ./build
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Set up Go environment values
run: echo "GOPATH=$(go env GOPATH)" >> "$GITHUB_ENV"
- name: Setup gomobile
uses: './.github/actions/setup-gomobile'
with:
setup-go: false
- name: Show GOPATH
run: |
echo $GOPATH
go env GOPATH
- name: Build mobile binary
run: ./scripts/build-mobile-v2 ./build
- name: Upload built binaries
uses: actions/upload-artifact@v4
with:
name: mobile-binaries
path: ./build
retention-days: 7 # for 1 week
if-no-files-found: error
# Build auto-generated document
build-document:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 5
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0 # for all history and tags
# needs Go since use go generate internally.
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
- name: Generate document
run: bash scripts/gendoc -o build/document
- name: Upload built binaries
uses: actions/upload-artifact@v4
with:
name: generated-document
path: ./build/document
retention-days: 7 # for 1 week
if-no-files-found: error
# Build licenses of dependencies.
build-credits:
# The type of runner that the job will run on
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 1 # just need HEAD files.
# needs Go since use go generate internally.
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version-file: go.mod
cache: true
# needs Go since use go generate internally.
- name: Set up go-licenses
run: go install github.com/google/[email protected]
- name: Generate credits
run: bash scripts/credits -o build
- name: Upload built credits
uses: actions/upload-artifact@v4
with:
name: generated-credits
path: ./build
retention-days: 7 # for 1 week
if-no-files-found: error
# archive artifacts
archive:
runs-on: ubuntu-latest
needs: [build, build-mobile, build-document, build-credits]
timeout-minutes: 5
env:
ARTIFACT_NAME: archive
outputs:
artifact-name: ${{ env.ARTIFACT_NAME }}
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Prepare directory
run: mkdir -p build/document
- name: Download cross-binaries
uses: actions/download-artifact@v4
with:
name: cross-binaries
path: ./
# unpack into ./build/ directory
- name: Unpack cross-binaries
run: |
ls -l .
tar zxf cross-binaries.tar.gz
- name: Download mobile-binaries
uses: actions/download-artifact@v4
with:
name: mobile-binaries
path: build
- name: Download generated documents
uses: actions/download-artifact@v4
with:
name: generated-document
path: build/document
- name: Download generated credits
uses: actions/download-artifact@v4
with:
name: generated-credits
path: build
- name: Show download files
run: echo `ls -R build`
- name: Archive
run: bash scripts/archive build
- name: Upload archive
uses: actions/upload-artifact@v4
with:
name: ${{ env.ARTIFACT_NAME }}
path: ./build/archive
retention-days: 7 # for 1 week
if-no-files-found: error
# release archive if push tags
release:
runs-on: ubuntu-latest
needs: [archive]
if: startsWith(github.ref, 'refs/tags/')
timeout-minutes: 5
steps:
- name: Download archive
uses: actions/download-artifact@v4
with:
name: archive
path: build/archive
- name: Release
uses: softprops/action-gh-release@v1
with:
generate_release_notes: true
files: build/archive/**/*
fail_on_unmatched_files: true