1
0
mirror of https://github.com/joaquinjsb/gitea-release-please-action synced 2026-05-05 10:37:47 +02:00

test: add tests and configure CI/CD (#104)

This commit is contained in:
Benjamin E. Coe
2020-11-25 14:10:46 -05:00
committed by GitHub
parent 562cbbb631
commit fe20625bea
6 changed files with 1108 additions and 6 deletions

35
.github/workflows/ci.yaml vendored Normal file
View File

@@ -0,0 +1,35 @@
on:
push:
branches:
- main
pull_request:
name: ci
jobs:
test:
runs-on: ubuntu-latest
strategy:
matrix:
node: [12, 14]
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}
- run: node --version
# The first installation step ensures that all of our production
# dependencies work on the given Node.js version, this helps us find
# dependencies that don't match our engines field:
- run: npm install --production --engine-strict --ignore-scripts --no-package-lock
# Clean up the production install, before installing dev/production:
- run: rm -rf node_modules
- run: npm install
- run: npm test
windows:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- uses: actions/setup-node@v1
with:
node-version: 14
- run: npm install
- run: npm test

1
.gitignore vendored
View File

@@ -1,2 +1,3 @@
coverage
node_modules
.DS_Store

View File

@@ -25,7 +25,8 @@ async function main () {
// First we check for any merged release PRs (PRs merged with the label
// "autorelease: pending"):
if (!command || command === 'github-release') {
const gr = new GitHubRelease({
const Release = releasePlease.getGitHubRelease()
const gr = new Release({
label: RELEASE_LABEL,
repoUrl: process.env.GITHUB_REPOSITORY,
packageName,
@@ -45,7 +46,7 @@ async function main () {
// Next we check for PRs merged since the last release, and groom the
// release PR:
if (!command || command === 'release-pr') {
const release = ReleasePRFactory.buildStatic(releaseType, {
const release = releasePlease.getReleasePRFactory().buildStatic(releaseType, {
monorepoTags,
packageName,
path,
@@ -62,6 +63,24 @@ async function main () {
}
}
main().catch(err => {
core.setFailed(`release-please failed: ${err.message}`)
})
function getGitHubRelease () {
return GitHubRelease
}
function getReleasePRFactory () {
return ReleasePRFactory
}
const releasePlease = {
main,
getGitHubRelease,
getReleasePRFactory
}
if (require.main === module) {
main().catch(err => {
core.setFailed(`release-please failed: ${err.message}`)
})
} else {
module.exports = releasePlease
}

924
package-lock.json generated

File diff suppressed because it is too large Load Diff

View File

@@ -5,7 +5,8 @@
"description": "automated releases based on conventional commits",
"main": "index.js",
"scripts": {
"test": "standard",
"test": "c8 mocha test/*.js",
"posttest": "standard",
"fix": "standard --fix",
"build": "ncc build index.js"
},
@@ -29,6 +30,9 @@
},
"devDependencies": {
"@zeit/ncc": "^0.22.3",
"c8": "^7.3.5",
"mocha": "^8.2.1",
"sinon": "^9.2.1",
"standard": "^14.3.4"
},
"standard": {

119
test/release-please.js Normal file
View File

@@ -0,0 +1,119 @@
const { describe, it } = require('mocha')
const action = require('../')
const assert = require('assert')
const core = require('@actions/core')
const sinon = require('sinon')
describe('release-please-action', () => {
it('both opens PR and tags GitHub releases by default', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
}
const input = {
'release-type': 'node'
}
core.getInput = (name) => {
return input[name]
}
const createRelease = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = createRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
}
}
await action.main()
sinon.assert.calledOnce(createRelease)
sinon.assert.calledOnce(releasePR)
assert.deepStrictEqual(output, {
release_created: true,
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
})
it('only opens PRs if, command set to release-pr', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
}
const input = {
'release-type': 'node',
command: 'release-pr'
}
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
}
}
await action.main()
sinon.assert.notCalled(githubRelease)
sinon.assert.calledOnce(releasePR)
})
it('only opens tags releases, if command set to github-release', async () => {
const output = {}
core.setOutput = (name, value) => {
output[name] = value
}
const input = {
'release-type': 'node',
command: 'github-release'
}
core.getInput = (name) => {
return input[name]
}
const githubRelease = sinon.stub().returns({
upload_url: 'http://example.com',
tag_name: 'v1.0.0'
})
action.getGitHubRelease = () => {
class Release {}
Release.prototype.createRelease = githubRelease
return Release
}
const releasePR = sinon.stub()
action.getReleasePRFactory = () => {
return {
buildStatic: () => {
return {
run: releasePR
}
}
}
}
await action.main()
sinon.assert.calledOnce(githubRelease)
sinon.assert.notCalled(releasePR)
})
})