| 1 |
#!/usr/bin/env bash |
| 2 |
# Copyright 2023 The Bazel Authors. All rights reserved. |
| 3 |
# |
| 4 |
# Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 |
# you may not use this file except in compliance with the License. |
| 6 |
# You may obtain a copy of the License at |
| 7 |
# |
| 8 |
# http://www.apache.org/licenses/LICENSE-2.0 |
| 9 |
# |
| 10 |
# Unless required by applicable law or agreed to in writing, software |
| 11 |
# distributed under the License is distributed on an "AS IS" BASIS, |
| 12 |
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 |
# See the License for the specific language governing permissions and |
| 14 |
# limitations under the License. |
| 15 |
|
| 16 |
set -o errexit -o nounset -o pipefail |
| 17 |
|
| 18 |
JSONNET_VERSION="$(grep -Ee '^\s*#\s*define\s+LIB_JSONNET_VERSION\s+"[^"]+"\s*$' include/libjsonnet.h | sed -E -e 's/[^"]+"([^"]+)".*/\1/')" |
| 19 |
|
| 20 |
# GITHUB_REF is set by GH actions, see |
| 21 |
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables |
| 22 |
|
| 23 |
VERSION_SUFFIX= |
| 24 |
if [[ ( "${GITHUB_REF_TYPE}" != 'branch' || "${GITHUB_REF_NAME}" != "prepare-release" ) && |
| 25 |
( "${GITHUB_REF_TYPE}" != 'tag' || "${GITHUB_REF_NAME}" != "${JSONNET_VERSION}" ) ]]; then |
| 26 |
>&2 echo 'WARNING: Jsonnet library version in header does not match release ref. Adding commit suffix.' |
| 27 |
VERSION_SUFFIX="-${GITHUB_SHA:0:9}" |
| 28 |
fi |
| 29 |
|
| 30 |
# A prefix is added to better match the GitHub generated archives. |
| 31 |
PREFIX="jsonnet-${JSONNET_VERSION}${VERSION_SUFFIX}" |
| 32 |
ARCHIVE="jsonnet-${JSONNET_VERSION}${VERSION_SUFFIX}.tar.gz" |
| 33 |
git archive --format=tar --prefix=${PREFIX}/ "${GITHUB_SHA}" | gzip > "$ARCHIVE" |
| 34 |
ARCHIVE_SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}') |
| 35 |
|
| 36 |
echo "archive_sha256=${ARCHIVE_SHA}" >> "$GITHUB_OUTPUT" |
| 37 |
echo "jsonnet_version=${JSONNET_VERSION}" >> "$GITHUB_OUTPUT" |
| 38 |
echo "jsonnet_version_permanent=${JSONNET_VERSION}${VERSION_SUFFIX}" >> "$GITHUB_OUTPUT" |