Skip to content
Merged
Show file tree
Hide file tree
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
71 changes: 52 additions & 19 deletions .github/scripts/get-pr-details.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

set -euo pipefail

echo "Retrieving PR information..."
echo "Determining next SemVer..."

if [ -z "${GITHUB_TOKEN:-}" ]; then
echo "GITHUB_TOKEN not set"
Expand All @@ -13,35 +13,68 @@ OWNER="${GITHUB_REPOSITORY%%/*}"
REPO="${GITHUB_REPOSITORY##*/}"
SHA="${GITHUB_SHA}"

git fetch --tags
LATEST_TAG=$(git tag --list 'v*.*.*' --sort=-v:refname | head -n1 || true)

if [ -z "$LATEST_TAG" ]; then
LATEST_TAG="v0.0.0"
fi

echo "Latest tag: $LATEST_TAG"

VERSION="${LATEST_TAG#v}"
IFS='.' read -r MAJOR MINOR PATCH <<< "$VERSION"

PRS_JSON=$(curl -s \
-H "Authorization: Bearer $GITHUB_TOKEN" \
-H "Accept: application/vnd.github+json" \
"https://api.github.com/repos/$OWNER/$REPO/commits/$SHA/pulls")

echo "$PRS_JSON" | jq .

PR_COUNT=$(echo "$PRS_JSON" | jq length)

if [ "$PR_COUNT" -eq 0 ]; then
echo "No PR associated with this commit."
echo "title=" >> "$GITHUB_OUTPUT"
echo "body=" >> "$GITHUB_OUTPUT"
exit 0
exit 1
fi

TITLE=$(echo "$PRS_JSON" | jq -r '.[0].title // ""')
BODY=$(echo "$PRS_JSON" | jq -r '.[0].body // ""')
LABELS=$(echo "$PRS_JSON" | jq -r '.[0].labels[].name' | tr '[:upper:]' '[:lower:]')

BUMP="patch"

COUNT=0
for LABEL in major minor patch; do
if echo "$LABELS" | grep -qx "$LABEL"; then
BUMP="$LABEL"
COUNT=$((COUNT+1))
fi
done

if [ "$COUNT" -gt 1 ]; then
echo "Multiple SemVer labels applied. Use only one of: major, minor, patch."
exit 1
fi

echo "Version bump type: $BUMP"

case "$BUMP" in
major)
MAJOR=$((MAJOR+1))
MINOR=0
PATCH=0
;;
minor)
MINOR=$((MINOR+1))
PATCH=0
;;
patch)
PATCH=$((PATCH+1))
;;
esac

{
echo "title<<EOF"
echo "$TITLE"
echo "EOF"
} >> "$GITHUB_OUTPUT"
NEW_TAG="v${MAJOR}.${MINOR}.${PATCH}"

{
echo "body<<EOF"
echo "$BODY"
echo "EOF"
} >> "$GITHUB_OUTPUT"
echo "New tag: $NEW_TAG"

echo "PR details captured."
echo "- Title = $TITLE."
echo "- Description = $BODY."
echo "tag=$NEW_TAG" >> "$GITHUB_OUTPUT"
5 changes: 3 additions & 2 deletions .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,9 @@
{
"label": "LumenLab - Upload (release)",
"type": "shell",
"command": "export LUMENLAB_VERSION=v999.999.999 && platformio run -e release --target upload",
// Alternative command to align with prod releases: "export LUMENLAB_VERSION=$(git describe --tags --abbrev=0) && platformio run -e release --target upload",
// "command": "export LUMENLAB_VERSION=v9.99.999 && platformio run -e release --target upload",
// Alternative command to align with prod releases:
"command": "export LUMENLAB_VERSION=$(git describe --tags --abbrev=0) && platformio run -e release --target upload",
"problemMatcher": [
"$platformio"
],
Expand Down