- introduce proper approach to retrieve tag before a given tag

- add configuration options for
  - path
  - configuration
  - fromTag, toTag
  - token
- allow to specify transformers to adjust information to a specific form
- allow to specify different templates
- speed up by limiting information to pull
- add logic to automatically resolve current
- use github actions logger
This commit is contained in:
Mike Penz
2020-10-16 15:52:24 +02:00
parent 5ec7a2d86f
commit 0a66008df0
18 changed files with 14515 additions and 158 deletions
+80 -7
View File
@@ -1,16 +1,89 @@
import * as core from '@actions/core'
import {wait} from './wait'
import { wait } from './wait'
import { readConfiguration } from './utils';
import { ReleaseNotes } from './releaseNotes';
import { createCommandManager } from './git-helper';
import * as github from '@actions/github'
import * as path from 'path';
async function run(): Promise<void> {
try {
const ms: string = core.getInput('milliseconds')
core.debug(`Waiting ${ms} milliseconds ...`) // debug is only output if you set the secret `ACTIONS_RUNNER_DEBUG` to true
let githubWorkspacePath = process.env['GITHUB_WORKSPACE']
if (!githubWorkspacePath) {
throw new Error('GITHUB_WORKSPACE not defined')
}
githubWorkspacePath = path.resolve(githubWorkspacePath)
core.debug(`GITHUB_WORKSPACE = '${githubWorkspacePath}'`)
core.debug(new Date().toTimeString())
await wait(parseInt(ms, 10))
core.debug(new Date().toTimeString())
let repositoryPath = core.getInput('path') || '.'
repositoryPath = path.resolve(
githubWorkspacePath,
repositoryPath
)
core.debug(`repositoryPath = '${repositoryPath}'`)
core.setOutput('time', new Date().toTimeString())
const configurationFile: string = core.getInput('configuration')
const configurationPath = path.resolve(
githubWorkspacePath,
configurationFile
)
core.debug(`configurationPath = '${configurationPath}'`)
const configuration = readConfiguration(configurationPath)
let token = core.getInput('token')
let owner = core.getInput('owner')
let repo = core.getInput('repo')
let fromTag = core.getInput("fromTag")
let toTag = core.getInput("toTag")
if (!toTag) {
// if not specified try to retrieve tag from git
const gitHelper = await createCommandManager(repositoryPath)
const latestTag = await gitHelper.latestTag()
toTag = latestTag
core.debug(`toTag = '${latestTag}'`)
}
if (!owner || !repo) {
// Qualified repository
const qualifiedRepository = core.getInput('repository') || `${github.context.repo.owner}/${github.context.repo.repo}`
core.debug(`qualified repository = '${qualifiedRepository}'`)
const splitRepository = qualifiedRepository.split('/')
if (splitRepository.length !== 2 || !splitRepository[0] || !splitRepository[1]) {
throw new Error(
`Invalid repository '${qualifiedRepository}'. Expected format {owner}/{repo}.`
)
}
owner = splitRepository[0]
repo = splitRepository[1]
}
if (!owner) {
core.error(`Missing or couldn't resolve 'owner'`)
return
}
if (!repo) {
core.error(`Missing or couldn't resolve 'owner'`)
return
}
if (!toTag) {
core.error(`Missing or couldn't resolve 'toTag'`)
return
}
const releaseNotes = new ReleaseNotes({
owner: owner,
repo: repo,
fromTag: fromTag,
toTag: toTag,
configuration: configuration
})
core.setOutput('changelog', await releaseNotes.pull(token))
} catch (error) {
core.setFailed(error.message)
}