Skip to content

Commit

Permalink
Version v0.1.0 (#2)
Browse files Browse the repository at this point in the history
* 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
dangoslen authored Apr 26, 2020
1 parent f239a77 commit df72635
Show file tree
Hide file tree
Showing 14 changed files with 27,249 additions and 278 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
name: "units-test"
on:
pull_request:
push:
branches:
- master
- 'releases/*'
types: [opened, synchronize, reopened, ready_for_review, labeled, unlabeled]

jobs:
# unit tests
Expand All @@ -21,5 +18,3 @@ jobs:
steps:
- uses: actions/checkout@v1
- uses: ./
with:
milliseconds: 1000
7 changes: 7 additions & 0 deletions CHANGELOG.md
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
97 changes: 97 additions & 0 deletions __tests__/changelog-enforcer.test.js
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')
})
})
})
3 changes: 3 additions & 0 deletions __tests__/env.js
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
455 changes: 455 additions & 0 deletions __tests__/pull_request.json

Large diffs are not rendered by default.

17 changes: 9 additions & 8 deletions action.yml
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'
Loading

0 comments on commit df72635

Please sign in to comment.