diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index d2dbbe3..cb5d731 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -14,37 +14,7 @@ jobs: runs-on: "ubuntu-latest" steps: - - name: "Determine release tag" - run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" - - - name: "Determine release body" - uses: "actions/github-script@v5" - with: - github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const repository = context.repo; - - const response = await github.rest.repos.generateReleaseNotes({ - owner: repository.owner, - repo: repository.repo, - tag_name: "${{ env.RELEASE_TAG }}", - }); - - core.exportVariable("RELEASE_BODY", response.data.body); - - name: "Create release" - uses: "actions/github-script@v5" + uses: "ergebnis/.github/actions/github/release/create@main" with: github-token: "${{ secrets.ERGEBNIS_BOT_TOKEN }}" - script: | - const repository = context.repo; - - await github.rest.repos.createRelease({ - body: "${{ env.RELEASE_BODY }}", - draft: false, - name: "${{ env.RELEASE_TAG }}", - owner: repository.owner, - prerelease: false, - repo: repository.repo, - tag_name: "${{ env.RELEASE_TAG }}", - }); diff --git a/CHANGELOG.md b/CHANGELOG.md index 6f24ba8..2d18b47 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -14,6 +14,7 @@ For a full diff see [`1.2.1...main`][1.2.1...main]. - Added composite action `github/pull-request/approve` ([#60]), by [@localheinz] - Added composite action `github/pull-request/merge` ([#64]), by [@localheinz] - Added composite action `github/pull-request/add-label-based-on-branch-name` ([#67]), by [@localheinz] +- Added composite action `github/release/create` ([#72]), by [@localheinz] ## [`1.2.1`][1.2.1] @@ -66,5 +67,6 @@ For a full diff see [`1.0.0...main`][1.0.0...main]. [#60]: https://github.com/ergebnis/.github/pull/60 [#64]: https://github.com/ergebnis/.github/pull/64 [#67]: https://github.com/ergebnis/.github/pull/67 +[#72]: https://github.com/ergebnis/.github/pull/72 [@localheinz]: https://github.com/localheinz diff --git a/actions/github/release/create/action.yaml b/actions/github/release/create/action.yaml new file mode 100644 index 0000000..f3949ff --- /dev/null +++ b/actions/github/release/create/action.yaml @@ -0,0 +1,48 @@ +# https://docs.github.com/en/actions/creating-actions/creating-a-composite-action +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#inputs +# https://docs.github.com/en/actions/creating-actions/metadata-syntax-for-github-actions#runs-for-composite-run-steps-actions +# https://docs.github.com/en/rest/reference/releases#create-a-release +# https://docs.github.com/en/developers/webhooks-and-events/webhooks/webhook-events-and-payloads#push + +name: "Create a release" + +description: "Creates a release" + +inputs: + github-token: + description: "GitHub token of a user with permission to create a release" + required: true + +runs: + using: "composite" + + steps: + - name: "Determine tag" + if: "${{ github.event_name }} == 'push' && ${{ github.ref_type }} == 'tag'" + run: "echo \"RELEASE_TAG=${GITHUB_REF#refs/tags/}\" >> $GITHUB_ENV" + shell: "bash" + + - name: "Create release" + uses: "actions/github-script@v5" + with: + github-token: "${{ inputs.github-token }}" + script: | + if (!process.env.RELEASE_TAG) { + core.setFailed("The environment variable RELEASE_TAG is not defined.") + + return; + } + + try { + await github.rest.repos.createRelease({ + draft: false, + generate_release_notes: true, + name: process.env.RELEASE_TAG, + owner: context.repo.owner, + prerelease: false, + repo: context.repo.repo, + tag_name: process.env.RELEASE_TAG, + }); + } catch (error) { + core.setFailed(error.message); + }