refactor: move 'git archive' configuration to .gitattributes (#641)

Makes it match bazelbuild/rules_proto#189
This commit is contained in:
Alex Eagle 2023-11-01 09:00:27 -07:00 committed by GitHub
parent 602b7b8f80
commit 59ea86d7c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 16 additions and 11 deletions

11
.gitattributes vendored
View File

@ -1 +1,12 @@
# In code review, collapse generated files
docs/*.md linguist-generated=true docs/*.md linguist-generated=true
#################################
# Configuration for 'git archive'
# see https://git-scm.com/docs/git-archive#ATTRIBUTES
# Omit folders that users don't need, making the distribution artifact smaller
lib/tests export-ignore
# Substitution for the _VERSION_PRIVATE placeholder
tools/version.bzl export-subst

View File

@ -2,22 +2,16 @@
set -o errexit -o nounset -o pipefail set -o errexit -o nounset -o pipefail
# Configuration for 'git archive'
# see https://git-scm.com/docs/git-archive/2.40.0#ATTRIBUTES
cat >.git/info/attributes <<EOF
# Omit folders that users don't need, making the distribution artifact smaller
lib/tests export-ignore
# Substitution for the _VERSION_PRIVATE placeholder
tools/version.bzl export-subst
EOF
# Set by GH actions, see # Set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables # https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
TAG=${GITHUB_REF_NAME} TAG=${GITHUB_REF_NAME}
# The prefix is chosen to match what GitHub generates for source archives # The prefix is chosen to match what GitHub generates for source archives
# This guarantees that users can easily switch from a released artifact to a source archive
# with minimal differences in their code (e.g. strip_prefix remains the same)
PREFIX="bazel-lib-${TAG:1}" PREFIX="bazel-lib-${TAG:1}"
ARCHIVE="bazel-lib-$TAG.tar.gz" ARCHIVE="bazel-lib-$TAG.tar.gz"
# NB: configuration for 'git archive' is in /.gitattributes
git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE git archive --format=tar --prefix=${PREFIX}/ ${TAG} | gzip > $ARCHIVE
SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}') SHA=$(shasum -a 256 $ARCHIVE | awk '{print $1}')

View File

@ -1,7 +1,7 @@
"version information. replaced with stamped info with each release" "version information. replaced with stamped info with each release"
# This is automagically replace by git during git archive using `git export-subst` # This is automagically replace by git during git archive using `git export-subst`
# See https://git-scm.com/docs/git-archive/2.29.0#Documentation/git-archive.txt-export-subst # See https://git-scm.com/docs/git-archive#Documentation/git-archive.txt-export-subst
_VERSION_PRIVATE = "$Format:%(describe:tags=true)$" _VERSION_PRIVATE = "$Format:%(describe:tags=true)$"
VERSION = "0.0.0" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1) VERSION = "0.0.0" if _VERSION_PRIVATE.startswith("$Format") else _VERSION_PRIVATE.replace("v", "", 1)