Skip to content

Commit

Permalink
Merge pull request #7 from issue-ops/versioning
Browse files Browse the repository at this point in the history
Versioning and config
  • Loading branch information
ncalteen authored Sep 20, 2023
2 parents 45feaa0 + 686efee commit 45c1400
Show file tree
Hide file tree
Showing 16 changed files with 173 additions and 122 deletions.
5 changes: 5 additions & 0 deletions .github/codeql/codeql-config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
name: CodeQL Configuration

paths-ignore:
- node_modules
- dist
4 changes: 2 additions & 2 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ updates:
- package-ecosystem: github-actions
directory: /
schedule:
interval: weekly
interval: monthly
labels:
- dependabot
- actions
Expand All @@ -13,7 +13,7 @@ updates:
- package-ecosystem: npm
directory: /
schedule:
interval: weekly
interval: monthly
labels:
- dependabot
- npm
Expand Down
1 change: 0 additions & 1 deletion .github/linters/.shellcheckrc

This file was deleted.

45 changes: 45 additions & 0 deletions .github/workflows/continuous-delivery.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Continuous Delivery

on:
pull_request:
types:
- closed
branches:
- main

# This is required to be able to update tags and create releases
permissions:
contents: write

jobs:
release:
name: Release Version
runs-on: ubuntu-latest

# Only run this job if the PR was merged
if: ${{ github.event.pull_request.merged == true }}

steps:
# Checkout the repository with fetch-tags set to true
- name: Checkout
id: checkout
uses: actions/checkout@v4
with:
fetch-tags: true

# Get the version and update the tags to use in the release
- name: Tag
id: tag
uses: issue-ops/[email protected]
with:
manifest-path: package.json
workspace: ${{ github.workspace }}
ref: main

# Use the version output from the previous step for the release
# Prepend a 'v' to the beginning (e.g. 'v1.2.3')
- name: Create Release
id: release
uses: issue-ops/[email protected]
with:
tag: v${{ steps.tag.outputs.version }}
2 changes: 1 addition & 1 deletion .github/workflows/continuous-integration.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Continuous Integration

on:
push:
branches:
branches-ignore:
- main
pull_request:
branches:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/super-linter.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: Super Linter

