Updated octokit methods.

This commit is contained in:
Corey Butler 2020-01-30 18:33:32 -06:00
parent d5e17eef8c
commit 3071dd056e

View File

@ -1,5 +1,5 @@
const github = require('@actions/github')
const core = require('@actions/core')
const { GitHub, context } = require('@actions/github')
const fs = require('fs')
const path = require('path')
const os = require('os')
@ -26,7 +26,7 @@ async function run() {
core.setFailed('Invalid or missing GITHUB_TOKEN.')
return
}
}
}
const pkg_root = core.getInput('package_root', { required: false })
const pkgfile = path.join(process.env.GITHUB_WORKSPACE, pkg_root, 'package.json')
@ -39,15 +39,22 @@ async function run() {
core.setOutput('version', pkg.version)
core.debug(` Detected version ${pkg.version}`)
// Check for existing tag
const git = new github.GitHub(process.env.INPUT_GITHUB_TOKEN || process.env.GITHUB_TOKEN)
const owner = process.env.GITHUB_REPOSITORY.split('/').shift()
const repo = process.env.GITHUB_REPOSITORY.split('/').pop()
// Get authenticated GitHub client (Ocktokit): https://github.com/actions/toolkit/tree/master/packages/github#usage
const github = new GitHub(process.env.GITHUB_TOKEN || process.env.INPUT_GITHUB_TOKEN)
// Get owner and repo from context of payload that triggered the action
const { owner, repo } = context.repo
// // Check for existing tag
// const git = new github.GitHub(process.env.INPUT_GITHUB_TOKEN || process.env.GITHUB_TOKEN)
// const owner = process.env.GITHUB_REPOSITORY.split('/').shift()
// const repo = process.env.GITHUB_REPOSITORY.split('/').pop()
let tags
try {
tags = await git.repos.listTags({
...repo,
tags = await github.repos.listTags({
owner,
repo,
per_page: 100,
})
} catch (e) {
@ -56,9 +63,10 @@ async function run() {
}
}
const tagPrefix = core.getInput('tag_prefix', { required: false })
const tagSuffix = core.getInput('tag_suffix', { required: false })
const getTagName = version => {
const tagPrefix = core.getInput('tag_prefix', { required: false })
const tagSuffix = core.getInput('tag_suffix', { required: false })
return `${tagPrefix}${version}${tagSuffix}`
}
@ -79,8 +87,9 @@ async function run() {
try {
latestTag = tags.data.shift()
let changelog = await git.repos.compareCommits({
...repo,
let changelog = await github.repos.compareCommits({
owner,
repo,
base: latestTag.name,
head: 'master',
})
@ -107,15 +116,16 @@ async function run() {
try {
tagMsg = tagMsg.trim().length > 0 ? tagMsg : `Version ${pkg.version}`
newTag = await git.git.createTag({
...repo,
newTag = await github.git.createTag({
owner,
repo,
tag: tagName,
message: tagMsg,
object: process.env.GITHUB_SHA,
type: 'commit',
type: 'commit'
})
console.log(`Created new tag: ${newTag.data.tag}` + os.EOL)
core.warning(`Created new tag: ${newTag.data.tag}`)
} catch (e) {
core.setFailed(e.message)
return
@ -123,16 +133,18 @@ async function run() {
let newReference
try {
newReference = await git.git.createRef({
...repo,
newReference = await github.git.createRef({
owner,
repo,
ref: `refs/tags/${newTag.data.tag}`,
sha: newTag.data.sha,
})
console.log(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL)
core.warning(`Reference ${newReference.data.ref} available at ${newReference.data.url}` + os.EOL)
} catch (e) {
core.warning({
...repo,
owner,
repo,
ref: `refs/tags/${newTag.data.tag}`,
sha: newTag.data.sha,
})