<commit_before>#!/bin/bash

set -eEuo pipefail

eval "$(go env)"

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 third arg. Empty string disables it.
VERSION_DETAILS=${3-"$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"}

build() {
    local ALIAS="$1" SUFFIX="${2}"  # Any other arguments are passed to the go build command as env vars
    local NAME="k6-${VERSION}-${ALIAS}"

    local BUILD_ENV=("${@:3}")
    local BUILD_ARGS=(-o "${OUT_DIR}/${NAME}/k6${SUFFIX}" -trimpath)

    if [ -n "$VERSION_DETAILS" ]; then
        BUILD_ARGS+=(-ldflags "-X go.k6.io/k6/lib/consts.VersionDetails=$VERSION_DETAILS")
    fi

    echo "- Building platform: ${ALIAS} (" "${BUILD_ENV[@]}" "go build" "${BUILD_ARGS[@]}" ")"

    mkdir -p "${OUT_DIR}/${NAME}"

    # Subshell to not mess with the current env vars or CWD
    (
        export "${BUILD_ENV[@]}"
        # Build a binary
         go build "${BUILD_ARGS[@]}"
    )
}

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
}

cleanup() {
    find "$OUT_DIR" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
    echo "--- Cleaned ${OUT_DIR}"
}
trap cleanup EXIT

echo "--- Building Release: ${VERSION}"

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

package linux32 tgz
package linux64 tgz
package linux64 rpm
package linux64 deb
package mac     zip
package win32   zip
package win64   zip
<commit_msg>Remove 32-bit builds and add arm64 ones<commit_after>#!/bin/bash

set -eEuo pipefail

eval "$(go env)"

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 third arg. Empty string disables it.
VERSION_DETAILS=${3-"$(date -u +"%FT%T%z")/$(git describe --always --long --dirty)"}

build() {
    local ALIAS="$1" SUFFIX="${2}"  # Any other arguments are passed to the go build command as env vars
    local NAME="k6-${VERSION}-${ALIAS}"

    local BUILD_ENV=("${@:3}")
    local BUILD_ARGS=(-o "${OUT_DIR}/${NAME}/k6${SUFFIX}" -trimpath)

    if [ -n "$VERSION_DETAILS" ]; then
        BUILD_ARGS+=(-ldflags "-X go.k6.io/k6/lib/consts.VersionDetails=$VERSION_DETAILS")
    fi

    echo "- Building platform: ${ALIAS} (" "${BUILD_ENV[@]}" "go build" "${BUILD_ARGS[@]}" ")"

    mkdir -p "${OUT_DIR}/${NAME}"

    # Subshell to not mess with the current env vars or CWD
    (
        export "${BUILD_ENV[@]}"
        # Build a binary
         go build "${BUILD_ARGS[@]}"
    )
}

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
}

cleanup() {
    find "$OUT_DIR" -mindepth 1 -maxdepth 1 -type d -exec rm -rf {} \;
    echo "--- Cleaned ${OUT_DIR}"
}
trap cleanup EXIT

echo "--- Building Release: ${VERSION}"

mkdir -p "$OUT_DIR"

build mac         ""   GOOS=darwin  GOARCH=amd64
build mac-arm64   ""   GOOS=darwin  GOARCH=arm64
build win64      .exe  GOOS=windows GOARCH=amd64
build linux64     ""   GOOS=linux   GOARCH=amd64  CGO_ENABLED=0
build linux-arm64 ""   GOOS=linux   GOARCH=arm64  CGO_ENABLED=0

package mac         zip
package mac-arm64   zip
package win64       zip
package linux64     tgz
package linux-arm64 tgz
package linux64     rpm
package linux64     deb

{'fraction_non_alphanumeric': 0.17627944760357434, 'fraction_numerical': 0.024370430544272948, 'mean_word_length': 2.6698956780923995, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2527008', 'n_tokens_mistral': 1825, 'n_tokens_neox': 1735, 'n_words': 489}