on:
push:
branches:
branches-ignore:
- main
pull_request:
branches:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
[![Check dist/](https://github.com/issue-ops/parser/actions/workflows/check-dist.yml/badge.svg)](https://github.com/issue-ops/parser/actions/workflows/check-dist.yml)
[![CodeQL](https://github.com/issue-ops/parser/actions/workflows/codeql.yml/badge.svg)](https://github.com/issue-ops/parser/actions/workflows/codeql.yml)
[![Continuous Integration](https://github.com/issue-ops/parser/actions/workflows/continuous-integration.yml/badge.svg)](https://github.com/issue-ops/parser/actions/workflows/continuous-integration.yml)
[![Continuous Delivery](https://github.com/issue-ops/parser/actions/workflows/continuous-delivery.yml/badge.svg)](https://github.com/issue-ops/parser/actions/workflows/continuous-delivery.yml)
[![Super Linter](https://github.com/issue-ops/parser/actions/workflows/super-linter.yml/badge.svg)](https://github.com/issue-ops/parser/actions/workflows/super-linter.yml)
[![Code Coverage](./badges/coverage.svg)](./badges/coverage.svg)

Expand Down
60 changes: 7 additions & 53 deletions __tests__/index.test.ts
Original file line number Diff line number Diff line change
@@ -1,62 +1,16 @@
/**
* Unit tests for the action's index.ts file.
* Unit tests for the action's entrypoint, src/index.ts
*/

import * as core from '@actions/core'
import fs from 'fs'
import * as main from '../src/main'

const getInputMock = jest.spyOn(core, 'getInput')
const setOutputMock = jest.spyOn(core, 'setOutput')
// Mock the action's entrypoint
const runMock = jest.spyOn(main, 'run').mockImplementation()

describe('index', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('retrieves the inputs', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'body':
return fs.readFileSync(
'__tests__/fixtures/bug-report/issue.md',
'utf8'
)
case 'csv_to_list':
return 'true'
default:
return ''
}
})

const { run } = require('../src/index')
await run()

expect(getInputMock).toHaveBeenCalledWith('body', { required: true })
expect(getInputMock).toHaveBeenCalledWith('csv_to_list')
})

it('returns the parsed body as JSON', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'body':
return fs.readFileSync(
'__tests__/fixtures/bug-report/issue.md',
'utf8'
)
case 'csv_to_list':
return 'true'
default:
return ''
}
})

const expected = JSON.parse(
fs.readFileSync('__tests__/fixtures/bug-report/expected.json', 'utf8')
)

const { run } = require('../src/index')
await run()
it('calls run when imported', async () => {
require('../src/index')

expect(setOutputMock).toHaveBeenCalledWith('json', JSON.stringify(expected))
expect(runMock).toHaveBeenCalled()
})
})
61 changes: 61 additions & 0 deletions __tests__/main.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/**
* Unit tests for the action's index.ts file.
*/

import * as core from '@actions/core'
import * as main from '../src/main'
import fs from 'fs'

const getInputMock = jest.spyOn(core, 'getInput')
const setOutputMock = jest.spyOn(core, 'setOutput')

describe('index', () => {
beforeEach(() => {
jest.clearAllMocks()
})

it('retrieves the inputs', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'body':
return fs.readFileSync(
'__tests__/fixtures/bug-report/issue.md',
'utf8'
)
case 'csv_to_list':
return 'true'
default:
return ''
}
})

await main.run()

expect(getInputMock).toHaveBeenCalledWith('body', { required: true })
expect(getInputMock).toHaveBeenCalledWith('csv_to_list')
})

it('returns the parsed body as JSON', async () => {
getInputMock.mockImplementation((name: string) => {
switch (name) {
case 'body':
return fs.readFileSync(
'__tests__/fixtures/bug-report/issue.md',
'utf8'
)
case 'csv_to_list':
return 'true'
default:
return ''
}
})

const expected = JSON.parse(
fs.readFileSync('__tests__/fixtures/bug-report/expected.json', 'utf8')
)

await main.run()

expect(setOutputMock).toHaveBeenCalledWith('json', JSON.stringify(expected))
})
})
26 changes: 17 additions & 9 deletions dist/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "parser",
"description": "Convert issue form responses to JSON",
"version": "0.1.0",
"version": "0.1.1",
"author": "Nick Alteen <[email protected]>",
"homepage": "https://github.com/issue-ops/parser#readme",
"repository": {
Expand All @@ -17,7 +17,10 @@
"issueops"
],
"engines": {
"node": ">=18"
"node": ">=20"
},
"exports": {
".": "./dist/index.js"
},
"scripts": {
"bundle": "npm run format:write && npm run package",
Expand All @@ -31,7 +34,6 @@
"all": "npm run format:write && npm run lint && npm run test && npm run package"
},
"license": "MIT",
"main": "index.js",
"jest": {
"clearMocks": true,
"collectCoverage": true,
Expand Down
28 changes: 0 additions & 28 deletions script/release

This file was deleted.

22 changes: 2 additions & 20 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
import * as core from '@actions/core'
import { parse } from './parse'

/**
* The entrypoint for the action
* The entrypoint for the action.
*/
export async function run(): Promise<void> {
// Get the input string
const body: string = core.getInput('body', { required: true })

// Get other input parameters
const csvToList: boolean = core.getInput('csv_to_list') === 'true'

core.info('Running action with the following inputs:')
core.info(` csv_to_list: ${csvToList}`)
core.info(` body: ${body}`)

// Parse the body
const parsedBody = await parse(body, csvToList)
core.debug(`Parsed body: ${JSON.stringify(parsedBody, null, 2)}`)
core.setOutput('json', JSON.stringify(parsedBody))
}
import { run } from './main'

run()
Loading

0 comments on commit 45c1400

Please sign in to comment.