Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'origin/master' into dixler/10668/patch-…
…state-once
- Loading branch information
Showing
84 changed files
with
2,754 additions
and
3,244 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
>&2 echo "::group::Get changelog" | ||
trap ">&2 echo '::endgroup::'" EXIT # bash equivalent of defer func() | ||
|
||
# Argument must be a committish or release tag. | ||
PREVIOUS_VERSION="${1:-""}" | ||
if [ -z "${PREVIOUS_VERSION}" ]; then | ||
>&2 echo "::warn::Previous version argument missing, use a release tag or commitish." | ||
PREVIOUS_VERSION=$(git rev-list --max-parents=0 HEAD) | ||
fi | ||
# All other arguments are passed to git-cliff as is. | ||
shift 1 | ||
|
||
# For debugging, use a commit other than HEAD as the 'current commit' to calculate the changelog. | ||
CURRENT_COMMIT="${CURRENT_COMMIT:-"HEAD"}" | ||
|
||
if git merge-base --is-ancestor "${PREVIOUS_VERSION}" "${CURRENT_COMMIT}"; then | ||
>&2 echo "::debug::Previous version is an ancestor." | ||
MERGE_BASE="${PREVIOUS_VERSION}" | ||
else | ||
>&2 echo "::debug::Previous version is not an ancestor, finding best common ancestor." | ||
MERGE_BASE="$(git merge-base "${PREVIOUS_VERSION}" "${CURRENT_COMMIT}")" | ||
fi | ||
|
||
>&2 echo "::debug::Merge base ${MERGE_BASE}" | ||
|
||
go run github.com/aaronfriel/go-change@v0.1.0 render --filter-since-commit "${MERGE_BASE}" "${@}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
>&2 echo "::group::Get changelog comment" | ||
trap ">&2 echo '::endgroup::'" EXIT # bash equivalent of defer func() | ||
|
||
# Get the changelog as it would rendered on a pull request comment. | ||
|
||
PREVIOUS_VERSION="$1" | ||
CHANGELOG_REQUIRED="${2:-"true"}" | ||
PULL_REQUEST_NUMBER="${3}" | ||
|
||
CHANGELOG=$(./.github/scripts/get-changelog "${PREVIOUS_VERSION}" --version "[uncommitted]" --filter-open-pr-number "${PULL_REQUEST_NUMBER}") | ||
if [ -n "${CHANGELOG}" ]; then | ||
echo -n "${CHANGELOG}" || true | ||
else | ||
echo -n "n/a" | ||
if [ "${CHANGELOG_REQUIRED}" != "false" ]; then | ||
>&2 echo "::error::Changelog not present" | ||
exit 1 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
>&2 echo "::group::Get version" | ||
trap ">&2 echo '::endgroup::'" EXIT # bash equivalent of defer func() | ||
|
||
PREVIOUS_VERSION="${1:-""}" | ||
if [ -z "$PREVIOUS_VERSION" ]; then | ||
PREVIOUS_VERSION="$(.github/scripts/get-version)" | ||
fi | ||
|
||
if [[ "${PREVIOUS_VERSION}" = *-*.* ]]; then | ||
VERSION="${PREVIOUS_VERSION%.*}.$((${PREVIOUS_VERSION##*.} + 1))" | ||
else | ||
IFS=. read -r major minor rest <<< "${PREVIOUS_VERSION}" | ||
VERSION="TAG=${major}.$((minor + 1)).0" | ||
fi | ||
|
||
echo -n "$VERSION" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#!/usr/bin/env bash | ||
set -euo pipefail | ||
|
||
STDERR=$(mktemp -t previous-version-output.XXXXXX) | ||
|
||
# Capture the stderr and success status of this command: | ||
set +e | ||
PREVIOUS_VERSION="$(gh release view --json 'tagName' -q '.tagName' 2>"${STDERR}")" | ||
SUCCESS=$? | ||
set -e | ||
# If we fail, but the error is that the release doesn't exist, then we can | ||
# assume that the previous version is the first release. | ||
|
||
if [ "$SUCCESS" = "0" ]; then | ||
>&2 echo "::debug::Found previous GitHub release ${PREVIOUS_VERSION}" | ||
echo -n "${PREVIOUS_VERSION}" | ||
elif cat "${STDERR}" | grep -q 'HTTP 404: Not Found'; then | ||
>&2 echo "::warn::No previous release ($(cat "${STDERR}")), using initial commit" | ||
git rev-list --max-parents=0 HEAD | ||
else | ||
>&2 echo "::error::No previous release ($(cat "${STDERR}"))" | ||
exit 1 | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
ROOT=$(dirname "${0}")/../.. | ||
|
||
>&2 echo "::group::Get version" | ||
trap ">&2 echo '::endgroup::'" EXIT # bash equivalent of defer func() | ||
|
||
# Remove whitespace, this is our version: | ||
tr -d '[:space:]' < "${ROOT}/.version" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
#!/usr/bin/env bash | ||
|
||
# Sets an output value in GitHub Actions, escaping quotes, newlines, and special characters by JSON | ||
# stringifying it. | ||
# | ||
# To use this, invoke the script with an output variable name and quoted value, and then declare the | ||
# output like so: | ||
# | ||
# ```github-action.yaml | ||
# job: | ||
# steps: | ||
# - run: | | ||
# .github/scripts/set-output my-output "$(some-shell-command ...)" | ||
# outputs: | ||
# my-output: "${{ fromJSON(steps.job.outputs.my-output) }}" | ||
# ``` | ||
|
||
|
||
set -euo pipefail | ||
|
||
OUTPUT_NAME="$1" | ||
VALUE="$2" | ||
|
||
ESCAPED="$(echo -n "${VALUE}" | jq -Rsc ".")" # JSON encode | ||
echo "::set-output name=${OUTPUT_NAME}::${ESCAPED}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -euo pipefail | ||
|
||
>&2 echo "::group::Update versions" | ||
trap ">&2 echo '::endgroup::'" EXIT # bash equivalent of defer func() | ||
|
||
INPUT_VERSION="$1" | ||
BUILD="$(cut -d'+' -f2 <<< "$INPUT_VERSION")" # may not be present | ||
VERSION_PRERELEASE="$(cut -d'+' -f1 <<< "$INPUT_VERSION")" | ||
|
||
VERSION="$(cut -d'-' -f1 <<< "$VERSION_PRERELEASE")" | ||
PRERELEASE="$(cut -d'-' -f2 <<< "$VERSION_PRERELEASE")" # may not be present | ||
|
||
MAJOR="$(cut -d'.' -f1 <<< "$VERSION")" | ||
MINOR="$(cut -d'.' -f2 <<< "$VERSION")" | ||
PATCH="$(cut -d'.' -f3 <<< "$VERSION")" | ||
|
||
>&2 echo "::debug::INPUT_VERSION=$INPUT_VERSION" | ||
>&2 echo "::debug::VERSION=$VERSION" | ||
>&2 echo "::debug::PRERELEASE=$PRERELEASE" | ||
>&2 echo "::debug::MAJOR=$MAJOR" | ||
>&2 echo "::debug::MAJOR=$MINOR" | ||
>&2 echo "::debug::MINOR=$PATCH" | ||
>&2 echo "::debug::BUILD=$BUILD" | ||
|
||
PIPX_MISSING=false | ||
if ! command -v pipx &>/dev/null; then | ||
>&2 echo "::error::pipx not installed, install pipx via pypi or homebrew" | ||
PIPX_MISSING=true | ||
fi | ||
|
||
JQ_MISSING=false | ||
if ! command -v jq &>/dev/null; then | ||
>&2 echo "::error::yq not installed, install jq via your OS package manager" | ||
JQ_MISSING=true | ||
fi | ||
|
||
if $JQ_MISSING || $PIPX_MISSING; then | ||
exit 1; | ||
fi | ||
|
||
yq() { | ||
pipx run yq==3.0.2 "$@" | ||
} | ||
|
||
N=$(yq '.replacements | length' .github/scripts/versions.yaml) | ||
for n in $(seq 0 1 "$((N-1))"); do | ||
replacement=$(yq ".replacements[$n]" .github/scripts/versions.yaml) | ||
type=$(yq -r '.type' <<< "$replacement") | ||
|
||
case "$type" in | ||
"file") | ||
file=$(yq -r '.file' <<< "$replacement") | ||
fileFormat=$(yq -r '.fileFormat' <<< "$replacement") | ||
updatePath=$(yq -r '.updatePath' <<< "$replacement") | ||
versionFormat=$(yq -r '.versionFormat' <<< "$replacement") | ||
|
||
TOOL="jq" | ||
TOOL_ARGS="" | ||
SPONGE=false | ||
case "$fileFormat" in | ||
"sed") TOOL="sed";; | ||
"json") TOOL="jq" TOOL_ARGS="--in-place";; | ||
"yaml") TOOL="yq" TOOL_ARGS="--in-place";; | ||
*) | ||
>&2 echo "::error::Unknown file format $fileFormat; unable to update file $file" | ||
exit 1 | ||
esac | ||
|
||
tool() { | ||
if $SPONGE; then | ||
TEMP="$("$TOOL" "$@")" | ||
echo -n "$TEMP" > "$file" | ||
else | ||
"$TOOL" "$@" | ||
fi | ||
} | ||
|
||
# Use a subshell to avoid mutating our caller's environment. | ||
# envsubst requires exported variables | ||
( | ||
export SEMVER="$INPUT_VERSION" | ||
export VERSION | ||
export MAJOR | ||
export MINOR | ||
export PATCH | ||
export PRERELEASE | ||
export BUILD | ||
|
||
# We do not want to expand vars to envsubst, we're listing the ones we want to allow. | ||
# shellcheck disable=SC2016 | ||
versionString=$(envsubst '$SEMVER,$VERSION,$MAJOR,$MINOR,$PATCH,$PRERELEASE,$BUILD' <<< "$versionFormat") | ||
|
||
if [ "$TOOL" == "sed" ]; then | ||
sed --in-place -E "s/$updatePath/$versionString/" "$file" | ||
else | ||
tool $TOOL_ARGS "$updatePath = \"$versionString\"" "$file" | ||
fi | ||
) | ||
;; | ||
"command") | ||
command=$(yq -r '.command' <<< "$replacement") | ||
eval "${command}" | ||
;; | ||
*) | ||
>&2 echo "::error::Unknown replacement type $type" | ||
exit 1 | ||
;; | ||
esac | ||
done |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
replacements: | ||
- type: file | ||
file: .version | ||
fileFormat: sed | ||
updatePath: .* | ||
versionFormat: ${SEMVER} |
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.