...

Text file src/github.com/bazelbuild/buildtools/release/github.sh

Documentation: github.com/bazelbuild/buildtools/release

     1#!/usr/bin/env bash
     2
     3set -e
     4
     5if [ -z "$GITHUB_ACCESS_TOKEN" ]
     6then
     7    echo "Create a Github auth token at https://github.com/settings/tokens and set it as \$GITHUB_ACCESS_TOKEN"
     8    exit 1
     9fi
    10
    11TAG="$(git describe --abbrev=0 --tags | sed 's/* //')"  # v1.2.3
    12VERSION=$(echo $TAG | sed 's/v//')  # 1.2.3
    13DATE="$(date +"%Y-%m-%d")"
    14NAME="Release $VERSION ($DATE)"
    15
    16GH_REPO="repos/bazelbuild/buildtools"
    17GH_AUTH_HEADER="Authorization: token $GITHUB_ACCESS_TOKEN"
    18
    19BIN_DIR=`mktemp -d -p "$DIR"`
    20
    21bazel clean
    22bazel build --config=release //buildifier:all //buildozer:all //unused_deps:all
    23
    24for tool in "buildifier" "buildozer" "unused_deps"; do
    25  cp bazel-bin/"$tool/$tool-linux_amd64" $BIN_DIR
    26  cp bazel-bin/"$tool/$tool-linux_arm64" $BIN_DIR
    27  cp bazel-bin/"$tool/$tool-darwin_amd64" $BIN_DIR
    28  cp bazel-bin/"$tool/$tool-darwin_arm64" $BIN_DIR
    29  cp bazel-bin/"$tool/$tool-windows_amd64.exe" $BIN_DIR
    30done;
    31
    32echo "Creating a draft release"
    33API_JSON="{\"tag_name\": \"$TAG\", \"target_commitish\": \"master\", \"name\": \"$NAME\", \"draft\": true}"
    34RESPONSE=$(curl -s --show-error -H "$GH_AUTH_HEADER" --data "$API_JSON" "https://api.github.com/$GH_REPO/releases")
    35RELEASE_ID=$(echo $RESPONSE | jq -r '.id')
    36RELEASE_URL=$(echo $RESPONSE | jq -r '.html_url')
    37
    38upload_file() {
    39    echo "Uploading $2"
    40    ASSET="https://uploads.github.com/$GH_REPO/releases/$RELEASE_ID/assets?name=$2"
    41    curl --data-binary @"$1" -s --show-error -o /dev/null -H "$GH_AUTH_HEADER" -H "Content-Type: application/octet-stream" $ASSET
    42}
    43
    44for tool in "buildifier" "buildozer" "unused_deps"; do
    45  upload_file "$BIN_DIR/$tool-linux_amd64" "$tool-linux-amd64"
    46  upload_file "$BIN_DIR/$tool-linux_arm64" "$tool-linux-arm64"
    47  upload_file "$BIN_DIR/$tool-darwin_amd64" "$tool-darwin-amd64"
    48  upload_file "$BIN_DIR/$tool-darwin_arm64" "$tool-darwin-arm64"
    49  upload_file "$BIN_DIR/$tool-windows_amd64.exe" "$tool-windows-amd64.exe"
    50done
    51
    52rm -rf $BIN_DIR
    53
    54echo "The draft release is available at $RELEASE_URL"

View as plain text