diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 6388398..3217bd0 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -30,6 +30,7 @@ jobs: new-release-published: ${{ steps.get-next-version.outputs.new-release-published }} new-release-version: ${{ steps.get-next-version.outputs.new-release-version }} new-release-git-tag: ${{ steps.get-next-version.outputs.new-release-git-tag }} + new-release-notes: ${{ steps.get-next-version.outputs.new-release-notes }} release: runs-on: ubuntu-latest @@ -39,6 +40,11 @@ jobs: steps: - run: echo "The new release version is ${{ needs.get-next-version.outputs.new-release-version }} with tag ${{ needs.get-next-version.outputs.new-release-git-tag }}" + - run: | + cat << 'EOF' + The release notes are: + ${{ needs.get-next-version.outputs.new-release-notes }} + EOF - uses: actions/checkout@v3 with: fetch-depth: 0 diff --git a/README.md b/README.md index 2dffaa0..dfe8b09 100644 --- a/README.md +++ b/README.md @@ -43,6 +43,7 @@ Currently, the plugin exports the following GitHub Actions's outputs: | `new-release-published` | Whether a new release was published. The return value is in the form of a string. (`true` or `false`) | | `new-release-version` | If a new release was published, the version of the new release. (e.g. `1.3.0`) | | `new-release-git-tag` | If a new version was published, the git tag of the new release. (e.g. `v1.3.0`) | +| `new-release-notes` | If a new version was published, the generated notes (if present) | ### GitHub Actions Example diff --git a/index.js b/index.js index 4b3db4e..562f710 100644 --- a/index.js +++ b/index.js @@ -2,11 +2,22 @@ const { env } = require("node:process"); const { appendFileSync } = require("node:fs"); +const { EOL } = require("node:os"); +const { randomUUID } = require("node:crypto"); -function exportData(name, value) { - console.log(`semantic-release-export-data: ${name}=${value}`); +function exportData(name, value, { log = true, escape = false } = {}) { + if (log) { + console.log(`semantic-release-export-data: ${name}=${value}`); + } if (env.GITHUB_OUTPUT) { - const output = `${name}=${value}\n`; + let output; + if (escape) { + // Borrowed from https://github.com/actions/toolkit/blob/ddc5fa4ae84a892bfa8431c353db3cf628f1235d/packages/core/src/file-command.ts#L27 + const delimiter = "output_delimiter_".concat(randomUUID()); + output = `${name}<<${delimiter}${EOL}${value}${EOL}${delimiter}${EOL}`; + } else { + output = `${name}=${value}${EOL}`; + } appendFileSync(env.GITHUB_OUTPUT, output); } } @@ -19,6 +30,7 @@ function generateNotes(_pluginConfig, { nextRelease }) { exportData("new-release-published", "true"); exportData("new-release-version", nextRelease.version); exportData("new-release-git-tag", nextRelease.gitTag); + exportData("new-release-notes", nextRelease.notes, { log: false, escape: true }); } module.exports = {