diff --git a/.github/draft_release_notes.sh b/.github/draft_release_notes.sh new file mode 100755 index 0000000000..bb8c6d91ba --- /dev/null +++ b/.github/draft_release_notes.sh @@ -0,0 +1,54 @@ +#! /bin/sh + +# this script assumes the GITHUB_TOKEN and PREVIOUS_TAG environment variables have been set; +# it produces a 'Changes.md' file as its final output; +# the file 'last-300-prs-with-release-note.txt' that is produces is intermediate data; it is not +# pruned for now to assist development of the release notes process (we are still curating all this) + +sudo apt-get -y install jq +sudo apt-get -y install wget +curl -L https://github.com/github/hub/releases/download/v2.14.2/hub-linux-amd64-2.14.2.tgz | tar xzf - +PWD=`pwd` +export PATH=$PWD/hub-linux-amd64-2.14.2/bin:$PATH +git fetch --all --tags --prune --force +echo -e "# Insert Title\n" > Changes.md +echo -e "## Features\n\n## Fixes\n\n## Backwards incompatible changes\n\n## Docs\n\n## Misc\n\n## Thanks" >> Changes.md - name: Draft Release +# this effectively gets the commit associated with github.event.inputs.tags +COMMON_ANCESTOR=$(git merge-base $PREVIOUS_TAG HEAD) +# in theory the new tag has not been created yet; do we want another input that specifies the existing +# commit desired for drafting the release? for now, we are using HEAD in the above git merge-base call +# and PR cross referencing below + +# use of 'hub', which is an extension of the 'git' CLI, allows for pulling of PRs, though we can't search based on commits +# associated with those PRs, so we grab a super big number, 300, which should guarantee grabbing all the PRs back to +# github.events.inputs.tags; we use grep -v to filter out release-note-none and release-note-action-required +hub pr list --state merged -L 300 -f "%sm;%au;%i;%t;%L%n" | egrep ", release-note|release-note," | grep -v release-note-none | grep -v release-note-action-required > last-300-prs-with-release-note.txt +# now we cylce through last-300-prs-with-release-note.txt, filtering out stuff that is too old or other anomalies, +# and update Changes.md with the release note. +while IFS= read -r pr; do + SHA=$(echo $pr | cut -d';' -f1) + # skip the common ancestor, which in essences is the commit associated with the tag github.event.inputs.tags + if [ "$SHA" == "$COMMON_ANCESTOR" ]; then + continue + fi + + # styllistic clarification, purposefully avoiding slicker / cleverer / more compact scripting conventions + + # this makes sure that this PR has merged + git merge-base --is-ancestor $SHA HEAD + rc=$? + if [ ${rc} -eq 1 ]; then + continue + fi + # otherwise, if the current commit from the last 300 PRs is not an ancestor of github.event.inputs.tags, we have gone too far, so skip + git merge-base --is-ancestor $COMMON_ANCESTOR $SHA + rc=$? + if [ ${rc} -eq 1 ]; then + continue + fi + # if we are at this point, we have a PR with a release note to add + AUTHOR=$(echo $pr | cut -d';' -f2) + PR_NUM=$(echo $pr | cut -d';' -f3) + PR_RELEASE_NOTE=$(wget -q -O- https://api.github.com/repos/shipwright-io/build/issues/${PR_NUM:1} | jq .body -r | grep -oPz '(?s)(?<=```release-note..)(.+?)(?=```)' | grep -avP '\W*(Your release note here|action required: your release note here|NONE)\W*') + echo -e "$PR_NUM by $AUTHOR: $PR_RELEASE_NOTE" >> Changes.md +done < last-300-prs-with-release-note.txt diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index ebd3da76b7..d682a3e548 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -19,11 +19,15 @@ jobs: with: fetch-depth: 0 - name: Build Release Changelog + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + PREVIOUS_TAG: ${{ github.event.inputs.tags }} run: | - git fetch --all --tags --prune --force - echo -e "# Insert Title\n" > Changes.md - git log --pretty=format:"%h - %s - %an" ${{ github.event.inputs.tags }}..HEAD | grep -v "Merge pull" >> Changes.md - echo -e "## Features\n\n## Fixes\n\n## Backwards incompatible changes\n\n## Docs\n\n## Misc\n\n## Thanks" >> Changes.md - name: Draft Release + # might not be necessary but make sure + chmod +x "${GITHUB_WORKSPACE}/.github/draft_release_notes.sh" + export GITHUB_TOKEN + export PREVIOUS_TAG + "${GITHUB_WORKSPACE}/.github/draft_release_notes.sh" - name: Draft release id: draft_release uses: actions/create-release@v1