|
| 1 | +name: Semantic Release |
| 2 | +description: Release |
| 3 | + |
| 4 | +inputs: |
| 5 | + artifactName: |
| 6 | + description: Name of the uploaded build artifact |
| 7 | + default: build-artifact |
| 8 | + required: false |
| 9 | + artifactPath: |
| 10 | + description: Destination path for the downloaded build artifact |
| 11 | + default: dist |
| 12 | + required: false |
| 13 | + publishToNpm: |
| 14 | + description: Enable this to publish artifacts to NPM |
| 15 | + required: false |
| 16 | + withoutBuiltArtifact: |
| 17 | + description: Indicates that no artifact should be downloaded |
| 18 | + required: false |
| 19 | + withoutChangelog: |
| 20 | + description: Enable this to prevent @semantic-release/changelog from writing a CHANGELOG file |
| 21 | + required: false |
| 22 | + withoutNpmPlugin: |
| 23 | + description: Enable this to prevent @semantic-release/npm from writing package.json |
| 24 | + required: false |
| 25 | + extraPlugins: |
| 26 | + description: Additional array of plugins to be added to the .releaserc file in JSON format |
| 27 | + required: false |
| 28 | + GITHUB_TOKEN: |
| 29 | + description: Github token with write permission |
| 30 | + required: true |
| 31 | + NPM_TOKEN: |
| 32 | + description: Secret NPM token |
| 33 | + required: false |
| 34 | + |
| 35 | +outputs: |
| 36 | + isReleased: |
| 37 | + description: Whether a new release was published. Contains "true" or "false" string |
| 38 | + value: ${{ steps.semantic-release.outputs.new_release_published }} |
| 39 | + releasedVersion: |
| 40 | + description: The version of the release that actually happened |
| 41 | + value: ${{ steps.semantic-release.outputs.new_release_version }} |
| 42 | + previousVersion: |
| 43 | + description: Version of the previous release, if there was one |
| 44 | + value: ${{ steps.semantic-release.outputs.last_release_version }} |
| 45 | + releasedSHA: |
| 46 | + description: The SHA of the commit that was released, that contains the [skip-ci] commit |
| 47 | + value: ${{ steps.released-sha.outputs.SHA }} |
| 48 | + |
| 49 | +runs: |
| 50 | + using: composite |
| 51 | + steps: |
| 52 | + - uses: actions/checkout@v4 |
| 53 | + with: |
| 54 | + token: ${{ inputs.GITHUB_TOKEN }} |
| 55 | + |
| 56 | + # install node_modules since there might be a dependency from husky which is invoked during npm publish |
| 57 | + - if: inputs.publishToNpm == 'true' |
| 58 | + uses: cloudbeds/workflows/.github/actions/npm-install@main |
| 59 | + |
| 60 | + - if: inputs.withoutBuiltArtifact != 'true' |
| 61 | + name: Download artifact |
| 62 | + uses: actions/download-artifact@v4 |
| 63 | + with: |
| 64 | + name: ${{ inputs.artifactName }} |
| 65 | + path: ${{ inputs.artifactPath }} |
| 66 | + |
| 67 | + - shell: bash |
| 68 | + run: | |
| 69 | + echo "" |
| 70 | + echo "::group::📂 Contents of the Root directory" |
| 71 | + ls -la |
| 72 | + echo "::endgroup::" |
| 73 | + echo "" |
| 74 | +
|
| 75 | + - if: inputs.withoutBuiltArtifact != 'true' |
| 76 | + shell: bash |
| 77 | + run: | |
| 78 | + echo "" |
| 79 | + echo "::group::📂 Contents of the '${{ inputs.artifactPath }}' directory" |
| 80 | + ls -la ${{ inputs.artifactPath }} |
| 81 | + echo "::endgroup::" |
| 82 | + echo "" |
| 83 | +
|
| 84 | + - name: Create config file for Semantic Release |
| 85 | + uses: actions/github-script@v7 |
| 86 | + with: |
| 87 | + script: | |
| 88 | + const fs = require('fs'); |
| 89 | + const inputs = ${{ toJSON(inputs) }}; |
| 90 | +
|
| 91 | + const plugins = [ |
| 92 | + ['@semantic-release/commit-analyzer', { |
| 93 | + releaseRules: [ |
| 94 | + { type: 'perf', release: 'patch' }, |
| 95 | + { type: 'refactor', release: 'patch' }, |
| 96 | + { type: 'revert', release: 'patch' } |
| 97 | + ] |
| 98 | + }], |
| 99 | + '@semantic-release/release-notes-generator', |
| 100 | + ]; |
| 101 | +
|
| 102 | + if (inputs.withoutChangelog !== 'true') { |
| 103 | + plugins.push('@semantic-release/changelog'); |
| 104 | + } |
| 105 | +
|
| 106 | + if (inputs.withoutNpmPlugin !== 'true') { |
| 107 | + plugins.push([ |
| 108 | + '@semantic-release/npm', |
| 109 | + { npmPublish: inputs.publishToNpm === 'true' }, |
| 110 | + ]); |
| 111 | + } |
| 112 | +
|
| 113 | + plugins.push('@semantic-release/github'); |
| 114 | + plugins.push('@semantic-release/git'); |
| 115 | +
|
| 116 | + const extraPlugins = JSON.parse(inputs.extraPlugins || '[]'); |
| 117 | +
|
| 118 | + if (extraPlugins.length) { |
| 119 | + extraPlugins.forEach(plugin => plugins.push(plugin)); |
| 120 | + } |
| 121 | +
|
| 122 | + fs.writeFileSync('.releaserc', JSON.stringify({ plugins }, null, 2)); |
| 123 | +
|
| 124 | + const extraPluginNames = extraPlugins.map(plugin => Array.isArray(plugin) ? plugin[0] : plugin).join(' '); |
| 125 | + core.exportVariable('EXTRA_PLUGINS', extraPluginNames); |
| 126 | +
|
| 127 | + console.log('::group::📂 Contents of .releaserc:'); |
| 128 | + console.log(fs.readFileSync('.releaserc')); |
| 129 | + console.log('::endgroup::'); |
| 130 | +
|
| 131 | + - name: Semantic Release |
| 132 | + uses: cycjimmy/semantic-release-action@v4 |
| 133 | + id: semantic-release |
| 134 | + with: |
| 135 | + branches: | |
| 136 | + [ |
| 137 | + 'main', |
| 138 | + '+([0-9])?(.{+([0-9]),x}).x' |
| 139 | + ] |
| 140 | + extra_plugins: | |
| 141 | + @semantic-release/changelog |
| 142 | + @semantic-release/git |
| 143 | + ${{ env.EXTRA_PLUGINS }} |
| 144 | + env: |
| 145 | + GITHUB_TOKEN: ${{ inputs.GITHUB_TOKEN }} |
| 146 | + NPM_TOKEN: ${{ inputs.NPM_TOKEN }} |
| 147 | + HUSKY: '0' |
| 148 | + |
| 149 | + - name: Output commit hash |
| 150 | + id: released-sha |
| 151 | + shell: bash |
| 152 | + run: | |
| 153 | + echo "" |
| 154 | + if [[ "${{ steps.semantic-release.outputs.new_release_published }}" == true ]]; then |
| 155 | + echo "::notice::🎉 Application version was updated to ${{ steps.semantic-release.outputs.new_release_version }}" |
| 156 | + else |
| 157 | + echo "::warning::No new version is released" |
| 158 | + echo "::warning::Make sure that commit messages follow the semantic-release format" |
| 159 | + fi |
| 160 | + echo "SHA=$(git rev-parse HEAD)" >> $GITHUB_OUTPUT |
0 commit comments