ci: create a stable source archive attached to the release

This commit is contained in:
John Bartholomew 2025-03-13 00:42:33 +00:00
parent 2a3f4afd6a
commit 9cd0cd006c
2 changed files with 45 additions and 0 deletions

25
.github/workflows/create_archive.sh vendored Executable file
View File

@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -o errexit -o nounset -o pipefail
JSONNET_VERSION="$(grep -Ee '^\s*const\s+version\s*=\s*"[^"]+"\s*$' vm.go | sed -E -e 's/[^"]+"([^"]+)".*/\1/')"
# GITHUB_REF is set by GH actions, see
# https://docs.github.com/en/actions/learn-github-actions/environment-variables#default-environment-variables
VERSION_SUFFIX=
if [[ ( "${GITHUB_REF_TYPE}" != 'branch' || "${GITHUB_REF_NAME}" != "prepare-release" ) &&
( "${GITHUB_REF_TYPE}" != 'tag' || "${GITHUB_REF_NAME}" != "${JSONNET_VERSION}" ) ]]; then
>&2 echo 'WARNING: Jsonnet library version in header does not match release ref. Adding commit suffix.'
VERSION_SUFFIX="-${GITHUB_SHA:0:9}"
fi
# A prefix is added to better match the GitHub generated archives.
PREFIX="go-jsonnet-${JSONNET_VERSION}${VERSION_SUFFIX}"
ARCHIVE="go-jsonnet-${JSONNET_VERSION}${VERSION_SUFFIX}.tar.gz"
git archive --format=tar --prefix="${PREFIX}"/ "${GITHUB_SHA}" | gzip > "$ARCHIVE"
ARCHIVE_SHA=$(shasum -a 256 "$ARCHIVE" | awk '{print $1}')
echo "archive_sha256=${ARCHIVE_SHA}" >> "$GITHUB_OUTPUT"
echo "go_jsonnet_version=${JSONNET_VERSION}" >> "$GITHUB_OUTPUT"
echo "go_jsonnet_version_permanent=${JSONNET_VERSION}${VERSION_SUFFIX}" >> "$GITHUB_OUTPUT"

View File

@ -38,3 +38,23 @@ jobs:
with:
version: latest
args: release --clean --draft
create_source_archive:
permissions:
contents: write
runs-on: ubuntu-22.04
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Create release archive
id: create_archive
run: .github/workflows/create_archive.sh
- name: Release
uses: softprops/action-gh-release@c95fe1489396fe8a9eb87c0abf8aa5b2ef267fda # v2.2.1
with:
name: ${{ steps.create_archive.outputs.go_jsonnet_version }}
tag_name: ${{ steps.create_archive.outputs.go_jsonnet_version }}
prerelease: ${{ inputs.prerelease }}
draft: true
fail_on_unmatched_files: true
files: go-jsonnet-*.tar.gz