From d25abd51a4402b4521185770b85fa7802d89fc64 Mon Sep 17 00:00:00 2001 From: Pablo Chacin Date: Wed, 14 Feb 2024 12:51:00 +0100 Subject: [PATCH] build with k6 version from go.mod Signed-off-by: Pablo Chacin --- .github/workflows/ci.yml | 17 ++++++++++++++++- build.sh | 7 ++++++- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 5569cf34..e4f355da 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -17,6 +17,10 @@ jobs: matrix: os: [ubuntu-latest, macos-latest] steps: + - name: get k6 version + run: | + K6_VERSION=$(cat go.mod | grep "go.k6.io/k6" | cut -d' ' -f 2) + echo "K6_VERSION=$K6_VERSION" >> $GITHUB_ENV - name: Checkout code uses: actions/checkout@v4 - name: Install Go @@ -24,6 +28,8 @@ jobs: with: go-version-file: go.mod - name: Build with xk6 + env: + K6_VERSION: ${{ env.K6_VERSION }} run: | go install go.k6.io/xk6/cmd/xk6@latest xk6 build --with $(go list -m)=. @@ -31,11 +37,20 @@ jobs: build-with-xk6-docker: runs-on: ubuntu-latest steps: + - name: get k6 version + run: | + K6_VERSION=$(cat go.mod | grep "go.k6.io/k6" | cut -d' ' -f 2) + echo "K6_VERSION=$K6_VERSION" >> $GITHUB_ENV - name: Checkout code uses: actions/checkout@v4 - name: Build with xk6 + env: + K6_VERSION: ${{ env.K6_VERSION }} run: | - docker run --rm -i -u "$(id -u):$(id -g)" -v "${PWD}:/xk6" grafana/xk6 build --with $(go list -m)=/xk6 + docker run --rm -i -u "$(id -u):$(id -g)" \ + -v "${PWD}:/xk6-disruptor" \ + -e K6_VERSION="${K6_VERSION}" \ + grafana/xk6 build --with $(go list -m)=/xk6-disruptor run-unit-tests: runs-on: ${{ matrix.os }} diff --git a/build.sh b/build.sh index ede298ba..a05234d5 100755 --- a/build.sh +++ b/build.sh @@ -17,6 +17,7 @@ $0 [OPTIONS] options: -a, --arch: target architecture (valid option amd64, arm64. Defaults to GOARCH) -b, --build: directory for building binaries (defaults to 'build. Created if it does not exist) + -k, --k6-version: version of k6 to use -n, --name: package base name. Defaults to 'xk6-disruptor' -o, --os: target operating systems (valid options linux, darwing, windows. Defaults to GOOS) -r, --replace: module that replaces xk6-distruptor module @@ -46,6 +47,10 @@ while [[ $# -gt 0 ]]; do BUILD="$2" shift ;; + -k|--k6-version) + K6_VERSION="$2" + shift + ;; -o|--os) OS="$2" if [[ ! $OS =~ linux|darwin|windows ]]; then @@ -112,6 +117,6 @@ fi export GOARCH=$ARCH export GOOS=$OS export XK6_BUILD_FLAGS='-ldflags "-w -s' - xk6 build --with $MOD=${REPLACE} --output $BUILD/$BINARY + xk6 build $K6_VERSION --with $MOD=${REPLACE} --output $BUILD/$BINARY )