Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 21 additions & 21 deletions scripts/save_release_notes.sh
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

set -euo pipefail
set -eu

trap 'printf "Interrupted. Cleaning up...\n" >&2' INT TERM

Expand All @@ -31,11 +31,12 @@ trap 'printf "Interrupted. Cleaning up...\n" >&2' INT TERM
save_release_notes() {
if [ "$#" -ne 1 ] && [ -z "${RELEASE_ID:-}" ]; then
printf "Usage: %s [release_id]\n" "$0" >&2
exit 1
fi

local release_id; release_id="${1:-${RELEASE_ID:-}}"
local github_token; github_token="${GH_TOKEN:-}"
local repo; repo="${GITHUB_REPOSITORY:-}"
release_id="${1:-${RELEASE_ID:-}}"
github_token="${GH_TOKEN:-}"
repo="${GITHUB_REPOSITORY:-}"

if [ -z "$release_id" ]; then
printf "Error: RELEASE_ID environment variable or argument is required.\n" >&2
Expand All @@ -54,27 +55,28 @@ save_release_notes() {

# 1. Generate filename: NTE-DDHYM
# Optimization: Single date call reduces process spawning.
# Using Bash string manipulation instead of cut/printf.
# DD: Day of month (01-31)
# H: Hour of day (0-N for 0-23)
# Y: Last digit of year
# M: Month (1-C for 1-12)

local dd h_val y_val m_val vars
vars=$(date "+%d %-H %y %-m")
vars=$(date "+%d %H %y %m")
dd=$(echo "$vars" | cut -d' ' -f1)
h_val=$(echo "$vars" | cut -d' ' -f2)
y_val=$(echo "$vars" | cut -d' ' -f3)
m_val=$(echo "$vars" | cut -d' ' -f4)

read -r dd h_val y_val m_val <<EOV
$vars
EOV
# Remove leading zeros to avoid octal interpretation in arithmetic
h_val_clean=$(echo "$h_val" | sed 's/^0//'); h_val_clean="${h_val_clean:-0}"
m_val_clean=$(echo "$m_val" | sed 's/^0//'); m_val_clean="${m_val_clean:-0}"

local hours="0123456789ABCDEFGHIJKLMN"
local h; h="${hours:$h_val:1}"
local y; y="${y_val:1:1}"
local months="123456789ABC"
local m_idx; m_idx=$((m_val - 1))
local m; m="${months:$m_idx:1}"
hours="0123456789ABCDEFGHIJKLMN"
h=$(echo "$hours" | cut -c "$((h_val_clean + 1))")
y=$(echo "$y_val" | cut -c 2)
months="123456789ABC"
m=$(echo "$months" | cut -c "$((m_val_clean + 0))")

local filename="Notes/NTE-${dd}${h}${y}${m}.md"
filename="Notes/NTE-${dd}${h}${y}${m}.md"

# 2. Ensure Notes directory and .gitkeep exist
mkdir -p Notes
Expand All @@ -83,8 +85,7 @@ EOV
fi

# 3. Fetch release body using curl -fsS and jq
local api_url="https://api.github.com/repos/${repo}/releases/${release_id}"
local body
api_url="https://api.github.com/repos/${repo}/releases/${release_id}"
body=$(curl -fsS -H "Authorization: token ${github_token}" \
-H "Accept: application/vnd.github.v3+json" \
"$api_url" | jq -r '.body')
Expand All @@ -97,7 +98,6 @@ EOV
fi

# 5. Git operations
# Optimization: Only perform network operations if there are changes to push.
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
git add "$filename" Notes/.gitkeep
Expand All @@ -110,4 +110,4 @@ EOV
fi
}

save_release_notes "$@"
(save_release_notes "$@")
Loading