Prepare script for release
Some checks failed
CI / Lint & Format (push) Has been cancelled
CI / Build (push) Has been cancelled
CI / Tests (${{ matrix.browser }}) (chromium) (push) Has been cancelled
CI / Tests (${{ matrix.browser }}) (firefox) (push) Has been cancelled

This commit is contained in:
David 2026-07-24 09:51:29 +02:00
parent 9be91dfc84
commit 056ca9abcc

View file

@ -16,6 +16,17 @@ SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)" ROOT_DIR="$(cd "$SCRIPT_DIR/.." && pwd)"
cd "$ROOT_DIR" cd "$ROOT_DIR"
# Print a recovery hint if the script dies between the version bump and the commit.
BUMPED=0
COMMITTED=0
on_exit() {
if [[ $? -ne 0 && "$BUMPED" == "1" && "$COMMITTED" == "0" ]]; then
echo -e "\n${YELLOW}⚠ Release interrupted after the version bump.${NC}" >&2
echo " To undo it: git checkout -- package.json package-lock.json" >&2
fi
}
trap on_exit EXIT
# ── Prerequisites ───────────────────────────────────────────────────────────── # ── Prerequisites ─────────────────────────────────────────────────────────────
echo "" echo ""
echo -e "${BOLD}Checking prerequisites...${NC}" echo -e "${BOLD}Checking prerequisites...${NC}"
@ -35,6 +46,28 @@ if [[ "$CURRENT_BRANCH" != "main" ]]; then
fi fi
info "On branch: $CURRENT_BRANCH" info "On branch: $CURRENT_BRANCH"
# ── Quality gate ──────────────────────────────────────────────────────────────
echo ""
echo -e "${BOLD}Quality gate${NC}"
echo " Running: npm run lint"
npm run lint --silent || error "Lint failed. Fix the issues before releasing."
info "Lint passed."
echo " Running: npm run format:check"
npm run format:check --silent || error "Formatting check failed. Run 'npm run format' and commit."
info "Formatting is clean."
echo -n " Run the Playwright test suite now? (slow) [Y/n] "
read -r RUN_TESTS
if [[ "$RUN_TESTS" =~ ^[Nn] ]]; then
warn "Tests skipped — make sure the suite passed recently."
else
echo " Running: npm run test:parallel"
npm run test:parallel || error "Tests failed. Fix them before releasing."
info "Tests passed on Firefox and Chromium."
fi
# ── Commits since last release ──────────────────────────────────────────────── # ── Commits since last release ────────────────────────────────────────────────
echo "" echo ""
echo -e "${BOLD}Changes since last release${NC}" echo -e "${BOLD}Changes since last release${NC}"
@ -46,12 +79,6 @@ if [[ -n "$LAST_TAG" ]]; then
echo " Commits since $LAST_TAG:" echo " Commits since $LAST_TAG:"
echo "" echo ""
COMMIT_LOG=$(git log "${LAST_TAG}..HEAD" --oneline --no-merges) COMMIT_LOG=$(git log "${LAST_TAG}..HEAD" --oneline --no-merges)
else
warn "No previous tag found — listing all commits."
echo ""
COMMIT_LOG=$(git log --oneline --no-merges)
fi
if [[ -z "$COMMIT_LOG" ]]; then if [[ -z "$COMMIT_LOG" ]]; then
warn "No commits since $LAST_TAG. Are you sure you want to release?" warn "No commits since $LAST_TAG. Are you sure you want to release?"
else else
@ -59,6 +86,10 @@ else
echo -e " ${DIM}${line}${NC}" echo -e " ${DIM}${line}${NC}"
done <<< "$COMMIT_LOG" done <<< "$COMMIT_LOG"
fi fi
else
COMMIT_LOG=""
info "No previous tag — this is the first release."
fi
echo "" echo ""
@ -73,8 +104,9 @@ read -r VERSION
|| error "Invalid format. Use MAJOR.MINOR.PATCH without a 'v' prefix." || error "Invalid format. Use MAJOR.MINOR.PATCH without a 'v' prefix."
TAG="v$VERSION" TAG="v$VERSION"
ARCHIVE="trainus-${TAG}-src.zip" mkdir -p tmp
NOTES_FILE="trainus-${TAG}-notes.md" ARCHIVE="tmp/trainus-${TAG}-src.zip"
NOTES_FILE="tmp/trainus-${TAG}-notes.md"
git tag --list | grep -q "^${TAG}$" \ git tag --list | grep -q "^${TAG}$" \
&& error "Tag $TAG already exists locally." && error "Tag $TAG already exists locally."
@ -99,7 +131,7 @@ echo " 5. Create a source archive of the current commit"
echo " $ARCHIVE (tracked files only, no node_modules, no dist)" echo " $ARCHIVE (tracked files only, no node_modules, no dist)"
echo "" echo ""
echo " 6. Generate a draft release notes file for you to edit" echo " 6. Generate a draft release notes file for you to edit"
echo " $NOTES_FILE (pre-filled with the commit list above)" echo " $NOTES_FILE (pre-filled draft to edit)"
echo "" echo ""
echo -e "${YELLOW}Nothing will be pushed or sent anywhere. All steps are local.${NC}" echo -e "${YELLOW}Nothing will be pushed or sent anywhere. All steps are local.${NC}"
echo "" echo ""
@ -111,6 +143,7 @@ read -r CONFIRM
doing "Step 1/6 — Bumping version in package.json and package-lock.json" doing "Step 1/6 — Bumping version in package.json and package-lock.json"
echo " Running: npm version $VERSION --no-git-tag-version" echo " Running: npm version $VERSION --no-git-tag-version"
npm version "$VERSION" --no-git-tag-version --silent npm version "$VERSION" --no-git-tag-version --silent
BUMPED=1
info "package.json and package-lock.json updated to $VERSION." info "package.json and package-lock.json updated to $VERSION."
# ── Step 2 — Build ──────────────────────────────────────────────────────────── # ── Step 2 — Build ────────────────────────────────────────────────────────────
@ -125,6 +158,7 @@ echo " Running: git add package.json package-lock.json"
echo " git commit -m \"chore: release $TAG\"" echo " git commit -m \"chore: release $TAG\""
git add package.json package-lock.json git add package.json package-lock.json
git commit -m "chore: release $TAG" git commit -m "chore: release $TAG"
COMMITTED=1
info "Commit created: chore: release $TAG" info "Commit created: chore: release $TAG"
# ── Step 4 — Tag ────────────────────────────────────────────────────────────── # ── Step 4 — Tag ──────────────────────────────────────────────────────────────
@ -145,15 +179,12 @@ echo " Excludes: node_modules/, dist/, .git/, and any untracked files."
doing "Step 6/6 — Generating draft release notes" doing "Step 6/6 — Generating draft release notes"
echo " Writing: $NOTES_FILE" echo " Writing: $NOTES_FILE"
if [[ -n "$LAST_TAG" ]]; then
RANGE_LABEL="since $LAST_TAG"
else
RANGE_LABEL="(no previous tag — all commits)"
fi
{ {
echo "# TrainUs $TAG — Release notes" echo "# TrainUs $TAG — Release notes"
echo "" echo ""
if [[ -z "$LAST_TAG" ]]; then
echo "First release $VERSION."
else
echo "<!-- Edit this file before pasting into Forgejo. Delete comments. -->" echo "<!-- Edit this file before pasting into Forgejo. Delete comments. -->"
echo "" echo ""
echo "## What's new" echo "## What's new"
@ -174,7 +205,7 @@ fi
echo "" echo ""
echo "---" echo "---"
echo "" echo ""
echo "## Commits $RANGE_LABEL" echo "## Commits since $LAST_TAG"
echo "" echo ""
echo "<!-- For reference — trim or reword before publishing. -->" echo "<!-- For reference — trim or reword before publishing. -->"
echo "" echo ""
@ -185,6 +216,7 @@ fi
else else
echo "- (none)" echo "- (none)"
fi fi
fi
} > "$NOTES_FILE" } > "$NOTES_FILE"
info "Draft release notes written to $NOTES_FILE." info "Draft release notes written to $NOTES_FILE."
@ -229,6 +261,6 @@ echo " Fill in the placeholders — set draft: false when ready."
echo " Write the French version yourself." echo " Write the French version yourself."
echo " Rebuild and redeploy the website (step 5)." echo " Rebuild and redeploy the website (step 5)."
echo "" echo ""
echo -e " ${BOLD}7. Clean up local artifacts${NC}" echo -e " ${BOLD}7. Clean up local artifacts (optional — tmp/ is gitignored)${NC}"
echo " Once uploaded and published: rm $ARCHIVE $NOTES_FILE" echo " Once uploaded and published: rm $ARCHIVE $NOTES_FILE"
echo "" echo ""