Skip to content

Commit

Permalink
fix: embed tzdata into Windows builds (#305)
Browse files Browse the repository at this point in the history
Migrate cross-test jobs to use cross-builder so Windows tests run on a system without Go, as a regression test
  • Loading branch information
danxmoran authored Oct 14, 2021
1 parent 964bc4f commit d92bede
Show file tree
Hide file tree
Showing 6 changed files with 315 additions and 55 deletions.
238 changes: 183 additions & 55 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,25 +1,29 @@
version: "2.1"

executors:
cross-builder:
docker:
# NOTE: To upgrade the Go version, first push the upgrade to the cross-builder Dockerfile in the edge repo,
# then update the version here to match. Until we finish the migration to using the cross-builder image,
# you'll also need to update references to `cimg/go` and `GO_VERSION` in this file.
- image: quay.io/influxdb/cross-builder:go1.17.2-f7b4e805fa9588c1c2fa4562ea29e576557fb797
resource_class: medium
linux-amd64:
machine:
image: ubuntu-2004:202104-01

image: ubuntu-2004:202107-02
linux-arm64:
machine:
image: ubuntu-2004:202104-01
resource_class: arm.medium

resource_class: arm.medium
mac:
macos:
xcode: 12.4.0
resource_class: medium
resource_class: medium
shell: /bin/bash -eo pipefail

windows:
machine:
image: windows-server-2019-vs2019:stable
resource_class: windows.medium
resource_class: windows.medium
shell: bash.exe -eo pipefail

workflows:
Expand All @@ -29,14 +33,37 @@ workflows:
- lint
- check-openapi
- build-all
- test:
- test-race:
name: test-linux-amd64
- test-build:
matrix:
parameters:
executor:
- linux-amd64
- linux-arm64
- mac
- windows
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
- os: darwin
arch: arm64
- os: windows
arch: arm64
# linux/amd64 can be tested directly from our cross-builder image
# to save time & enable running with the race detector.
- os: linux
arch: amd64
- test-prebuilt:
name: test-linux-arm64
executor: linux-arm64
requires:
- test-build-arm64-linux
- test-prebuilt:
name: test-mac
executor: mac
requires:
- test-build-amd64-darwin
- test-prebuilt:
name: test-windows
executor: windows
requires:
- test-build-amd64-windows
release-nightly:
triggers:
- schedule:
Expand All @@ -48,21 +75,46 @@ workflows:
jobs:
- lint
- check-openapi
- test:
requires:
- lint
- check-openapi
- test-race:
name: test-linux-amd64
- test-build:
matrix:
parameters:
executor:
- linux-amd64
- linux-arm64
- mac
- windows
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
- os: darwin
arch: arm64
- os: windows
arch: arm64
# linux/amd64 can be tested directly from our cross-builder image
# to save time & enable running with the race detector.
- os: linux
arch: amd64
- test-prebuilt:
name: test-linux-arm64
executor: linux-arm64
requires:
- test-build-arm64-linux
- test-prebuilt:
name: test-mac
executor: mac
requires:
- test-build-amd64-darwin
- test-prebuilt:
name: test-windows
executor: windows
requires:
- test-build-amd64-windows
- release:
is-nightly: true
requires:
- test
- lint
- check-openapi
- test-linux-amd64
- test-linux-arm64
- test-mac
- test-windows
release-tag:
jobs:
- lint:
Expand All @@ -77,22 +129,62 @@ workflows:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
- test:
requires:
- lint
- check-openapi
- test-race:
name: test-linux-amd64
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
- test-build:
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
matrix:
parameters:
executor:
- linux-amd64
- linux-arm64
- mac
- windows
os: [ linux, darwin, windows ]
arch: [ amd64, arm64 ]
exclude:
- os: darwin
arch: arm64
- os: windows
arch: arm64
# linux/amd64 can be tested directly from our cross-builder image
# to save time & enable running with the race detector.
- os: linux
arch: amd64
- test-prebuilt:
name: test-linux-arm64
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
executor: linux-arm64
requires:
- test-build-arm64-linux
- test-prebuilt:
name: test-mac
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
executor: mac
requires:
- test-build-amd64-darwin
- test-prebuilt:
name: test-windows
filters:
branches:
ignore: /.*/
tags:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
executor: windows
requires:
- test-build-amd64-windows
- release:
filters:
branches:
Expand All @@ -101,7 +193,12 @@ workflows:
only: /^v[0-9]+\.[0-9]+\.[0-9]+(-(rc|alpha|beta)[0-9]+)?$/
is-nightly: false
requires:
- test
- lint
- check-openapi
- test-linux-amd64
- test-linux-arm64
- test-mac
- test-windows

commands:
setup:
Expand Down Expand Up @@ -131,14 +228,25 @@ commands:

jobs:
lint:
executor: linux-amd64
executor: cross-builder
steps:
- checkout
- setup
- run: make vet
- run: make checkfmt
- run: make checktidy
- run: make staticcheck
- run:
name: vet
command: make vet
when: always
- run:
name: Check formatting
command: make checkfmt
when: always
- run:
name: Check mod tidy
command: make checktidy
when: always
- run:
name: staticcheck
command: make staticcheck
when: always

check-openapi:
executor: linux-amd64
Expand Down Expand Up @@ -201,31 +309,51 @@ jobs:
- store_artifacts:
path: dist

test:
test-build:
executor: cross-builder
parameters:
os:
type: string
arch:
type: string
steps:
- checkout
- run:
name: Build test binaries
command: |
export GOOS=<< parameters.os >>
export GOARCH=<< parameters.arch >>
./scripts/ci/build-tests.sh ./test-bin
- persist_to_workspace:
root: .
paths:
- ./test-bin

test-prebuilt:
parameters:
executor:
type: executor
executor: << parameters.executor >>
steps:
- checkout
- setup
- attach_workspace:
at: .
- run:
name: Download gotestsum
command: |
GOTESTSUM_VERSION=1.6.4
GOTESTSUM_ARCHIVE=gotestsum_${GOTESTSUM_VERSION}_$(go env GOOS)_$(go env GOARCH).tar.gz
GOTESTSUM_URL=https://github.com/gotestyourself/gotestsum/releases/download/v${GOTESTSUM_VERSION}/${GOTESTSUM_ARCHIVE}
name: Run tests
command: ./scripts/ci/run-prebuilt-tests.sh $(pwd)/test-bin $(pwd)/test-results
- store_artifacts:
path: ./test-results
destination: raw-test-output
- store_test_results:
path: ./test-results

wget ${GOTESTSUM_URL}
tar xzf ${GOTESTSUM_ARCHIVE}
install gotestsum ${GOPATH}/bin/
test-race:
executor: cross-builder
steps:
- checkout
- run:
name: Run parallel race tests
command: |
mkdir -p test-results
GO_TEST_CMD="gotestsum --format standard-quiet --junitfile ./test-results/gotestsum.xml --"
TESTFILES=($(go list ./... | circleci tests split --split-by=timings))
make GO_TEST="$GO_TEST_CMD" GO_TEST_PATHS="${TESTFILES[*]}" test-race
name: Run race tests
command: ./scripts/ci/run-race-tests.sh $(pwd)/test-results
- store_artifacts:
path: ./test-results
destination: raw-test-output
Expand Down
2 changes: 2 additions & 0 deletions .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ builds:
main: ./cmd/influx
env:
- CGO_ENABLED=0
flags:
- -tags={{if eq .Os "windows"}}timetzdata{{end}}
ldflags:
- -s -w -X main.version={{.Version}} -X main.commit={{.ShortCommit}} -X main.date={{.Date}}
binary: influx
Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

1. [297](https://github.com/influxdata/influx-cli/pull/297): Detect and warn when `restore --full` changes the operator token.
1. [302](https://github.com/influxdata/influx-cli/pull/302): Set newly-created config as active in `setup`.
1. [305](https://github.com/influxdata/influx-cli/pull/305): Embed timezone data into Windows builds to avoid errors.

## v2.1.1 [2021-09-22]

Expand Down
51 changes: 51 additions & 0 deletions scripts/ci/build-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/usr/bin/env bash
set -exo pipefail

function build_test_binaries () {
local tags=""
if [ "$(go env GOOS)" = windows ]; then
tags="-tags timetzdata"
fi

CGO_ENABLED=0 go-test-compile ${tags} -o "${1}/" ./...
}

function build_test_tools () {
# Copy pre-built gotestsum out of the cross-builder.
local ext=""
if [ "$(go env GOOS)" = windows ]; then
ext=".exe"
fi
cp "/usr/local/bin/gotestsum_$(go env GOOS)_$(go env GOARCH)${ext}" "$1/gotestsum${ext}"

# Build test2json from the installed Go distribution.
CGO_ENABLED=0 go build -o "${1}/" -ldflags="-s -w" cmd/test2json
}

function write_test_metadata () {
# Write version that should be reported in test results.
echo "$(go env GOVERSION) $(go env GOOS)/$(go env GOARCH)" > "${1}/go.version"

# Write list of all packages.
go list ./... > "${1}/tests.list"
}

function main () {
if [[ $# != 1 ]]; then
>&2 echo Usage: $0 '<output-dir>'
>&2 echo '<output-dir>' will be created if it does not already exist
exit 1
fi
local -r out_dir="$1"

mkdir -p "$out_dir"

# Build all test binaries.
build_test_binaries "${out_dir}/"
# Build gotestsum and test2json so downstream jobs can use it without needing `go`.
build_test_tools "$out_dir"
# Write other metadata needed for testing.
write_test_metadata "$out_dir"
}

main ${@}
Loading

0 comments on commit d92bede

Please sign in to comment.