Skip to content

Commit f4b17b3

Browse files
authored
Allow releases from different branches
1 parent 1ab550f commit f4b17b3

File tree

1 file changed

+44
-22
lines changed

1 file changed

+44
-22
lines changed

Diff for: .github/scripts/on-release.sh

+44-22
Original file line numberDiff line numberDiff line change
@@ -255,35 +255,43 @@ releasesJson=`curl -sH "Authorization: token $GITHUB_TOKEN" "https://api.github.
255255
if [ $? -ne 0 ]; then echo "ERROR: Get Releases Failed! ($?)"; exit 1; fi
256256

257257
set +e
258-
prev_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false and .prerelease == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name')
259-
prev_any_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false)) | sort_by(.created_at | - fromdateiso8601) | .[0].tag_name')
258+
prev_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false)) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
259+
prev_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false)) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
260+
prev_branch_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
261+
prev_branch_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[0].tag_name")
260262
shopt -s nocasematch
263+
if [ "$prev_release" == "$RELEASE_TAG" ]; then
264+
prev_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false)) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
265+
fi
261266
if [ "$prev_any_release" == "$RELEASE_TAG" ]; then
262-
prev_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false and .prerelease == false)) | sort_by(.created_at | - fromdateiso8601) | .[1].tag_name')
263-
prev_any_release=$(echo "$releasesJson" | jq -e -r '. | map(select(.draft == false)) | sort_by(.created_at | - fromdateiso8601) | .[1].tag_name')
267+
prev_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false)) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
268+
fi
269+
if [ "$prev_branch_release" == "$RELEASE_TAG" ]; then
270+
prev_branch_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .prerelease == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
271+
fi
272+
if [ "$prev_branch_any_release" == "$RELEASE_TAG" ]; then
273+
prev_branch_any_release=$(echo "$releasesJson" | jq -e -r ". | map(select(.draft == false and .target_commitish == \"$RELEASE_BRANCH\")) | sort_by(.published_at | - fromdateiso8601) | .[1].tag_name")
264274
fi
265-
COMMITS_SINCE_RELEASE="$prev_any_release"
266275
shopt -u nocasematch
267276
set -e
268277

278+
echo "Previous Release: $prev_release"
279+
echo "Previous (any)release: $prev_any_release"
280+
echo
281+
269282
# Merge package JSONs with previous releases
270283
if [ ! -z "$prev_any_release" ] && [ "$prev_any_release" != "null" ]; then
271284
echo "Merging with JSON from $prev_any_release ..."
272285
merge_package_json "$prev_any_release/$PACKAGE_JSON_DEV" "$OUTPUT_DIR/$PACKAGE_JSON_DEV"
273286
fi
274287

275288
if [ "$RELEASE_PRE" == "false" ]; then
276-
COMMITS_SINCE_RELEASE="$prev_release"
277289
if [ ! -z "$prev_release" ] && [ "$prev_release" != "null" ]; then
278290
echo "Merging with JSON from $prev_release ..."
279291
merge_package_json "$prev_release/$PACKAGE_JSON_REL" "$OUTPUT_DIR/$PACKAGE_JSON_REL"
280292
fi
281293
fi
282294

283-
echo "Previous Release: $prev_release"
284-
echo "Previous (any)release: $prev_any_release"
285-
echo
286-
287295
# Upload package JSONs
288296
echo "Uploading $PACKAGE_JSON_DEV ..."
289297
echo "Download URL: "`git_safe_upload_asset "$OUTPUT_DIR/$PACKAGE_JSON_DEV"`
@@ -328,21 +336,35 @@ if [ $arrLen > 3 ] && [ "${msgArray[0]:0:3}" == "tag" ]; then
328336
fi
329337

330338
# Append Commit Messages
339+
echo
340+
echo "Previous Branch Release: $prev_branch_release"
341+
echo "Previous Branch (any)release: $prev_branch_any_release"
342+
echo
343+
commitFile="$OUTPUT_DIR/commits.txt"
344+
COMMITS_SINCE_RELEASE="$prev_branch_any_release"
345+
if [ "$RELEASE_PRE" == "false" ]; then
346+
COMMITS_SINCE_RELEASE="$prev_branch_release"
347+
fi
331348
if [ ! -z "$COMMITS_SINCE_RELEASE" ] && [ "$COMMITS_SINCE_RELEASE" != "null" ]; then
332349
echo "Getting commits since $COMMITS_SINCE_RELEASE ..."
333-
commitFile=$OUTPUT_DIR/commits.txt
334-
git -C "$GITHUB_WORKSPACE" log --oneline "$COMMITS_SINCE_RELEASE..HEAD" > "$OUTPUT_DIR/commits.txt"
335-
releaseNotes+=$'\r\n##### Commits\r\n'
336-
IFS=$'\n'
337-
for next in `cat $commitFile`
338-
do
339-
IFS=' ' read -r commitId commitMsg <<< "$next"
340-
commitLine="- [$commitId](https://github.com/$GITHUB_REPOSITORY/commit/$commitId) $commitMsg"
341-
releaseNotes+="$commitLine"
342-
releaseNotes+=$'\r\n'
343-
done
344-
rm -f $commitFile
350+
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 "$COMMITS_SINCE_RELEASE..HEAD" > "$commitFile"
351+
elif [ "$RELEASE_BRANCH" != "master" ]; then
352+
echo "Getting all commits on branch '$RELEASE_BRANCH' ..."
353+
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 --cherry-pick --left-only --no-merges HEAD...origin/master > "$commitFile"
354+
else
355+
echo "Getting all commits on master ..."
356+
git -C "$GITHUB_WORKSPACE" log --oneline -n 500 --no-merges > "$commitFile"
345357
fi
358+
releaseNotes+=$'\r\n##### Commits\r\n'
359+
IFS=$'\n'
360+
for next in `cat $commitFile`
361+
do
362+
IFS=' ' read -r commitId commitMsg <<< "$next"
363+
commitLine="- [$commitId](https://github.com/$GITHUB_REPOSITORY/commit/$commitId) $commitMsg"
364+
releaseNotes+="$commitLine"
365+
releaseNotes+=$'\r\n'
366+
done
367+
rm -f $commitFile
346368

347369
# Prepend the original release body
348370
if [ "${RELEASE_BODY: -1}" == $'\r' ]; then

0 commit comments

Comments
 (0)