├── .gitignore ├── package.json ├── action.yml ├── index.js ├── LICENSE ├── main.js └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | node_modules 2 | .idea 3 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "action-semantic-release-info", 3 | "dependencies": { 4 | "@actions/core": "^1.10.0", 5 | "semantic-release": "^17.1.1" 6 | }, 7 | "license": "MIT" 8 | } 9 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Get Semantic Release Info' 2 | description: 'Action to get next semantic release info, does not publish. export the info as output variables' 3 | author: 'Jossef Harush' 4 | outputs: 5 | type: 6 | description: 'The part of the version incremented - major/minor/patch' 7 | channel: 8 | description: 'The distribution channel on which the last release was initially made available' 9 | git_head: 10 | description: 'The sha of the last commit being part of the release' 11 | version: 12 | description: 'The version of the release' 13 | git_tag: 14 | description: 'The Git tag associated with the release' 15 | name: 16 | description: 'The name of the release' 17 | notes: 18 | description: 'The release notes of the release (a summary of git commits)' 19 | branding: 20 | icon: 'package' 21 | color: 'green' 22 | runs: 23 | using: 'node16' 24 | main: 'index.js' 25 | -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | const exec = require('child_process').exec; 2 | const path = require('path'); 3 | 4 | function executeCommand(cmd, workingDirectory = null) { 5 | return new Promise((resolve, reject) => { 6 | let options = {}; 7 | if (workingDirectory) { 8 | options.cwd = path.resolve(workingDirectory); 9 | } 10 | let p = exec(cmd, options, (error, stdout, stderr) => { 11 | if (error) { 12 | reject(error); 13 | } 14 | resolve(stdout ? stdout : stderr); 15 | }); 16 | 17 | p.stdout.pipe(process.stdout); 18 | p.stderr.pipe(process.stderr); 19 | }); 20 | } 21 | 22 | async function main() { 23 | await executeCommand('npm ci --only=prod', __dirname); 24 | await require('./main').main(); 25 | } 26 | 27 | if (require.main === module) { 28 | main() 29 | .then(() => process.exit(0)) 30 | .catch(e => { 31 | console.error(e); 32 | process.exit(1); 33 | }); 34 | } 35 | 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2020 GitHub, Inc. and contributors 5 | 6 | Permission is hereby granted, free of charge, to any person obtaining a copy 7 | of this software and associated documentation files (the "Software"), to deal 8 | in the Software without restriction, including without limitation the rights 9 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 10 | copies of the Software, and to permit persons to whom the Software is 11 | furnished to do so, subject to the following conditions: 12 | 13 | The above copyright notice and this permission notice shall be included in 14 | all copies or substantial portions of the Software. 15 | 16 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 19 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 21 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 22 | THE SOFTWARE. -------------------------------------------------------------------------------- /main.js: -------------------------------------------------------------------------------- 1 | const semanticRelease = require('semantic-release'); 2 | const core = require("@actions/core"); 3 | 4 | async function main() { 5 | try { 6 | const result = await semanticRelease({ 7 | dryRun: true, "plugins": [ 8 | ["@semantic-release/commit-analyzer", { 9 | "preset": "angular", 10 | }], 11 | '@semantic-release/release-notes-generator', 12 | ] 13 | }); 14 | if (result) { 15 | const {nextRelease} = result; 16 | core.setOutput("type", nextRelease.type); 17 | core.setOutput("channel", nextRelease.channel); 18 | core.setOutput("git_head", nextRelease.gitHead); 19 | core.setOutput("version", nextRelease.version); 20 | core.setOutput("git_tag", nextRelease.gitTag); 21 | core.setOutput("name", nextRelease.name); 22 | core.setOutput("notes", nextRelease.notes); 23 | } else { 24 | core.setFailed('no info regarding next release'); 25 | } 26 | } catch (err) { 27 | core.setFailed(err) 28 | throw err; 29 | } 30 | } 31 | 32 | if (require.main === module) { 33 | main() 34 | .then(() => process.exit(0)) 35 | .catch(e => { 36 | console.error(e); 37 | process.exit(1); 38 | }); 39 | } 40 | 41 | module.exports.main = main; 42 | 43 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action - Get Next Semantic Release Info 2 | This GitHub Action gets next semantic release info, does not publish. export the info as output variables. 3 | 4 | ## Usage 5 | 6 | Add this step in your workflow file 7 | ```yaml 8 | - name: Gets semantic release info 9 | id: semantic_release_info 10 | uses: jossef/action-semantic-release-info@v2.1.0 11 | env: 12 | GITHUB_TOKEN: ${{ github.token }} 13 | ``` 14 | 15 | ### Output Variables 16 | 17 | - `type` - The part of the version incremented - major/minor/patch 18 | - `channel` - The distribution channel on which the last release was initially made available 19 | - `git_head` - The sha of the last commit being part of the release 20 | - `version` - The version of the release 21 | - `git_tag` - The Git tag associated with the release 22 | - `name` - The name of the release 23 | - `notes` - The release notes of the release (a summary of git commits) 24 | 25 | output variables can be accessed after the step is completed via 26 | ``` 27 | ${{ steps.semantic_release_info.outputs. }} 28 | ``` 29 | 30 | ### Full Example 31 | In this example I build auto generated docs, commit the built docs artifacts and make a tagged release 32 | 33 | ```yaml 34 | 35 | name: CI 36 | 37 | on: 38 | push: 39 | branches: 40 | - '**' 41 | tags-ignore: 42 | - '*.*' 43 | 44 | jobs: 45 | build: 46 | runs-on: ubuntu-latest 47 | steps: 48 | - uses: actions/checkout@v2 49 | 50 | - name: Gets semantic release info 51 | id: semantic_release_info 52 | uses: jossef/action-semantic-release-info@v2.1.0 53 | env: 54 | GITHUB_TOKEN: ${{ github.token }} 55 | 56 | - name: Build auto generated docs 57 | run: | 58 | npm install 59 | npm run build-docs 60 | 61 | - name: Commit files 62 | run: | 63 | git config --local user.email "action@github.com" 64 | git config --local user.name "GitHub Action" 65 | git add -A 66 | git commit -m "docs(): bumping release ${{ steps.semantic_release_info.outputs.git_tag }}" 67 | git tag ${{ steps.semantic_release_info.outputs.git_tag }} 68 | 69 | - name: Push changes 70 | uses: ad-m/github-push-action@v0.6.0 71 | with: 72 | github_token: ${{ github.token }} 73 | tags: true 74 | 75 | - name: Create GitHub Release 76 | uses: actions/create-release@v1 77 | env: 78 | GITHUB_TOKEN: ${{ github.token }} 79 | with: 80 | tag_name: ${{ steps.semantic_release_info.outputs.git_tag }} 81 | release_name: ${{ steps.semantic_release_info.outputs.git_tag }} 82 | body: ${{ steps.semantic_release_info.outputs.notes }} 83 | draft: false 84 | prerelease: false 85 | ``` 86 | 87 | --------------------------------------------------------------------------------