test workflow
This commit is contained in:
@@ -6,10 +6,19 @@ set -euo pipefail
|
||||
: "${DOWNLOAD_URL_TEMPLATE:?DOWNLOAD_URL_TEMPLATE is required}"
|
||||
: "${RELEASE_API_REPO:?RELEASE_API_REPO is required}"
|
||||
|
||||
if command -v python >/dev/null 2>&1; then
|
||||
PYTHON_BIN=python
|
||||
elif command -v python3 >/dev/null 2>&1; then
|
||||
PYTHON_BIN=python3
|
||||
else
|
||||
echo "python is required but was not found"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
version_strip_prefix="${LATEST_VERSION_STRIP_PREFIX:-v}"
|
||||
release_tag_template="${RELEASE_TAG_TEMPLATE:-{version}}"
|
||||
|
||||
current_version=$(python - <<'PY'
|
||||
current_version=$($PYTHON_BIN - <<'PY'
|
||||
import re
|
||||
import os
|
||||
p=os.environ['FILE']
|
||||
@@ -35,12 +44,12 @@ if [ -z "$latest_version" ] || [ "$latest_version" = "$current_version" ]; then
|
||||
fi
|
||||
|
||||
download_url="${DOWNLOAD_URL_TEMPLATE//\{version\}/$latest_version}"
|
||||
new_hash=$(nix store prefetch-file --json "$download_url" | python -c 'import json,sys; print(json.load(sys.stdin)["hash"])')
|
||||
new_hash=$(nix store prefetch-file --json "$download_url" | "$PYTHON_BIN" -c 'import json,sys; print(json.load(sys.stdin)["hash"])')
|
||||
|
||||
export LATEST_VERSION="$latest_version"
|
||||
export NEW_HASH="$new_hash"
|
||||
|
||||
python - <<'PY'
|
||||
"$PYTHON_BIN" - <<'PY'
|
||||
import os
|
||||
import re
|
||||
p=os.environ['FILE']
|
||||
@@ -55,12 +64,29 @@ echo "version=$latest_version" >> "$GITHUB_OUTPUT"
|
||||
echo "previous_version=$current_version" >> "$GITHUB_OUTPUT"
|
||||
|
||||
release_tag="${release_tag_template//\{version\}/$latest_version}"
|
||||
release_notes=$(curl -fsSL "https://api.github.com/repos/${RELEASE_API_REPO}/releases/tags/${release_tag}" \
|
||||
| python -c 'import json,sys; d=json.load(sys.stdin); print((d.get("body") or "").strip())' \
|
||||
|| true)
|
||||
api_url="https://api.github.com/repos/${RELEASE_API_REPO}/releases/tags/${release_tag}"
|
||||
|
||||
curl_headers=(
|
||||
-H "Accept: application/vnd.github+json"
|
||||
-H "X-GitHub-Api-Version: 2022-11-28"
|
||||
)
|
||||
if [ -n "${GITHUB_TOKEN:-}" ]; then
|
||||
curl_headers+=( -H "Authorization: Bearer ${GITHUB_TOKEN}" )
|
||||
fi
|
||||
|
||||
api_response=$(curl -sS -w '\n%{http_code}' "${curl_headers[@]}" "$api_url" || true)
|
||||
api_body=$(printf '%s\n' "$api_response" | sed '$d')
|
||||
api_code=$(printf '%s\n' "$api_response" | tail -n1)
|
||||
|
||||
release_notes=""
|
||||
if [ "$api_code" = "200" ]; then
|
||||
release_notes=$(printf '%s' "$api_body" | "$PYTHON_BIN" -c 'import json,sys; d=json.load(sys.stdin); print((d.get("body") or "").strip())' || true)
|
||||
else
|
||||
echo "warning: failed to fetch release notes from GitHub API (status=$api_code, url=$api_url)"
|
||||
fi
|
||||
|
||||
if [ -z "$release_notes" ]; then
|
||||
release_notes="_No changelog found in upstream release notes._"
|
||||
release_notes="_No changelog found in upstream release notes. Check ${LATEST_RELEASE_URL%/latest}/tag/${release_tag}._"
|
||||
fi
|
||||
|
||||
delimiter="CHANGELOG_$(date +%s%N)"
|
||||
|
||||
Reference in New Issue
Block a user