Skip to content

Commit

Permalink
Take advantage of matrix builds
Browse files Browse the repository at this point in the history
  • Loading branch information
makotom committed Jul 27, 2021
1 parent b43ccb8 commit 994d817
Show file tree
Hide file tree
Showing 2 changed files with 119 additions and 40 deletions.
150 changes: 110 additions & 40 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,60 @@ version: 2.1

commands:
smoke-test-common-steps:
parameters:
goos:
type: string
goarch:
type: string
steps:
- attach_workspace:
at: .
- when:
condition:
or:
- equal:
- << parameters.goos >>
- linux
- equal:
- << parameters.goos >>
- android
steps:
- run:
name: Extract tarball
command: |
. BUILD_NAME
tar -xf cfspeed-${BUILD_NAME}-<< parameters.goos >>-<< parameters.goarch >>.tar.gz
- when:
condition:
equal:
- << parameters.goos >>
- windows
steps:
- run:
name: Extract zip
command: |
$ProgressPreference = "SilentlyContinue"
$BuildName = $(& bash -c '. BUILD_NAME; echo $BUILD_NAME')
Expand-Archive cfspeed-${BuildName}-<< parameters.goos >>-<< parameters.goarch >>.zip .
- unless:
condition:
or:
- equal:
- << parameters.goos >>
- linux
- equal:
- << parameters.goos >>
- android
- equal:
- << parameters.goos >>
- windows
steps:
- run:
name: Extract zip
command: |
. BUILD_NAME
unzip cfspeed-${BUILD_NAME}-<< parameters.goos >>-<< parameters.goarch >>.zip
- run:
name: Show version
command: ./cfspeed --version
Expand All @@ -11,30 +64,47 @@ commands:
command: ./cfspeed

jobs:
determine-build-name:
docker:
- image: debian:buster-slim
steps:
- run:
name: Determine build name
command: |
echo export BUILD_NAME=\"0.1.${CIRCLE_BUILD_NUM}-${CIRCLE_SHA1:0:7}\" | tee -a BUILD_NAME
- persist_to_workspace:
root: .
paths:
- BUILD_NAME

build:
docker:
- image: golang:1.17-rc
parameters:
goos:
type: string
goarch:
type: string
steps:
- checkout
- run:
name: Install dependencies
command: |
apt update
apt install -y zip
- attach_workspace:
at: dist
- run:
name: Determine build name
command: |
mkdir -p dist
echo export BUILD_NAME=\"0.1.${CIRCLE_BUILD_NUM}-${CIRCLE_SHA1:0:7}\" | tee -a dist/BUILD_NAME
- run:
name: Build all
name: Build
command: |
. dist/BUILD_NAME
./build-and-pack-all.sh
GOOS_LIST_OVERRIDE='("<< parameters.goos >>")' GOARCH_LIST_OVERRIDE='("<< parameters.goarch >>")' ./build-and-pack-all.sh
- persist_to_workspace:
root: dist
paths:
- .
- << parameters.goos >>/<< parameters.goarch >>
- "*.tar.gz"
- "*.zip"
- store_artifacts:
path: dist
destination: /
Expand All @@ -51,50 +121,36 @@ jobs:
docker:
- image: archlinux
steps:
- attach_workspace:
at: .
- run:
name: Extract tarball
command: tar -xf cfspeed-*-linux-amd64.tar.gz
- smoke-test-common-steps
- smoke-test-common-steps:
goos: linux
goarch: amd64

smoke-test-linux-arm64:
machine:
image: ubuntu-2004:202101-01
resource_class: arm.medium
steps:
- attach_workspace:
at: .
- run:
name: Extract tarball
command: tar -xf cfspeed-*-linux-arm64.tar.gz
- smoke-test-common-steps
- smoke-test-common-steps:
goos: linux
goarch: arm64

smoke-test-windows-amd64:
machine:
image: windows-server-2019-vs2019:stable
resource_class: windows.medium
shell: powershell.exe
steps:
- attach_workspace:
at: .
- run:
name: Extract zip
command: |
$ProgressPreference = "SilentlyContinue"
Expand-Archive cfspeed-*-windows-amd64.zip .
- smoke-test-common-steps
- smoke-test-common-steps:
goos: windows
goarch: amd64

smoke-test-darwin-amd64:
macos:
xcode: 12.4.0
steps:
- attach_workspace:
at: .
- run:
name: Extract zip
command: unzip cfspeed-*-darwin-amd64.zip
- smoke-test-common-steps
- smoke-test-common-steps:
goos: darwin
goarch: amd64

release:
docker:
Expand All @@ -112,25 +168,39 @@ jobs:
name: Create a release
command: |
. BUILD_NAME
gh release create -R ${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} -t "${BUILD_NAME}" -n "" "${BUILD_NAME}" *.tar.* *.zip
gh release create -R ${CIRCLE_PROJECT_USERNAME}/${CIRCLE_PROJECT_REPONAME} -t "${BUILD_NAME}" -n "" "${BUILD_NAME}" *.tar.gz *.zip
workflows:
build-test-release:
jobs:
- build
- determine-build-name
- build:
name: build-<< matrix.goos >>-<< matrix.goarch >>
matrix:
parameters:
goos:
- linux
- windows
- darwin
- android
goarch:
- amd64
- arm64
requires:
- determine-build-name
- go-test
- smoke-test-linux-amd64:
requires:
- build
- build-linux-amd64
- smoke-test-linux-arm64:
requires:
- build
- build-linux-arm64
- smoke-test-windows-amd64:
requires:
- build
- build-windows-amd64
- smoke-test-darwin-amd64:
requires:
- build
- build-darwin-amd64
- release:
requires:
- build
Expand Down
9 changes: 9 additions & 0 deletions build-and-pack-all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ GOARCH_LIST=("amd64" "arm64")
BUILD_NAME=${BUILD_NAME:-"git"}
BUILD_ANNOTATION="$(date --iso-8601=seconds)"

if [ "${GOOS_LIST_OVERRIDE:-}" ]
then
eval GOOS_LIST="${GOOS_LIST_OVERRIDE}"
fi
if [ "${GOARCH_LIST_OVERRIDE:-}" ]
then
eval GOARCH_LIST="${GOARCH_LIST_OVERRIDE}"
fi

build_gc() {
goos=$1
goarch=$2
Expand Down

0 comments on commit 994d817

Please sign in to comment.