From 9cd0cd006c3ce0200aa42145b8d41b5789b1b6f0 Mon Sep 17 00:00:00 2001 From: John Bartholomew Date: Thu, 13 Mar 2025 00:42:33 +0000 Subject: [PATCH] ci: create a stable source archive attached to the release --- .github/workflows/create_archive.sh | 25 +++++++++++++++++++++++++ .github/workflows/release.yml | 20 ++++++++++++++++++++ 2 files changed, 45 insertions(+) create mode 100755 .github/workflows/create_archive.sh diff --git a/.github/workflows/create_archive.sh b/.github/workflows/create_archive.sh new file mode 100755 index 0000000..d493d63 --- /dev/null +++ b/.github/workflows/create_archive.sh @@ -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" diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 2035ccd..71b5095 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -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