|
| 1 | +name: release |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - v* |
| 7 | + |
| 8 | +jobs: |
| 9 | + constraints: |
| 10 | + name: Setup build constraints |
| 11 | + runs-on: ubuntu-latest |
| 12 | + timeout-minutes: 1 |
| 13 | + outputs: |
| 14 | + sha: ${{ steps.sha.outputs.value }} |
| 15 | + version: ${{ steps.version.outputs.value }} |
| 16 | + timestamp: ${{ steps.timestamp.outputs.value }} |
| 17 | + |
| 18 | + steps: |
| 19 | + - name: Checkout branch |
| 20 | + uses: actions/checkout@v2 |
| 21 | + |
| 22 | + - name: Check git ref |
| 23 | + run: | |
| 24 | + [[ "${{ github.ref }}" == refs/tags/* ]] |
| 25 | +
|
| 26 | + - name: Set sha |
| 27 | + id: sha |
| 28 | + run: | |
| 29 | + echo "::set-output name=value::${{ github.sha }}" |
| 30 | +
|
| 31 | + - name: Set version |
| 32 | + id: version |
| 33 | + run: | |
| 34 | + echo "::set-output name=value::$(echo ${{ github.ref }} | sed -e 's|.*/||')" |
| 35 | +
|
| 36 | + - name: Set timestamp |
| 37 | + id: timestamp |
| 38 | + run: | |
| 39 | + echo "::set-output name=value::$(date -u '+%Y-%m-%dT%H:%M:%SZ')" |
| 40 | +
|
| 41 | + - name: Check version |
| 42 | + run: | |
| 43 | + [[ "${{ steps.version.outputs.value }}" =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]] |
| 44 | +
|
| 45 | + changelog: |
| 46 | + name: Parse changelog |
| 47 | + needs: constraints |
| 48 | + runs-on: ubuntu-latest |
| 49 | + timeout-minutes: 1 |
| 50 | + outputs: |
| 51 | + body: ${{ steps.changelog.outputs.body }} |
| 52 | + |
| 53 | + steps: |
| 54 | + - name: Checkout branch |
| 55 | + uses: actions/checkout@v2 |
| 56 | + |
| 57 | + - name: Parse changelog |
| 58 | + id: changelog |
| 59 | + # NOTE: actions/create-release does not support multiline body, and it does |
| 60 | + # not support reading from files either, so as suggested in the GitHub issue, |
| 61 | + # the workaround is to encode the line endings and carriage returns. |
| 62 | + # https://github.com/actions/create-release/issues/25 |
| 63 | + run: | |
| 64 | + BODY=$(sed -n "/<!-- START ${{ needs.constraints.outputs.version }} -->/,/<!-- END ${{ needs.constraints.outputs.version }} -->/{//!p;}" CHANGELOG.md) |
| 65 | + BODY="${BODY//$'%'/'%25'}" |
| 66 | + BODY="${BODY//$'\n'/'%0A'}" |
| 67 | + BODY="${BODY//$'\r'/'%0D'}" |
| 68 | + echo "::set-output name=body::${BODY}" |
| 69 | +
|
| 70 | + release: |
| 71 | + name: Create release |
| 72 | + needs: [constraints, changelog] |
| 73 | + runs-on: ubuntu-latest |
| 74 | + timeout-minutes: 1 |
| 75 | + |
| 76 | + steps: |
| 77 | + - name: Checkout branch |
| 78 | + uses: actions/checkout@v2 |
| 79 | + |
| 80 | + - name: Create release |
| 81 | + uses: actions/create-release@v1 |
| 82 | + env: |
| 83 | + GITHUB_TOKEN: ${{ github.token }} |
| 84 | + with: |
| 85 | + tag_name: ${{ needs.constraints.outputs.version }} |
| 86 | + release_name: ${{ needs.constraints.outputs.version }} |
| 87 | + body: ${{ needs.changelog.outputs.body }} |
| 88 | + draft: false |
| 89 | + prerelease: false |
0 commit comments