├── .eslintrc ├── .github └── workflows │ ├── ci.yml │ └── versioning.yml ├── .gitignore ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── action.yml ├── dist └── index.js ├── package-lock.json ├── package.json ├── src ├── create-release.js └── main.js └── tests └── create-release.test.js /.eslintrc: -------------------------------------------------------------------------------- 1 | { 2 | "extends": [ 3 | "airbnb", 4 | "prettier" 5 | ], 6 | "env": { 7 | "es6": true, 8 | "node": true, 9 | "jest": true 10 | }, 11 | "rules": { 12 | "prettier/prettier": [ 13 | "error", 14 | { 15 | "trailingComma": "none", 16 | "singleQuote": true, 17 | "printWidth": 120 18 | } 19 | ] 20 | }, 21 | "plugins": [ 22 | "prettier" 23 | ] 24 | } 25 | -------------------------------------------------------------------------------- /.github/workflows/ci.yml: -------------------------------------------------------------------------------- 1 | name: "Tests" 2 | 3 | on: 4 | pull_request: 5 | push: 6 | branches: # array of glob patterns matching against refs/heads. Optional; defaults to all 7 | - master # triggers on pushes that contain changes in master 8 | 9 | jobs: 10 | test: 11 | runs-on: ubuntu-latest 12 | steps: 13 | - uses: actions/checkout@v1 14 | - run: npm ci 15 | - run: npm test 16 | -------------------------------------------------------------------------------- /.github/workflows/versioning.yml: -------------------------------------------------------------------------------- 1 | name: Keep the versions up-to-date 2 | 3 | on: 4 | release: 5 | types: [published] 6 | 7 | jobs: 8 | actions-tagger: 9 | runs-on: windows-latest 10 | steps: 11 | - uses: Actions-R-Us/actions-tagger@latest 12 | with: 13 | publish_latest: true 14 | env: 15 | GITHUB_TOKEN: '${{secrets.GITHUB_TOKEN}}' 16 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Logs 2 | logs 3 | *.log 4 | npm-debug.log* 5 | yarn-debug.log* 6 | yarn-error.log* 7 | lerna-debug.log* 8 | 9 | # Diagnostic reports (https://nodejs.org/api/report.html) 10 | report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json 11 | 12 | # Runtime data 13 | pids 14 | *.pid 15 | *.seed 16 | *.pid.lock 17 | 18 | # Directory for instrumented libs generated by jscoverage/JSCover 19 | lib-cov 20 | 21 | # Coverage directory used by tools like istanbul 22 | coverage 23 | *.lcov 24 | 25 | # nyc test coverage 26 | .nyc_output 27 | 28 | # Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) 29 | .grunt 30 | 31 | # Bower dependency directory (https://bower.io/) 32 | bower_components 33 | 34 | # node-waf configuration 35 | .lock-wscript 36 | 37 | # Compiled binary addons (https://nodejs.org/api/addons.html) 38 | build/Release 39 | 40 | # Dependency directories 41 | node_modules/ 42 | jspm_packages/ 43 | 44 | # TypeScript v1 declaration files 45 | typings/ 46 | 47 | # TypeScript cache 48 | *.tsbuildinfo 49 | 50 | # Optional npm cache directory 51 | .npm 52 | 53 | # Optional eslint cache 54 | .eslintcache 55 | 56 | # Optional REPL history 57 | .node_repl_history 58 | 59 | # Output of 'npm pack' 60 | *.tgz 61 | 62 | # Yarn Integrity file 63 | .yarn-integrity 64 | 65 | # dotenv environment variables file 66 | .env 67 | .env.test 68 | 69 | # parcel-bundler cache (https://parceljs.org/) 70 | .cache 71 | 72 | # next.js build output 73 | .next 74 | 75 | # nuxt.js build output 76 | .nuxt 77 | 78 | # vuepress build output 79 | .vuepress/dist 80 | 81 | # Serverless directories 82 | .serverless/ 83 | 84 | # FuseBox cache 85 | .fusebox/ 86 | 87 | # DynamoDB Local files 88 | .dynamodb/ 89 | 90 | # Misc 91 | .idea/ 92 | .DS_Store 93 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | # Contributor Covenant Code of Conduct 2 | 3 | ## Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, sex characteristics, gender identity and expression, 9 | level of experience, education, socio-economic status, nationality, personal 10 | appearance, race, religion, or sexual identity and orientation. 11 | 12 | ## Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ## Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ## Scope 47 | 48 | This Code of Conduct applies within all project spaces, and it also applies when 49 | an individual is representing the project or its community in public spaces. 50 | Examples of representing a project or community include using an official 51 | project e-mail address, posting via an official social media account, or acting 52 | as an appointed representative at an online or offline event. Representation of 53 | a project may be further defined and clarified by project maintainers. 54 | 55 | ## Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise unacceptable behavior may be 58 | reported by contacting the project team at opensource+actions/create-release@github.com. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. 67 | 68 | ## Attribution 69 | 70 | This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, 71 | available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html 72 | 73 | [homepage]: https://www.contributor-covenant.org 74 | 75 | For answers to common questions about this code of conduct, see 76 | https://www.contributor-covenant.org/faq 77 | -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | ## Contributing 2 | 3 | [fork]: https://github.com/actions/create-release/fork 4 | [pr]: https://github.com/actions/create-release/compare 5 | [style]: https://github.com/styleguide/js 6 | [code-of-conduct]: CODE_OF_CONDUCT.md 7 | 8 | Hi there! We're thrilled that you'd like to contribute to this project. Your help is essential for keeping it great. 9 | 10 | Contributions to this project are [released](https://help.github.com/articles/github-terms-of-service/#6-contributions-under-repository-license) to the public under the [project's open source license](LICENSE). 11 | 12 | Please note that this project is released with a [Contributor Code of Conduct][code-of-conduct]. By participating in this project you agree to abide by its terms. 13 | 14 | ## Submitting a pull request 15 | 16 | 1. [Fork][fork] and clone the repository 17 | 2. Configure and install the dependencies: `npm install` 18 | 3. Make sure the tests pass on your machine: `npm run test` 19 | 4. Create a new branch: `git checkout -b my-branch-name` 20 | 5. Make your change, add tests, and make sure the tests still pass 21 | 6. Push to your fork and [submit a pull request][pr] 22 | 7. Pat your self on the back and wait for your pull request to be reviewed and merged. 23 | 24 | Here are a few things you can do that will increase the likelihood of your pull request being accepted: 25 | 26 | - Follow the [style guide][style]. 27 | - Write tests. 28 | - Keep your change as focused as possible. If there are multiple changes you would like to make that are not dependent upon each other, consider submitting them as separate pull requests. 29 | - Write a [good commit message](http://tbaggery.com/2008/04/19/a-note-about-git-commit-messages.html). 30 | 31 | ## Resources 32 | 33 | - [How to Contribute to Open Source](https://opensource.guide/how-to-contribute/) 34 | - [Using Pull Requests](https://help.github.com/articles/about-pull-requests/) 35 | - [GitHub Help](https://help.github.com) 36 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | The MIT License (MIT) 3 | 4 | Copyright (c) 2018 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. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # GitHub Action - Releases API 2 | This GitHub Action (written in JavaScript) wraps the [GitHub Release API](https://developer.github.com/v3/repos/releases/), specifically the [Create a Release](https://developer.github.com/v3/repos/releases/#create-a-release) endpoint, to allow you to leverage GitHub Actions to create releases. 3 | 4 | GitHub Actions status 5 | 6 | ## Usage 7 | ### Pre-requisites 8 | Create a workflow `.yml` file in your `.github/workflows` directory. An [example workflow](#example-workflow---create-a-release) is available below. For more information, reference the GitHub Help Documentation for [Creating a workflow file](https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file). 9 | 10 | ### Inputs 11 | For more information on these inputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#input) 12 | 13 | - `tag_name`: The name of the tag for this release 14 | - `release_name`: The name of the release 15 | - `body`: Text describing the contents of the release 16 | - `draft`: `true` to create a draft (unpublished) release, `false` to create a published one. Default: `false` 17 | - `prerelease`: `true` to identify the release as a prerelease. `false` to identify the release as a full release. Default `false` 18 | 19 | ### Outputs 20 | For more information on these outputs, see the [API Documentation](https://developer.github.com/v3/repos/releases/#response-4) for an example of what these outputs look like 21 | 22 | - `id`: The release ID 23 | - `html_url`: The URL users can navigate to in order to view the release. i.e. `https://github.com/octocat/Hello-World/releases/v1.0.0` 24 | - `upload_url`: The URL for uploading assets to the release, which could be used by GitHub Actions for additional uses, for example the [`@actions/upload-release-asset`](https://www.github.com/actions/upload-release-asset) GitHub Action 25 | 26 | ### Example workflow - create a release 27 | On every `push` to a tag matching the pattern `v*`, [create a release](https://developer.github.com/v3/repos/releases/#create-a-release): 28 | 29 | ```yaml 30 | on: 31 | push: 32 | # Sequence of patterns matched against refs/tags 33 | tags: 34 | - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 35 | 36 | name: Create Release 37 | 38 | jobs: 39 | build: 40 | name: Create Release 41 | runs-on: ubuntu-latest 42 | steps: 43 | - name: Checkout code 44 | uses: actions/checkout@master 45 | - name: Create Release 46 | id: create_release 47 | uses: actions/create-release@latest 48 | env: 49 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # This token is provided by Actions, you do not need to create your own token 50 | with: 51 | tag_name: ${{ github.ref }} 52 | release_name: Release ${{ github.ref }} 53 | body: | 54 | Changes in this Release 55 | - First Change 56 | - Second Change 57 | draft: false 58 | prerelease: false 59 | ``` 60 | 61 | This will create a [Release](https://help.github.com/en/articles/creating-releases), as well as a [`release` event](https://developer.github.com/v3/activity/events/types/#releaseevent), which could be handled by a third party service, or by GitHub Actions for additional uses, for example the [`@actions/upload-release-asset`](https://www.github.com/actions/upload-release-asset) GitHub Action. This uses the `GITHUB_TOKEN` provided by the [virtual environment](https://help.github.com/en/github/automating-your-workflow-with-github-actions/virtual-environments-for-github-actions#github_token-secret), so no new token is needed. 62 | 63 | ## Contributing 64 | We would love you to contribute to `@actions/create-release`, pull requests are welcome! Please see the [CONTRIBUTING.md](CONTRIBUTING.md) for more information. 65 | 66 | ## License 67 | The scripts and documentation in this project are released under the [MIT License](LICENSE) 68 | -------------------------------------------------------------------------------- /action.yml: -------------------------------------------------------------------------------- 1 | name: 'Create Tag Release' 2 | description: 'Create a release for a tag in your repository' 3 | author: 'liuxin' 4 | inputs: 5 | tag_name: 6 | description: 'The name of the tag. This should come from the webhook payload, `github.GITHUB_REF` when a user pushes a new tag' 7 | required: true 8 | release_name: 9 | description: 'The name of the release. For example, `Release v1.0.1`' 10 | required: true 11 | body: 12 | description: 'Text describing the contents of the tag.' 13 | required: false 14 | draft: 15 | description: '`true` to create a draft (unpublished) release, `false` to create a published one. Default: `false`' 16 | required: false 17 | default: false 18 | prerelease: 19 | description: '`true` to identify the release as a prerelease. `false` to identify the release as a full release. Default: `false`' 20 | required: false 21 | default: false 22 | outputs: 23 | id: 24 | description: 'The ID of the created Release' 25 | html_url: 26 | description: 'The URL users can navigate to in order to view the release' 27 | upload_url: 28 | description: 'The URL for uploading assets to the release' 29 | tag_name: 30 | description: 'The Tag Name' 31 | runs: 32 | using: 'node12' 33 | main: 'dist/index.js' 34 | branding: 35 | icon: 'tag' 36 | color: 'gray-dark' 37 | -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "create-release", 3 | "version": "1.0.0", 4 | "description": "Create a release", 5 | "main": "dist/index.js", 6 | "scripts": { 7 | "lint": "eslint 'src/**.js' 'tests/**.js' --fix", 8 | "test": "eslint 'src/**.js' 'tests/**.js' && jest --coverage", 9 | "build": "ncc build src/main.js", 10 | "precommit": "npm run build && git add dist/" 11 | }, 12 | "repository": { 13 | "type": "git", 14 | "url": "git+https://github.com/actions/create-release" 15 | }, 16 | "keywords": [ 17 | "actions", 18 | "node" 19 | ], 20 | "author": "GitHub", 21 | "license": "MIT", 22 | "dependencies": { 23 | "@actions/core": "^1.0.0", 24 | "@actions/exec": "^1.0.0", 25 | "@actions/github": "^1.0.0" 26 | }, 27 | "devDependencies": { 28 | "@zeit/ncc": "^0.20.4", 29 | "eslint": "^5.13.0", 30 | "eslint-config-airbnb": "^17.1.0", 31 | "eslint-config-prettier": "^3.6.0", 32 | "eslint-plugin-import": "^2.16.0", 33 | "eslint-plugin-jsx-a11y": "^6.2.1", 34 | "eslint-plugin-prettier": "^2.7.0", 35 | "eslint-plugin-react": "^7.12.4", 36 | "jest": "^24.8.0", 37 | "prettier": "^1.16.4", 38 | "husky": "^3.0.5" 39 | }, 40 | "jest": { 41 | "testEnvironment": "node", 42 | "collectCoverageFrom": [ 43 | "src/create-release.js" 44 | ], 45 | "coverageThreshold": { 46 | "global": { 47 | "branches": 80, 48 | "functions": 80, 49 | "lines": 80, 50 | "statements": 80 51 | } 52 | } 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/create-release.js: -------------------------------------------------------------------------------- 1 | const core = require('@actions/core'); 2 | const { GitHub, context } = require('@actions/github'); 3 | 4 | async function run() { 5 | try { 6 | // Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage 7 | const github = new GitHub(process.env.GITHUB_TOKEN); 8 | 9 | // Get owner and repo from context of payload that triggered the action 10 | const { owner, repo } = context.repo; 11 | 12 | // Get the inputs from the workflow file: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs 13 | const tagName = core.getInput('tag_name', { required: true }); 14 | 15 | // This removes the 'refs/tags' portion of the string, i.e. from 'refs/tags/v1.10.15' to 'v1.10.15' 16 | const tag = tagName.replace('refs/tags/', ''); 17 | const releaseName = core.getInput('release_name', { required: true }).replace('refs/tags/', ''); 18 | const body = core.getInput('body', { required: false }); 19 | const draft = core.getInput('draft', { required: false }) === 'true'; 20 | const prerelease = core.getInput('prerelease', { required: false }) === 'true'; 21 | 22 | // Create a release 23 | // API Documentation: https://developer.github.com/v3/repos/releases/#create-a-release 24 | // Octokit Documentation: https://octokit.github.io/rest.js/#octokit-routes-repos-create-release 25 | const createReleaseResponse = await github.repos.createRelease({ 26 | owner, 27 | repo, 28 | tag_name: tag, 29 | name: releaseName, 30 | body, 31 | draft, 32 | prerelease 33 | }); 34 | 35 | // Get the ID, html_url, and upload URL for the created Release from the response 36 | const { 37 | data: { id: releaseId, html_url: htmlUrl, upload_url: uploadUrl } 38 | } = createReleaseResponse; 39 | 40 | // Set the output variables for use by other actions: https://github.com/actions/toolkit/tree/master/packages/core#inputsoutputs 41 | core.setOutput('id', releaseId); 42 | core.setOutput('html_url', htmlUrl); 43 | core.setOutput('upload_url', uploadUrl); 44 | core.setOutput('tag_name,', tag); 45 | } catch (error) { 46 | core.setFailed(error.message); 47 | } 48 | } 49 | 50 | module.exports = run; 51 | -------------------------------------------------------------------------------- /src/main.js: -------------------------------------------------------------------------------- 1 | const run = require('./create-release'); 2 | 3 | if (require.main === module) { 4 | run(); 5 | } 6 | -------------------------------------------------------------------------------- /tests/create-release.test.js: -------------------------------------------------------------------------------- 1 | jest.mock('@actions/core'); 2 | jest.mock('@actions/github'); 3 | 4 | const core = require('@actions/core'); 5 | const { GitHub, context } = require('@actions/github'); 6 | const run = require('../src/create-release.js'); 7 | 8 | /* eslint-disable no-undef */ 9 | describe('Create Release', () => { 10 | let createRelease; 11 | 12 | beforeEach(() => { 13 | createRelease = jest.fn().mockReturnValueOnce({ 14 | data: { 15 | id: 'releaseId', 16 | html_url: 'htmlUrl', 17 | upload_url: 'uploadUrl' 18 | } 19 | }); 20 | 21 | context.repo = { 22 | owner: 'owner', 23 | repo: 'repo' 24 | }; 25 | 26 | const github = { 27 | repos: { 28 | createRelease 29 | } 30 | }; 31 | 32 | GitHub.mockImplementation(() => github); 33 | }); 34 | 35 | test('Create release endpoint is called', async () => { 36 | core.getInput = jest 37 | .fn() 38 | .mockReturnValueOnce('refs/tags/v1.0.0') 39 | .mockReturnValueOnce('myRelease') 40 | .mockReturnValueOnce('myBody') 41 | .mockReturnValueOnce('false') 42 | .mockReturnValueOnce('false'); 43 | 44 | await run(); 45 | 46 | expect(createRelease).toHaveBeenCalledWith({ 47 | owner: 'owner', 48 | repo: 'repo', 49 | tag_name: 'v1.0.0', 50 | name: 'myRelease', 51 | body: 'myBody', 52 | draft: false, 53 | prerelease: false 54 | }); 55 | }); 56 | 57 | test('Draft release is created', async () => { 58 | core.getInput = jest 59 | .fn() 60 | .mockReturnValueOnce('refs/tags/v1.0.0') 61 | .mockReturnValueOnce('myRelease') 62 | .mockReturnValueOnce('myBody') 63 | .mockReturnValueOnce('true') 64 | .mockReturnValueOnce('false'); 65 | 66 | await run(); 67 | 68 | expect(createRelease).toHaveBeenCalledWith({ 69 | owner: 'owner', 70 | repo: 'repo', 71 | tag_name: 'v1.0.0', 72 | name: 'myRelease', 73 | body: 'myBody', 74 | draft: true, 75 | prerelease: false 76 | }); 77 | }); 78 | 79 | test('Pre-release release is created', async () => { 80 | core.getInput = jest 81 | .fn() 82 | .mockReturnValueOnce('refs/tags/v1.0.0') 83 | .mockReturnValueOnce('myRelease') 84 | .mockReturnValueOnce('myBody') 85 | .mockReturnValueOnce('false') 86 | .mockReturnValueOnce('true'); 87 | 88 | await run(); 89 | 90 | expect(createRelease).toHaveBeenCalledWith({ 91 | owner: 'owner', 92 | repo: 'repo', 93 | tag_name: 'v1.0.0', 94 | name: 'myRelease', 95 | body: 'myBody', 96 | draft: false, 97 | prerelease: true 98 | }); 99 | }); 100 | 101 | test('Release with empty body is created', async () => { 102 | core.getInput = jest 103 | .fn() 104 | .mockReturnValueOnce('refs/tags/v1.0.0') 105 | .mockReturnValueOnce('myRelease') 106 | .mockReturnValueOnce('') // <-- The default value for body in action.yml 107 | .mockReturnValueOnce('false') 108 | .mockReturnValueOnce('false'); 109 | 110 | await run(); 111 | 112 | expect(createRelease).toHaveBeenCalledWith({ 113 | owner: 'owner', 114 | repo: 'repo', 115 | tag_name: 'v1.0.0', 116 | name: 'myRelease', 117 | body: '', 118 | draft: false, 119 | prerelease: false 120 | }); 121 | }); 122 | 123 | test('Outputs are set', async () => { 124 | core.getInput = jest 125 | .fn() 126 | .mockReturnValueOnce('refs/tags/v1.0.0') 127 | .mockReturnValueOnce('myRelease') 128 | .mockReturnValueOnce('myBody') 129 | .mockReturnValueOnce('false') 130 | .mockReturnValueOnce('false'); 131 | 132 | core.setOutput = jest.fn(); 133 | 134 | await run(); 135 | 136 | expect(core.setOutput).toHaveBeenNthCalledWith(1, 'id', 'releaseId'); 137 | expect(core.setOutput).toHaveBeenNthCalledWith(2, 'html_url', 'htmlUrl'); 138 | expect(core.setOutput).toHaveBeenNthCalledWith(3, 'upload_url', 'uploadUrl'); 139 | }); 140 | 141 | test('Action fails elegantly', async () => { 142 | core.getInput = jest 143 | .fn() 144 | .mockReturnValueOnce('refs/tags/v1.0.0') 145 | .mockReturnValueOnce('myRelease') 146 | .mockReturnValueOnce('myBody') 147 | .mockReturnValueOnce('false') 148 | .mockReturnValueOnce('false'); 149 | 150 | createRelease.mockRestore(); 151 | createRelease.mockImplementation(() => { 152 | throw new Error('Error creating release'); 153 | }); 154 | 155 | core.setOutput = jest.fn(); 156 | 157 | core.setFailed = jest.fn(); 158 | 159 | await run(); 160 | 161 | expect(createRelease).toHaveBeenCalled(); 162 | expect(core.setFailed).toHaveBeenCalledWith('Error creating release'); 163 | expect(core.setOutput).toHaveBeenCalledTimes(0); 164 | }); 165 | }); 166 | --------------------------------------------------------------------------------