generated from actions/javascript-action
-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Adds first jest test * Finished core functionality * Finished build * Trying something * Trying something different * Trying something again * Silly * Silly (again) * seperate options * Using git differently * Using different git command * Adds initial changelog
- Loading branch information
Showing
14 changed files
with
27,249 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# CHANGELOG | ||
|
||
* Pending <major>.<minor>.<patch> | ||
* Change | ||
|
||
* v0.1.0 | ||
* Adds initial `Changelog Enforcer` functionality, including the use of a label to skip |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,97 @@ | ||
const core = require('@actions/core') | ||
const exec = require('@actions/exec') | ||
const changelogEnforcer = require('../src/changelog-enforcer') | ||
|
||
// Inputs for mock @actions/core | ||
let inputs = {} | ||
|
||
describe('the changelog-enforcer', () => { | ||
|
||
afterAll(() => { | ||
// Restore | ||
jest.restoreAllMocks() | ||
}) | ||
|
||
beforeEach(() => { | ||
jest.clearAllMocks() | ||
|
||
jest.spyOn(core, 'getInput').mockImplementation((name) => { | ||
return inputs[name] | ||
}) | ||
}) | ||
|
||
it('should skip enforcing when label is present', () => { | ||
// Mock getInput | ||
inputs['skipLabel'] = 'Skip-Changelog' | ||
inputs['changeLogPath'] = 'CHANGELOG.md' | ||
|
||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(jest.fn()) | ||
const failureSpy = jest.spyOn(core, 'error').mockImplementation(jest.fn()) | ||
const execSpy = jest.spyOn(exec, 'exec').mockImplementation((command, args, options) => { return 0 }) | ||
|
||
changelogEnforcer.enforce() | ||
.then(() => { | ||
expect(infoSpy.mock.calls.length).toBe(2) | ||
expect(execSpy).not.toHaveBeenCalled() | ||
expect(failureSpy).not.toHaveBeenCalled() | ||
}) | ||
}) | ||
|
||
it('should enforce when label is not present; changelog is not present', () => { | ||
// Mock getInput | ||
inputs['skipLabel'] = 'A different label' | ||
inputs['changeLogPath'] = 'CHANGELOG.md' | ||
|
||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(jest.fn()) | ||
const failureSpy = jest.spyOn(core, 'setFailed').mockImplementation(jest.fn()) | ||
const execSpy = jest.spyOn(exec, 'exec').mockImplementation((command, args, options) => { | ||
const stdout = | ||
`M .env.js | ||
A an_added_changed_file.js` | ||
|
||
options.listeners.stdout(stdout) | ||
return 0 | ||
}) | ||
|
||
changelogEnforcer.enforce() | ||
.then(() => { | ||
expect(infoSpy.mock.calls.length).toBe(2) | ||
expect(execSpy).toHaveBeenCalled() | ||
expect(failureSpy).toHaveBeenCalled() | ||
|
||
const command = execSpy.mock.calls[0][0] | ||
const commandArgs = execSpy.mock.calls[0][1].join(' ') | ||
expect(command).toBe('git') | ||
expect(commandArgs).toBe('diff origin/master --name-status --diff-filter=AM') | ||
}) | ||
}) | ||
|
||
it('should enforce when label is not present; changelog is present', () => { | ||
// Mock getInput | ||
inputs['skipLabel'] = 'A different label' | ||
inputs['changeLogPath'] = 'CHANGELOG.md' | ||
|
||
const infoSpy = jest.spyOn(core, 'info').mockImplementation(jest.fn()) | ||
const failureSpy = jest.spyOn(core, 'setFailed').mockImplementation(jest.fn()) | ||
const execSpy = jest.spyOn(exec, 'exec').mockImplementation((command, args, options) => { | ||
const stdout = | ||
`M .env.js | ||
M CHANGELOG.md` | ||
|
||
options.listeners.stdout(stdout) | ||
return 0 | ||
}) | ||
|
||
changelogEnforcer.enforce() | ||
.then(() => { | ||
expect(infoSpy.mock.calls.length).toBe(2) | ||
expect(execSpy).toHaveBeenCalled() | ||
expect(failureSpy).not.toHaveBeenCalled() | ||
|
||
const command = execSpy.mock.calls[0][0] | ||
const commandArgs = execSpy.mock.calls[0][1].join(' ') | ||
expect(command).toBe('git') | ||
expect(commandArgs).toBe('diff origin/master --name-status --diff-filter=AM') | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
const path = require('path') | ||
const eventPath = path.resolve(__dirname, 'pull_request.json') | ||
process.env.GITHUB_EVENT_PATH = eventPath |
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,14 @@ | ||
name: 'Wait' | ||
description: 'Wait a designated number of milliseconds' | ||
name: 'Changelog Enforcer' | ||
description: 'Enforces a repository changelog to be kept up to date.' | ||
inputs: | ||
milliseconds: # id of input | ||
description: 'number of milliseconds to wait' | ||
changeLogPath: # id of input | ||
description: 'Path to the changelog file relative to the repository. Comparison is done using `git diff ... | grep ${changeLogPath}`' | ||
required: true | ||
default: '1000' | ||
outputs: | ||
time: # output will be available to future steps | ||
description: 'The message to output' | ||
default: 'CHANGELOG.md' | ||
skipLabel: | ||
description: 'Name of the label used to skip enforcing a changelog change' | ||
required: true | ||
default: 'Skip-Changelog' | ||
runs: | ||
using: 'node12' | ||
main: 'dist/index.js' |
Oops, something went wrong.