#!/usr/bin/env bash set -euo pipefail create_release() { local -r owner="$1" repo="$2" token="$3" version="$4" body_file="$5" local -i max_attempts=3 delay=5 attempt local http status # Read release body for JSON payload local body_json body_json=$(tail -n +2 "$body_file" | jq -Rs .) for (( attempt=1; attempt<=max_attempts; attempt++ )); do echo "🚀 Try $attempt/$max_attempts: creating release v$version …" http=$(curl -sS \ -H "Authorization: token $token" \ -H "Content-Type: application/json" \ -o resp.json -w '%{http_code}' \ -X POST "$GITHUB_API_URL/repos/$owner/$repo/releases" \ -d @- < "$RELEASE_BODY_TMP" # === Step 3: Commit changelog === git add "$CHANGELOG_FILE" if git diff --cached --quiet; then echo "✅ No changes to commit" else echo "📝 Committing updated changelog" git commit -m "chore(changelog): update changelog for v$VERSION" git push origin main fi # === Step 4: Create tag if necessary === if git rev-parse "v$VERSION" >/dev/null 2>&1; then echo "🔁 Tag v$VERSION already exists, skipping." else echo "🏷️ Creating annotated tag v$VERSION" export GIT_AUTHOR_DATE="@$(date +%s)" export GIT_COMMITTER_DATE="$GIT_AUTHOR_DATE" git tag -a "v$VERSION" -F "$RELEASE_BODY_TMP" --cleanup=verbatim git push origin "v$VERSION" fi # === Step 5: Create release (with retry) === OWNER="${GITHUB_REPOSITORY%/*}" REPO="${GITHUB_REPOSITORY#*/}" TOKEN="${RELEASE_PUBLISH_TOKEN:-$ACTIONS_RUNTIME_TOKEN}" if [[ -z "${RELEASE_PUBLISH_TOKEN:-}" ]]; then echo "::warning title=Limited Release Propagation::" echo "RELEASE_PUBLISH_TOKEN is not set. Using ACTIONS_RUNTIME_TOKEN instead." echo "⚠️ Release events may not trigger other workflows if created with the runtime token." echo fi create_release "$OWNER" "$REPO" "$TOKEN" "$VERSION" "$RELEASE_BODY_TMP" echo "🎉 Workflow finished successfully."