From 48b093848b2989b83cb5a4e6cb7487a8f4c022fe Mon Sep 17 00:00:00 2001 From: Ernesto Ojeda Date: Tue, 25 Jul 2023 17:43:09 -0700 Subject: [PATCH] feat: reusable workflow for GitHub Releases Signed-off-by: Ernesto Ojeda --- .github/workflows/release.yml | 56 +++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..9a7f47ce --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,56 @@ +name: Create Release +on: + workflow_call: + +jobs: + release: + runs-on: ubuntu-latest + env: + TAG_NAME: ${{ github.ref_name }} + steps: + - uses: actions/checkout@v3 + - name: Generate Body File + id: notes + run: | + if [ -f "CHANGELOG.md" ]; then + rm -rf release-body.md + release= + next= + while read -r version; do + if [[ "$version" =~ "$TAG_NAME" ]]; then + release="$version" + else + if [[ "$next" == "" ]]; then + next="$version" + fi + fi + done < <(grep -n "## \[v" CHANGELOG.md) + l1=$(echo "$release" | cut -d: -f1) + l2=$(echo "$next" | cut -d: -f1) + tail -n +$l1 CHANGELOG.md | head -n $((l2-l1)) > release-body.md + + if grep -q "tail: invalid" release-body.md; then + rm release-body.md + echo "status=error" >> $GITHUB_OUTPUT + elif [ $(wc -l release-body.md | awk '{print $1}') -eq 0 ]; then + rm release-body.md + echo "status=error" >> $GITHUB_OUTPUT + else + echo "status=created" >> $GITHUB_OUTPUT + fi + else + echo "status=error" >> $GITHUB_OUTPUT + fi + - name: Create Release with CHANGELOG + uses: ncipollo/release-action@v1.12.0 + if: ${{ steps.notes.outputs.status == 'created' }} + with: + skipIfReleaseExists: false + generateReleaseNotes: false + bodyFile: "release-body.md" + - name: Create Release with Autogenerated Notes + uses: ncipollo/release-action@v1.12.0 + if: ${{ steps.notes.outputs.status == 'error' }} + with: + skipIfReleaseExists: false + generateReleaseNotes: true \ No newline at end of file