Skip to content

Commit

Permalink
ci: use matrix to reduce build time
Browse files Browse the repository at this point in the history
  • Loading branch information
uubulb committed Sep 26, 2024
1 parent aad063f commit 403b8a4
Show file tree
Hide file tree
Showing 4 changed files with 118 additions and 124 deletions.
128 changes: 101 additions & 27 deletions .github/workflows/agent.yml
Original file line number Diff line number Diff line change
@@ -1,42 +1,116 @@
name: Release
name: Build + Release

on:
push:
tags:
- "v*"
branches:
- main
paths-ignore:
- ".github/workflows/agent.yml"
- ".github/workflows/codeql-analysis.yml"
- ".github/workflows/test.yml"
- ".github/workflows/contributors.yml"
- "README.md"
- ".goreleaser.yml"
pull_request:
branches:
- main

jobs:
deploy:
build:
strategy:
fail-fast: true
matrix:
goos: [linux, windows, darwin, freebsd]
goarch: [amd64, arm64, 386]
include:
- goos: linux
goarch: 386
- goos: linux
goarch: s390x
- goos: linux
goarch: riscv64
- goos: linux
goarch: arm
- goos: linux
goarch: mips
gomips: softfloat
- goos: linux
goarch: mipsle
gomips: softfloat
- goos: freebsd
goarch: arm
exclude:
- goos: darwin
goarch: 386

name: Build artifacts
runs-on: ubuntu-latest
container:
# 1.20 是 Windows 7/8 Server 2008/2012 最后一个支持版本
image: goreleaser/goreleaser-cross:v1.20
env:
GOOS: ${{ matrix.goos }}
GOARCH: ${{ matrix.goarch }}
GOMIPS: ${{ matrix.gomips }}
steps:
- run: |
git config --global --add safe.directory /__w/agent/agent
- uses: actions/checkout@master
- uses: actions/checkout@v4
with:
fetch-depth: 0
- uses: actions/setup-go@v4

- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: "1.20.13"
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
go-version: "1.20.14"

- name: Build Test
if: github.event_name != 'push' || !contains(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: latest
args: release
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
- name: Trigger sync
if: ${{ env.SYNCED == 0 }}
uses: actions/github-script@v6
version: '~> v2'
args: build --single-target --clean --snapshot

- name: Build
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
uses: goreleaser/goreleaser-action@v6
with:
distribution: goreleaser
version: '~> v2'
args: build --single-target --clean

- name: Archive
run: zip -jr dist/nezha-agent_${GOOS}_${GOARCH}.zip dist/*/*

- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
await github.rest.actions.createWorkflowDispatch({
owner: 'nezhahq',
repo: 'agent',
workflow_id: 'sync-release.yml',
ref: 'main'
})
name: nezha-agent_${{ env.GOOS }}_${{ env.GOARCH }}
path: |
./dist/nezha-agent_${{ env.GOOS }}_${{ env.GOARCH }}.zip
release:
runs-on: ubuntu-latest
if: github.event_name == 'push' && contains(github.ref, 'refs/tags/')
needs: build
name: Release
steps:
- name: Download artifacts
uses: actions/download-artifact@v4
with:
path: ./assets

- name: Checksum
run: sha256sum ./assets/*/*.zip | awk -F" |/" '{print $1, $NF}' > checksums.txt

- name: Release
uses: ncipollo/release-action@v1
with:
artifacts: "checksums.txt,assets/*/*.zip"
generateReleaseNotes: true

- name: Trigger sync
env:
GH_REPO: ${{ github.repository }}
GH_TOKEN: ${{ github.token }}
GH_DEBUG: api
run: |
gh workflow run sync-release.yml
36 changes: 0 additions & 36 deletions .github/workflows/test-on-pr.yml

This file was deleted.

27 changes: 14 additions & 13 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,32 @@ on:
- ".github/workflows/contributors.yml"
- "README.md"
- ".goreleaser.yml"
pull_request:
branches:
- main

jobs:
tests:
runs-on: ubuntu-latest
container:
image: goreleaser/goreleaser-cross:v1.20
strategy:
fail-fast: true
matrix:
os: [ubuntu, windows, macos]

runs-on: ${{ matrix.os }}-latest
steps:
- run: |
git config --global --add safe.directory /__w/agent/agent
- uses: actions/checkout@v4
- uses: actions/setup-go@v4
- uses: actions/setup-go@v5
with:
go-version: "1.20.13"
go-version: "1.20.14"

- name: Unit test
# Skip TestCloudflareDetection here, as most IP addresses of Github's action
# runners have been marked as bot.
run: |
go test -skip TestCloudflareDetection -v ./...
#- name: Run Gosec Security Scanner
# if: runner.os == 'Linux'
# run: |
# go install github.com/securego/gosec/v2/cmd/[email protected]
# gosec -exclude=G104 ./...
- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v2
with:
distribution: goreleaser
version: latest
args: build --snapshot
51 changes: 3 additions & 48 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
version: 2
before:
hooks:
- go mod tidy -v
Expand All @@ -11,6 +12,7 @@ builds:
- linux
- windows
- freebsd
- darwin
goarch:
- arm
- arm64
Expand All @@ -27,52 +29,5 @@ builds:
goarch: arm
main: ./cmd/agent
binary: nezha-agent
- id: darwin-amd64
env:
- CGO_ENABLED=1
- CC=o64-clang
- CXX=o64-clang++
ldflags:
- -s -w -X main.version={{.Version}} -X main.arch={{.Arch}}
goos:
- darwin
goarch:
- amd64
main: ./cmd/agent
binary: nezha-agent
- id: darwin-arm64
env:
- CGO_ENABLED=1
- CC=oa64-clang
- CXX=oa64-clang++
ldflags:
- -s -w -X main.version={{.Version}} -X main.arch={{.Arch}}
goos:
- darwin
goarch:
- arm64
main: ./cmd/agent
binary: nezha-agent
universal_binaries:
- name_template: "nezha-agent"
replace: false
checksum:
name_template: "checksums.txt"
snapshot:
name_template: "nezha-agent"
archives:
- name_template: "nezha-agent_{{ .Os }}_{{ .Arch }}"
format: zip
files:
- none*
changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"
- "^chore"
- Merge pull request
- Merge branch
- go mod tidy
- New translations
version_template: "nezha-agent"

0 comments on commit 403b8a4

Please sign in to comment.