diff --git a/.circleci/config.yml b/.circleci/config.yml deleted file mode 100644 index 96472bc882d..00000000000 --- a/.circleci/config.yml +++ /dev/null @@ -1,213 +0,0 @@ -version: 2 -jobs: - deps: - docker: - - image: circleci/golang:1.14 - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - - checkout - - run: - name: Check dependencies - command: | - go version - test -z "$(go mod vendor && git status --porcelain)" - go mod verify - - lint: - docker: - - image: circleci/golang:1.14 - environment: - GOLANGCI_VERSION: v1.30.0 - GO111MODULE: 'on' - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - # Workaround for custom env vars not available in cache keys - # https://discuss.circleci.com/t/cannot-use-circle-yml-environment-variables-in-cache-keys/10994/8 - - run: echo $GOLANGCI_VERSION > /tmp/.golangci.version - - restore_cache: - name: Restore golangci-lint cache - key: golangci-lint-{{ arch }}-{{ checksum "/tmp/.golangci.version" }}-{{ .Environment.CACHE_VERSION }} - paths: - - /go/bin/golangci-lint - - run: - name: Install golangci-lint - command: | - command -v golangci-lint && exit - go get github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCI_VERSION - - save_cache: - name: Save golangci-lint cache - key: golangci-lint-{{ arch }}-{{ checksum "/tmp/.golangci.version" }}-{{ .Environment.CACHE_VERSION }} - paths: - - /go/bin/golangci-lint - - checkout - - run: - name: Run golangci-lint - command: | - BASEREV=$(git merge-base HEAD origin/master) - echo "Base revision: $BASEREV" - golangci-lint run --out-format=tab --new-from-rev "$BASEREV" ./... - - - test: - docker: - - image: circleci/golang:1.14 - environment: - GOPATH: /home/circleci/.go_workspace - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - - checkout - - run: - name: Run tests and code coverage - command: | - go version - export GOMAXPROCS=2 - export PATH=$GOPATH/bin:$PATH - echo "mode: set" > coverage.txt - for pkg in $(go list ./... | grep -v vendor); do - list=$(go list -test -f '{{ join .Deps "\n"}}' $pkg | grep github.com/loadimpact/k6 | grep -v vendor || true) - if [ -n "$list" ]; then - list=$(echo "$list" | cut -f1 -d ' ' | sort -u | paste -sd,) - fi - - go test -race -timeout 800s --coverpkg="$list" -coverprofile=$(echo $pkg | tr / -).coverage $pkg - done - grep -h -v "^mode:" *.coverage >> coverage.txt - rm -f *.coverage - bash <(curl --fail -s https://codecov.io/bash) - - #TODO: when we officially move to Go 1.15, re-enable test-prev-golang with 1.14 - - test-next-golang: - docker: - - image: circleci/golang:1.15 - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - - checkout - - run: - name: Run tests with next Go version - command: | - go version - export GOMAXPROCS=2 - export PATH=$GOPATH/bin:$PATH - go test -p 2 -race -timeout 800s ./... - - build-docker-images: - docker: - - image: circleci/golang:1.14 - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - - checkout - - setup_remote_docker - - run: - name: Setup repo and docker - command: | - docker info - echo "{\"https://index.docker.io/v1/\":{\"auth\":\"$DOCKER_AUTH\",\"email\":\"$DOCKER_EMAIL\"}}" >~/.dockercfg - - run: - name: Build application Docker image - command: | - docker build -t loadimpact/k6 . - - run: - name: Run tests on generated Docker image - command: | - docker run loadimpact/k6 --help - docker run loadimpact/k6 help - docker run loadimpact/k6 run --help - docker run loadimpact/k6 inspect --help - docker run loadimpact/k6 status --help - docker run loadimpact/k6 stats --help - docker run loadimpact/k6 scale --help - docker run loadimpact/k6 pause --help - docker run loadimpact/k6 resume --help - - deploy: - name: Push application Docker image - command: | - if [ "${CIRCLE_BRANCH}" == "master" ]; then - docker tag loadimpact/k6 loadimpact/k6:master - docker push loadimpact/k6:master - elif [[ "${CIRCLE_TAG}" =~ ^v[0-9]+(\.[0-9]+)*$ ]]; then - docker tag loadimpact/k6 loadimpact/k6:${CIRCLE_TAG:1} - docker push loadimpact/k6:latest - docker push loadimpact/k6:${CIRCLE_TAG:1} - fi - - build-linux-packages: - docker: - - image: circleci/golang:1.14 - environment: - GOPATH: /home/circleci/.go_workspace - working_directory: /home/circleci/.go_workspace/src/github.com/loadimpact/k6 - steps: - - checkout - - run: - name: Build linux packages - command: | - export PATH=$GOPATH/bin:$PATH - - go get github.com/Masterminds/glide - go get -d github.com/mh-cbon/go-bin-deb \ - && cd $GOPATH/src/github.com/mh-cbon/go-bin-deb \ - && glide install \ - && go install - - go get -d github.com/mh-cbon/go-bin-rpm \ - && cd $GOPATH/src/github.com/mh-cbon/go-bin-rpm \ - && glide install \ - && go install - - sudo apt-get update -y - sudo apt-get install -y fakeroot rpm - - cd $GOPATH/src/github.com/loadimpact/k6 - - echo "Building k6..." - CGO_ENABLED=0 GOARCH=amd64 go build -a -trimpath -ldflags "-s -w -X github.com/loadimpact/k6/lib/consts.VersionDetails=$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)" -o /tmp/k6 - echo "Done!" - - VERSION=${CIRCLE_TAG:1} ./packaging/gen-packages.sh - - - deploy: - name: Publish packages in Bintray - command: | - export VERSION=${CIRCLE_TAG:1} - # Publishing deb - curl --fail -H "X-GPG-PASSPHRASE: $GPG_PASSPHRASE" -T dist/k6-v$VERSION-amd64.deb "https://$BINTRAY_USER:$BINTRAY_KEY@api.bintray.com/content/loadimpact/deb/k6/$VERSION/k6-v$VERSION-amd64.deb;deb_distribution=stable;deb_component=main;deb_architecture=amd64;publish=1;override=1" - # Publishing rpm - curl --fail -H "X-GPG-PASSPHRASE: $GPG_PASSPHRASE" -T dist/k6-v$VERSION-amd64.rpm "https://$BINTRAY_USER:$BINTRAY_KEY@api.bintray.com/content/loadimpact/rpm/k6/$VERSION/k6-v$VERSION-amd64.rpm?publish=1&override=1" - - -workflows: - version: 2 - test_and_build: - jobs: - - deps: - filters: - tags: - only: /.*/ - - lint - - test: - filters: - tags: - only: /.*/ - - test-next-golang: - filters: - tags: - only: /.*/ - - build-docker-images: - requires: - - deps - - lint - - test - filters: - tags: - only: /.*/ - - build-linux-packages: - requires: - - deps - - lint - - test - filters: - branches: - ignore: /.*/ - tags: - only: /^v.*/ diff --git a/.codecov.yaml b/.codecov.yaml index 9317ff3cbc8..b27d1502450 100644 --- a/.codecov.yaml +++ b/.codecov.yaml @@ -4,3 +4,13 @@ coverage: default: target: auto threshold: 0.3% + windows: + target: auto + flags: [windows] + ubuntu: + target: auto + flags: [ubuntu] + +flags: + windows: + ubuntu: diff --git a/.github/workflows/all.yml b/.github/workflows/all.yml new file mode 100644 index 00000000000..92b36ee8b37 --- /dev/null +++ b/.github/workflows/all.yml @@ -0,0 +1,321 @@ +name: CI +on: + # Enable manually triggering this workflow via the API or web UI + workflow_dispatch: + push: + branches: + - master + tags: + - v* + pull_request: + +defaults: + run: + shell: bash + +env: + APP_NAME: "k6" + DOCKER_IMAGE_ID: ${{ github.repository }} + +jobs: + deps: + runs-on: ubuntu-latest + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Check dependencies + run: | + go version + test -z "$(go mod vendor && git status --porcelain)" + go mod verify + + lint: + runs-on: ubuntu-latest + env: + GOLANGCI_VERSION: v1.31 + GO111MODULE: 'on' + steps: + - name: Checkout code + uses: actions/checkout@v2 + with: + fetch-depth: 0 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Install golangci-lint + working-directory: /tmp + run: go get github.com/golangci/golangci-lint/cmd/golangci-lint@$GOLANGCI_VERSION + - name: Run linters + run: | + BASEREV=$(git merge-base HEAD origin/master) + echo "Base revision: $BASEREV" + golangci-lint run --out-format=tab --new-from-rev "$BASEREV" ./... + + test: + strategy: + matrix: + go-version: [1.14.x] + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Run tests + run: | + set -x + go version + export GOMAXPROCS=2 + args=("-p" "2" "-race") + # Run with less concurrency on Windows to minimize flakiness. + if [[ "${{ matrix.platform }}" == windows* ]]; then + unset args[2] + args[1]="1" + export GOMAXPROCS=1 + fi + go test "${args[@]}" -timeout 800s ./... + + test-cov: + strategy: + matrix: + go-version: [1.15.x] + platform: [ubuntu-latest, windows-latest] + runs-on: ${{ matrix.platform }} + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: ${{ matrix.go-version }} + - name: Run tests with code coverage + run: | + go version + export GOMAXPROCS=2 + args=("-p" "2" "-race") + # Run with less concurrency on Windows to minimize flakiness. + if [[ "${{ matrix.platform }}" == windows* ]]; then + unset args[2] + args[1]="1" + export GOMAXPROCS=1 + fi + echo "mode: set" > coverage.txt + for pkg in $(go list ./... | grep -v vendor); do + list=$(go list -test -f '{{ join .Deps "\n"}}' $pkg | grep github.com/loadimpact/k6 | grep -v vendor || true) + if [ -n "$list" ]; then + list=$(echo "$list" | cut -f1 -d ' ' | sort -u | paste -sd, -) + fi + + go test "${args[@]}" -timeout 800s --coverpkg="$list" -coverprofile=$(echo $pkg | tr / -).coverage $pkg + done + grep -h -v "^mode:" *.coverage >> coverage.txt + rm -f *.coverage + - name: Upload coverage to Codecov + run: | + platform="${{ matrix.platform }}" + bash <(curl --fail -s https://codecov.io/bash) -F "${platform%%-*}" + - name: Generate coverage HTML report + run: go tool cover -html=coverage.txt -o coverage.html + - name: Upload coverage report + uses: actions/upload-artifact@v2 + with: + name: test-coverage-report-${{ matrix.platform }} + path: coverage.html + + configure: + runs-on: ubuntu-latest + outputs: + version: ${{ steps.get_version.outputs.version }} + steps: + - name: Get version + id: get_version + run: | + VERSION="${GITHUB_REF##*/}" + echo "VERSION=${VERSION}" + echo "::set-output name=version::${VERSION}" + + build: + runs-on: ubuntu-latest + needs: [deps, lint, test, test-cov] + if: startsWith(github.ref, 'refs/tags/v') + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install Go + uses: actions/setup-go@v2 + with: + go-version: 1.14.x + - name: Install package builders + env: + GO111MODULE: 'off' + run: | + gopath="$(go env GOPATH)" + go get github.com/Masterminds/glide + go get -d github.com/mh-cbon/go-bin-deb \ + && (cd "$gopath/src/github.com/mh-cbon/go-bin-deb" \ + && glide install \ + && go install) + go get -d github.com/mh-cbon/go-bin-rpm \ + && (cd "$gopath/src/github.com/mh-cbon/go-bin-rpm" \ + && glide install \ + && go install) + sudo apt-get update -y + sudo apt-get install -y fakeroot rpm + - name: Build + run: | + go version + ./build-release.sh + - name: Upload artifacts + uses: actions/upload-artifact@v2 + with: + name: binaries + path: dist/ + retention-days: 7 + + publish-docker: + runs-on: ubuntu-latest + needs: [deps, lint, test, test-cov, configure] + env: + VERSION: ${{ needs.configure.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Build + run: docker build -t $DOCKER_IMAGE_ID . + - name: Check + run: | + docker run $DOCKER_IMAGE_ID version + docker run $DOCKER_IMAGE_ID --help + docker run $DOCKER_IMAGE_ID help + docker run $DOCKER_IMAGE_ID run --help + docker run $DOCKER_IMAGE_ID inspect --help + docker run $DOCKER_IMAGE_ID status --help + docker run $DOCKER_IMAGE_ID stats --help + docker run $DOCKER_IMAGE_ID scale --help + docker run $DOCKER_IMAGE_ID pause --help + docker run $DOCKER_IMAGE_ID resume --help + - name: Publish + if: github.event_name != 'pull_request' + run: | + echo "REF=${{ github.ref }}" + echo "DOCKER_IMAGE_ID=$DOCKER_IMAGE_ID" + # Log into registry + echo "${{ secrets.DOCKER_PASS }}" | docker login -u "${{ secrets.DOCKER_USER }}" --password-stdin + VERSION="${VERSION#v}" + echo "VERSION=$VERSION" + docker tag "$DOCKER_IMAGE_ID" "$DOCKER_IMAGE_ID:$VERSION" + docker push "$DOCKER_IMAGE_ID:$VERSION" + # We also want to tag the latest stable version as latest + if [[ "$VERSION" != "master" ]] && [[ ! "$VERSION" =~ (RC|rc) ]]; then + docker tag "$DOCKER_IMAGE_ID" "$DOCKER_IMAGE_ID:latest" + docker push "$DOCKER_IMAGE_ID:latest" + fi + + publish-github: + runs-on: ubuntu-latest + needs: [deps, lint, test, test-cov, configure, build] + if: startsWith(github.ref, 'refs/tags/v') + env: + VERSION: ${{ needs.configure.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Download binaries + uses: actions/download-artifact@v2 + with: + name: binaries + path: dist + - name: Create release + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + run: | + set -x + assets=() + for asset in ./dist/*; do + assets+=("-a" "$asset") + done + hub release create "${assets[@]}" -m "$VERSION" -m "$(cat ./release\ notes/${VERSION}.md)" "$VERSION" + - name: Upload packages to Bintray + run: | + # Publishing deb + curl --fail -H "X-GPG-PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}" -T "dist/k6-$VERSION-amd64.deb" \ + "https://${{ secrets.BINTRAY_USER }}:${{ secrets.BINTRAY_KEY }}@api.bintray.com/content/loadimpact/deb/k6/${VERSION#v}/k6-${VERSION}-amd64.deb;deb_distribution=stable;deb_component=main;deb_architecture=amd64;publish=1;override=1" + # Publishing rpm + curl --fail -H "X-GPG-PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}" -T "dist/k6-$VERSION-amd64.rpm" \ + "https://${{ secrets.BINTRAY_USER }}:${{ secrets.BINTRAY_KEY }}@api.bintray.com/content/loadimpact/rpm/k6/${VERSION#v}/k6-${VERSION}-amd64.rpm?publish=1&override=1" + + publish-windows: + runs-on: windows-latest + defaults: + run: + shell: powershell + needs: [deps, lint, test, test-cov, configure, build] + if: startsWith(github.ref, 'refs/tags/v') + env: + VERSION: ${{ needs.configure.outputs.version }} + steps: + - name: Checkout code + uses: actions/checkout@v2 + - name: Install pandoc + uses: crazy-max/ghaction-chocolatey@b6061d587628735be315d74358228b83a7dba9a7 + with: + args: install -y pandoc + - name: Install wix tools + run: | + curl -O wix311-binaries.zip https://github.com/wixtoolset/wix3/releases/download/wix3112rtm/wix311-binaries.zip + Expand-Archive -Path .\wix311-binaries.zip -DestinationPath .\wix311\ + echo "$pwd\wix311" | Out-File -FilePath $env:GITHUB_PATH -Encoding utf8 -Append + - name: Download binaries + uses: actions/download-artifact@v2 + with: + name: binaries + path: dist + - name: Unzip Windows binary + run: | + Expand-Archive -Path ".\dist\k6-$env:VERSION-win64.zip" -DestinationPath .\packaging\ + move .\packaging\k6-$env:VERSION-win64\k6.exe .\packaging\ + rmdir .\packaging\k6-$env:VERSION-win64\ + - name: Create MSI package + run: | + $env:VERSION = $env:VERSION -replace 'v(\d+\.\d+\.\d+).*','$1' + pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md + cd .\packaging + candle.exe -arch x64 "-dVERSION=$env:VERSION" k6.wxs + light.exe -ext WixUIExtension k6.wixobj + - name: Prepare Chocolatey package + run: | + $env:VERSION = $env:VERSION.TrimStart("v", " ") + cd .\packaging + (Get-Content '.\k6.portable.nuspec' -Raw).Replace("__REPLACE__", "$env:VERSION") | Out-File '.\k6.portable.nuspec' + - name: Create Chocolatey package + uses: crazy-max/ghaction-chocolatey@b6061d587628735be315d74358228b83a7dba9a7 + with: + args: pack --verbose --outputdirectory .\packaging .\packaging\k6.portable.nuspec + - name: Upload packages to Bintray + run: | + cd .\packaging + $env:VERSION = $env:VERSION.TrimStart("v", " ") + curl.exe --fail -H "X-GPG-PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}" -T .\k6.msi "https://${{ secrets.BINTRAY_USER }}:${{ secrets.BINTRAY_KEY }}@api.bintray.com/content/loadimpact/windows/k6/$env:VERSION/k6-v$env:VERSION-amd64.msi?publish=1&override=1" + curl.exe --fail -H "X-GPG-PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}" -T .\k6.portable.$env:VERSION.nupkg "https://${{ secrets.BINTRAY_USER }}:${{ secrets.BINTRAY_KEY }}@api.bintray.com/content/loadimpact/choco/k6.portable/$env:VERSION/k6.portable.$env:VERSION.nupkg?publish=1&override=1" + + publish-macos: + runs-on: macos-latest + needs: [deps, lint, test, test-cov, configure, build] + if: startsWith(github.ref, 'refs/tags/v') + env: + VERSION: ${{ needs.configure.outputs.version }} + steps: + - name: Set up Homebrew + uses: Homebrew/actions/setup-homebrew@cd7c1eba155dc11d77aa3e3e4013836ad96a6894 + - name: Create version bump PR + run: brew bump-formula-pr k6 --tag="$VERSION" --revision="$GITHUB_SHA" diff --git a/appveyor.yml b/appveyor.yml deleted file mode 100644 index b5d1e7ac4a1..00000000000 --- a/appveyor.yml +++ /dev/null @@ -1,83 +0,0 @@ -image: Visual Studio 2017 -clone_folder: 'c:\gopath\src\github.com\%APPVEYOR_REPO_NAME%' - -# Do not build feature branch with open Pull Requests -skip_branch_with_pr: true - -environment: - # improve readability - VCS_URL: 'https://github.com/%APPVEYOR_REPO_NAME%' - # specific to go - VERSION: "%APPVEYOR_REPO_TAG_NAME:v=%" - GOPATH: c:\gopath - GOVERSION: 1.14.9 - GOMAXPROCS: 2 - CGO_ENABLED: '0' - GOARCH: amd64 - BINTRAY_KEY: - secure: 0DFVlQR9tBvdTiULPdCw12VBf2Zzy/hpPiPtlKhHdaatIBdwB6i1HhPcgh0kDEBr - GPG_PASSPHRASE: - secure: CMQ+U+qVVdhIr1Eip5nGPbaGFggVvSjg/BpSY0EpLbQ= - -# prepare system and project -install: - - choco install wixtoolset pandoc -y - - refreshenv - # ensure wix and go are available in PATH - - set PATH=C:\go\bin;%GOPATH%\bin;%WIX%\bin;%PATH% - - ps: | - Remove-Item 'C:\go' -Recurse -Force -ErrorAction Ignore - Remove-Item 'C:\go-x86' -Recurse -Force -ErrorAction Ignore - - Write-Host "Downloading..." - $goDistPath = "$env:TEMP\go" + $env:GOVERSION + ".windows-amd64.zip" - (New-Object Net.WebClient).DownloadFile("https://dl.google.com/go/go" + $env:GOVERSION + ".windows-amd64.zip", $goDistPath) - - Write-Host "Unpacking..." - 7z x $goDistPath -oC:\gotmp-x64 | Out-Null - [IO.Directory]::Move('C:\gotmp-x64\go', 'C:\go') - Remove-Item 'C:\gotmp-x64' -Recurse -Force - del $goDistPath - - Write-Host "Testing..." - - go version - - echo "NumCores:%NUMBER_OF_PROCESSORS%" - - systeminfo - - -# build msi artifacts -build_script: - # In case of non tag build, mock a version - - if "%APPVEYOR_REPO_TAG%" == "false" (set VERSION="0.0.1") - - cd %APPVEYOR_BUILD_FOLDER% - - pandoc -s -f markdown -t rtf -o packaging\LICENSE.rtf LICENSE.md - - go version - - go build -a -trimpath -ldflags "-s -w" -o packaging\k6.exe - - cd %APPVEYOR_BUILD_FOLDER%\packaging - - candle.exe -arch x64 -dVERSION=%VERSION% k6.wxs - - light.exe -ext WixUIExtension k6.wixobj - -test_script: - - cd %APPVEYOR_BUILD_FOLDER% - - go version - - go test -p 1 ./... - -deploy_script: - - cd %APPVEYOR_BUILD_FOLDER%\packaging - # Checking if the build has started by pushed tag - - ps: | - if ( $env:APPVEYOR_REPO_TAG -eq "false" ) { Exit-AppveyorBuild } - # Publishing the msi - - 'curl --fail -H "X-GPG-PASSPHRASE: %GPG_PASSPHRASE%" -T k6.msi "https://%BINTRAY_USER%:%BINTRAY_KEY%@api.bintray.com/content/loadimpact/windows/k6/%VERSION%/k6-v%VERSION%-amd64.msi?publish=1&override=1"' - - ps: | - # Create Chocolately Package - mkdir .\k6.portable - - Copy-Item -Path .\k6.portable.nuspec -Destination .\k6.portable\k6.portable.nuspec - Copy-Item -Path .\k6.exe -Destination .\k6.portable\k6.exe - - Set-Location -Path .\k6.portable\ - (Get-Content '.\k6.portable.nuspec' -Raw).Replace("__REPLACE__", "$($env:APPVEYOR_REPO_TAG_NAME.substring(1))") | Out-File '.\k6.portable.nuspec' - choco pack - # Publising the chocolatey package - - 'curl --fail -H "X-GPG-PASSPHRASE: %GPG_PASSPHRASE%" -T .\k6.portable.%VERSION%.nupkg "https://%BINTRAY_USER%:%BINTRAY_KEY%@api.bintray.com/content/loadimpact/choco/k6.portable/%VERSION%/k6.portable.%VERSION%.nupkg?publish=1&override=1"' diff --git a/build-release.sh b/build-release.sh index 57f76a70340..3a58008150d 100755 --- a/build-release.sh +++ b/build-release.sh @@ -1,87 +1,101 @@ -#!/usr/bin/env bash +#!/bin/bash set -eEuo pipefail eval "$(go env)" -# To override the latest git tag as the version, pass something else as the first arg. -VERSION=${1:-$(git describe --tags --always --dirty)} +OUT_DIR="${1-dist}" +# To override the latest git tag as the version, pass something else as the second arg. +VERSION=${2:-$(git describe --tags --always --dirty)} -# To overwrite the version details, pass something as the second arg. Empty string disables it. -VERSION_DETAILS=${2-"$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"} +# To overwrite the version details, pass something as the third arg. Empty string disables it. +VERSION_DETAILS=${3-"$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"} -make_archive() { - local FMT="$1" DIR="$2" +build() { + local ALIAS="$1" SUFFIX="${2}" # Any other arguments are passed to the go build command as env vars + local NAME="k6-${VERSION}-${ALIAS}" - case $FMT in - zip) - zip -rq9 "$DIR.zip" "$DIR" - ;; - tgz) - tar -zcf "$DIR.tar.gz" "$DIR" - ;; - esac -} - -build_dist() { - local ALIAS="$1" FMT="${2}" SUFFIX="${3}" # Any other arguments are passed to the go build command as env vars - local DIR="k6-${VERSION}-${ALIAS}" - - local BUILD_ENV=("${@:4}") - local BUILD_ARGS=(-o "dist/$DIR/k6${SUFFIX}" -trimpath) - - if [ -n "$VERSION_DETAILS" ]; then - BUILD_ARGS+=(-ldflags "-X github.com/loadimpact/k6/lib/consts.VersionDetails=$VERSION_DETAILS") - fi - - echo "- Building platform: ${ALIAS} (" "${BUILD_ENV[@]}" "go build" "${BUILD_ARGS[@]}" ")" + local BUILD_ENV=("${@:3}") + local BUILD_ARGS=(-o "${OUT_DIR}/${NAME}/k6${SUFFIX}" -trimpath) - # Clean out any old remnants of failed builds. - rm -rf "dist/$DIR" - mkdir -p "dist/$DIR" + if [ -n "$VERSION_DETAILS" ]; then + BUILD_ARGS+=(-ldflags "-X github.com/loadimpact/k6/lib/consts.VersionDetails=$VERSION_DETAILS") + fi - # Subshell to not mess with the current env vars or CWD - ( - export "${BUILD_ENV[@]}" + echo "- Building platform: ${ALIAS} (" "${BUILD_ENV[@]}" "go build" "${BUILD_ARGS[@]}" ")" - # Build a binary - go build "${BUILD_ARGS[@]}" + mkdir -p "${OUT_DIR}/${NAME}" - # Archive it all, native format depends on the platform. - cd dist - make_archive "$FMT" "$DIR" - ) + # Subshell to not mess with the current env vars or CWD + ( + export "${BUILD_ENV[@]}" + # Build a binary + go build "${BUILD_ARGS[@]}" + ) +} - # Delete the source files. - rm -rf "dist/$DIR" +package() { + local ALIAS="$1" FMT="$2" + local NAME="k6-${VERSION}-${ALIAS}" + echo "- Creating ${NAME}.${FMT} package..." + case $FMT in + deb|rpm) + # The go-bin-* tools expect the binary in /tmp/ + [ ! -r /tmp/k6 ] && cp "${OUT_DIR}/${NAME}/k6" /tmp/k6 + "go-bin-${FMT}" generate --file "packaging/${FMT}.json" -a amd64 \ + --version "${VERSION#v}" -o "${OUT_DIR}/k6-${VERSION}-amd64.${FMT}" + ;; + tgz) + tar -C "${OUT_DIR}" -zcf "${OUT_DIR}/${NAME}.tar.gz" "$NAME" + ;; + zip) + (cd "${OUT_DIR}" && zip -rq9 - "$NAME") > "${OUT_DIR}/${NAME}.zip" + ;; + *) + echo "Unknown format: $FMT" + return 1 + ;; + esac } +CHECKSUM_FILE="k6-${VERSION}-checksums.txt" checksum() { - local CHECKSUM_FILE="k6-${VERSION}-checksums.txt" - - if command -v sha256sum > /dev/null; then - CHECKSUM_CMD=("sha256sum") - elif command -v shasum > /dev/null; then - CHECKSUM_CMD=("shasum" "-a" "256") - else - echo "ERROR: unable to find a command to compute sha-256 hash" - return 1 - fi - - rm -f "dist/$CHECKSUM_FILE" - ( cd dist && for x in *; do [ -f "$x" ] && "${CHECKSUM_CMD[@]}" -- "$x" >> "$CHECKSUM_FILE"; done ) + if command -v sha256sum > /dev/null; then + CHECKSUM_CMD=("sha256sum") + elif command -v shasum > /dev/null; then + CHECKSUM_CMD=("shasum" "-a" "256") + else + echo "ERROR: unable to find a command to compute sha-256 hash" + exit 1 + fi + + echo "--- Generating checksum file..." + rm -f "${OUT_DIR}/$CHECKSUM_FILE" + (cd "$OUT_DIR" && find . -maxdepth 1 -type f -printf '%P\n' | sort | xargs "${CHECKSUM_CMD[@]}" > "$CHECKSUM_FILE") +} + +cleanup() { + find "$OUT_DIR" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \; + echo "--- Cleaned ${OUT_DIR}" } +trap cleanup EXIT echo "--- Building Release: ${VERSION}" -echo "-> Building platform packages..." -mkdir -p dist +mkdir -p "$OUT_DIR" + +build mac "" GOOS=darwin GOARCH=amd64 +build win32 .exe GOOS=windows GOARCH=386 +build win64 .exe GOOS=windows GOARCH=amd64 +build linux32 "" GOOS=linux GOARCH=386 CGO_ENABLED=0 +build linux64 "" GOOS=linux GOARCH=amd64 CGO_ENABLED=0 -build_dist mac zip "" GOOS=darwin GOARCH=amd64 -build_dist win32 zip .exe GOOS=windows GOARCH=386 -build_dist win64 zip .exe GOOS=windows GOARCH=amd64 -build_dist linux32 tgz "" GOOS=linux GOARCH=386 CGO_ENABLED=0 -build_dist linux64 tgz "" GOOS=linux GOARCH=amd64 CGO_ENABLED=0 +package linux32 tgz +package linux64 tgz +package linux64 rpm +package linux64 deb +package mac zip +package win32 zip +package win64 zip -echo "-> Generating checksum file..." checksum diff --git a/js/modules/k6/http/request_test.go b/js/modules/k6/http/request_test.go index 09e8a3019ec..c6608bc5b54 100644 --- a/js/modules/k6/http/request_test.go +++ b/js/modules/k6/http/request_test.go @@ -1669,7 +1669,7 @@ func TestErrorCodes(t *testing.T) { name: "Unroutable", expectedErrorCode: 1101, expectedErrorMsg: "lookup: no such host", - script: `var res = http.request("GET", "http://sdafsgdhfjg/");`, + script: `var res = http.request("GET", "http://sdafsgdhfjg.com/");`, }, { @@ -1683,7 +1683,7 @@ func TestErrorCodes(t *testing.T) { expectedErrorCode: 1101, expectedErrorMsg: "lookup: no such host", moreSamples: 1, - script: `var res = http.request("GET", "HTTPBIN_URL/redirect-to?url=http://dafsgdhfjg/");`, + script: `var res = http.request("GET", "HTTPBIN_URL/redirect-to?url=http://dafsgdhfjg.com/");`, }, { name: "Non location redirect", @@ -1701,7 +1701,7 @@ func TestErrorCodes(t *testing.T) { name: "Missing protocol", expectedErrorCode: 1000, expectedErrorMsg: `unsupported protocol scheme ""`, - script: `var res = http.request("GET", "dafsgdhfjg/");`, + script: `var res = http.request("GET", "dafsgdhfjg.com/");`, }, { name: "Too many redirects", diff --git a/packaging/deb.json b/packaging/deb.json index 5164c9bf94f..93df0b56585 100644 --- a/packaging/deb.json +++ b/packaging/deb.json @@ -15,9 +15,9 @@ "copyrights": [ { "files": "*", - "copyright": "2018 Load Impact AB", + "copyright": "2020 Load Impact AB", "license": "AGPL-3.0", "file": "LICENSE" } ] - } \ No newline at end of file + }