From c2d89ce30b4356d42a32d6670d0088bc41395e92 Mon Sep 17 00:00:00 2001 From: ZhengYuan Loo Date: Wed, 17 Feb 2021 12:55:27 +0800 Subject: [PATCH] ci: add release workflow (#8) --- .github/workflows/release.yml | 89 +++++++++++++++++++++++++++++++++++ 1 file changed, 89 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 0000000..50052ac --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,89 @@ +name: release + +on: + push: + tags: + - v* + +jobs: + constraints: + name: Setup build constraints + runs-on: ubuntu-latest + timeout-minutes: 1 + outputs: + sha: ${{ steps.sha.outputs.value }} + version: ${{ steps.version.outputs.value }} + timestamp: ${{ steps.timestamp.outputs.value }} + + steps: + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Check git ref + run: | + [[ "${{ github.ref }}" == refs/tags/* ]] + + - name: Set sha + id: sha + run: | + echo "::set-output name=value::${{ github.sha }}" + + - name: Set version + id: version + run: | + echo "::set-output name=value::$(echo ${{ github.ref }} | sed -e 's|.*/||')" + + - name: Set timestamp + id: timestamp + run: | + echo "::set-output name=value::$(date -u '+%Y-%m-%dT%H:%M:%SZ')" + + - name: Check version + run: | + [[ "${{ steps.version.outputs.value }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] + + changelog: + name: Parse changelog + needs: constraints + runs-on: ubuntu-latest + timeout-minutes: 1 + outputs: + body: ${{ steps.changelog.outputs.body }} + + steps: + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Parse changelog + id: changelog + # NOTE: actions/create-release does not support multiline body, and it does + # not support reading from files either, so as suggested in the GitHub issue, + # the workaround is to encode the line endings and carriage returns. + # https://github.com/actions/create-release/issues/25 + run: | + BODY=$(sed -n "//,//{//!p;}" CHANGELOG.md) + BODY="${BODY//$'%'/'%25'}" + BODY="${BODY//$'\n'/'%0A'}" + BODY="${BODY//$'\r'/'%0D'}" + echo "::set-output name=body::${BODY}" + + release: + name: Create release + needs: [constraints, changelog] + runs-on: ubuntu-latest + timeout-minutes: 1 + + steps: + - name: Checkout branch + uses: actions/checkout@v2 + + - name: Create release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ github.token }} + with: + tag_name: ${{ needs.constraints.outputs.version }} + release_name: ${{ needs.constraints.outputs.version }} + body: ${{ needs.changelog.outputs.body }} + draft: false + prerelease: false