Reorganization

This commit is contained in:
2025-12-26 23:27:20 -06:00
parent ed06a43ea4
commit b2839c10a5
18 changed files with 1 additions and 1 deletions

View File

@@ -0,0 +1,122 @@
#!/usr/bin/env bash
# -----------------------------------------------------------------------------
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
#
# This file is part of a Moko Consulting project.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software; you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free Software
# Foundation; either version 3 of the License, or (at your option) any later
# version.
#
# This program is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License (./LICENSE.md).
# -----------------------------------------------------------------------------
# FILE INFORMATION
# DEFGROUP: MokoStandards
# INGROUP: Generic.Script
# REPO: https://github.com/mokoconsulting-tech/MokoDefaults
# PATH: /scripts/update_changelog.sh
# VERSION: 03.05.00
# BRIEF: Insert a versioned CHANGELOG.md entry immediately after the main Changelog heading
# Purpose:
# - Apply the MokoWaaS-Brand CHANGELOG template entry for a given version.
# - Insert a new header at the top of CHANGELOG.md, immediately after "# Changelog".
# - Avoid duplicates if an entry for the version already exists.
# - Preserve the rest of the file verbatim.
#
# Usage:
# ./scripts/update_changelog.sh <VERSION>
#
# Example:
# ./scripts/update_changelog.sh 01.05.00
# =============================================================================
set -euo pipefail
CHANGELOG_FILE="CHANGELOG.md"
die() {
echo "ERROR: $*" 1>&2
exit 1
}
info() {
echo "INFO: $*"
}
require_cmd() {
command -v "$1" >/dev/null 2>&1 || die "Missing required command: $1"
}
validate_version() {
local v="$1"
[[ "$v" =~ ^[0-9]{2}\.[0-9]{2}\.[0-9]{2}$ ]] || die "Invalid version '$v'. Expected NN.NN.NN (example 03.01.00)."
}
main() {
require_cmd awk
require_cmd grep
require_cmd mktemp
require_cmd date
[[ $# -eq 1 ]] || die "Usage: $0 <VERSION>"
local version="$1"
validate_version "$version"
[[ -f "$CHANGELOG_FILE" ]] || die "Missing $CHANGELOG_FILE in repo root."
if ! grep -qE '^# Changelog[[:space:]]*$' "$CHANGELOG_FILE"; then
die "$CHANGELOG_FILE must contain a top level heading exactly: # Changelog"
fi
if grep -qE "^## \[$version\][[:space:]]" "$CHANGELOG_FILE"; then
info "CHANGELOG.md already contains an entry for version $version. No action taken."
exit 0
fi
local stamp
stamp="$(date '+%Y-%m-%d')"
local tmp
tmp="$(mktemp)"
trap 'rm -f "$tmp"' EXIT
awk -v v="$version" -v d="$stamp" '
BEGIN { inserted=0 }
{
print $0
if (inserted==0 && $0 ~ /^# Changelog[[:space:]]*$/) {
print ""
print "## [" v "] " d
print "- Version bump."
print ""
inserted=1
}
}
END {
if (inserted==0) {
exit 3
}
}
' "$CHANGELOG_FILE" > "$tmp" || {
rc=$?
if [[ $rc -eq 3 ]]; then
die "Insertion point not found. Expected: # Changelog"
fi
die "Failed to update $CHANGELOG_FILE (awk exit code $rc)."
}
mv "$tmp" "$CHANGELOG_FILE"
trap - EXIT
info "Inserted CHANGELOG.md entry for version $version on $stamp."
}
main "$@"

131
scripts/release/dates.sh Normal file
View File

@@ -0,0 +1,131 @@
#!/usr/bin/env bash
#
# Copyright (C) 2025 Moko Consulting <hello@mokoconsulting.tech>
#
# This file is part of a Moko Consulting project.
#
# SPDX-License-Identifier: GPL-3.0-or-later
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <https://www.gnu.org/licenses/>.
#
# FILE INFORMATION
# DEFGROUP: Release.Automation
# INGROUP: Date.Normalization
# REPO: https://github.com/mokoconsulting-tech/MokoStandards
# PATH: /scripts/update_dates.sh
# VERSION: 03.05.00
# BRIEF: Normalize release dates across manifests and CHANGELOG using a single authoritative UTC date.
# NOTE: Repo-controlled script only. CI-fatal on malformed inputs. Outputs a JSON report to stdout.
set -euo pipefail
TODAY_UTC="${1:-}"
VERSION="${2:-}"
usage() {
echo "ERROR: Usage: update_dates.sh <YYYY-MM-DD> <VERSION>" >&2
}
if [ -z "${TODAY_UTC}" ] || [ -z "${VERSION}" ]; then
usage
exit 1
fi
# Validate date format strictly
if ! echo "${TODAY_UTC}" | grep -Eq '^[0-9]{4}-[0-9]{2}-[0-9]{2}$'; then
echo "ERROR: Invalid date format. Expected YYYY-MM-DD, got '${TODAY_UTC}'" >&2
exit 1
fi
# Validate version format strictly
if ! echo "${VERSION}" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "ERROR: Invalid version format. Expected X.Y.Z, got '${VERSION}'" >&2
exit 1
fi
# Cross-platform sed in-place helper (GNU and BSD)
# - Ubuntu runners use GNU sed, but this keeps local execution deterministic.
sed_inplace() {
local expr="$1"
local file="$2"
if sed --version >/dev/null 2>&1; then
sed -i -E "${expr}" "${file}"
else
sed -i '' -E "${expr}" "${file}"
fi
}
echo "Normalizing dates to ${TODAY_UTC} for version ${VERSION}"
# Update CHANGELOG.md heading date
if [ ! -f CHANGELOG.md ]; then
echo "ERROR: CHANGELOG.md not found" >&2
exit 1
fi
if ! grep -Eq "^## \[${VERSION}\]" CHANGELOG.md; then
echo "ERROR: CHANGELOG.md does not contain heading for version [${VERSION}]" >&2
exit 1
fi
# Use a delimiter that will not collide with the pattern (the heading starts with "##")
sed_inplace "s|^(## \[${VERSION}\]) .*|\1 ${TODAY_UTC}|" CHANGELOG.md
# Update XML manifest dates
XML_SCANNED=0
XML_TOUCHED=0
while IFS= read -r -d '' FILE; do
XML_SCANNED=$((XML_SCANNED + 1))
BEFORE_HASH=""
AFTER_HASH=""
# Best-effort content hash for change detection without external deps.
if command -v sha256sum >/dev/null 2>&1; then
BEFORE_HASH="$(sha256sum "${FILE}" | awk '{print $1}')"
fi
# Use # delimiter because XML does not include # in these tags.
sed -i "s#<creationDate>[^<]*</creationDate>#<creationDate>${TODAY_UTC}</creationDate>#g" "${FILE}" || true
sed -i "s#<date>[^<]*</date>#<date>${TODAY_UTC}</date>#g" "${FILE}" || true
sed -i "s#<buildDate>[^<]*</buildDate>#<buildDate>${TODAY_UTC}</buildDate>#g" "${FILE}" || true
if [ -n "${BEFORE_HASH}" ]; then
AFTER_HASH="$(sha256sum "${FILE}" | awk '{print $1}')"
if [ "${BEFORE_HASH}" != "${AFTER_HASH}" ]; then
XML_TOUCHED=$((XML_TOUCHED + 1))
fi
fi
done < <(
find . -type f -name "*.xml" \
-not -path "./.git/*" \
-not -path "./.github/*" \
-not -path "./dist/*" \
-not -path "./node_modules/*" \
-print0
)
# JSON report to stdout (workflow can capture or include in summary)
printf '{"today_utc":"%s","version":"%s","changelog":"%s","xml_scanned":%s,"xml_touched":%s}
' \
"${TODAY_UTC}" \
"${VERSION}" \
"CHANGELOG.md" \
"${XML_SCANNED}" \
"${XML_TOUCHED}"
echo "Date normalization complete."