-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.js
82 lines (67 loc) · 2.2 KB
/
action.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
const core = require('@actions/core')
const github = require('@actions/github')
const process = require('process')
const customRepo = (repoPath) => {
const segments = repoPath.split('/', 2)
if (segments.length < 2) {
core.info('Please provide a repository in the format `owner/repo`.')
}
return segments
}
const repoInput = core.getInput('repo_path')
const [owner, repo] = repoInput
? customRepo(repoInput)
: process.env['GITHUB_REPOSITORY'].split('/', 2)
const octokit = new github.GitHub(
core.getInput('github_token', { required: true })
)
async function run() {
let latestRelease
core.info(`Fetching the latest release for \`${owner}/${repo}\``)
try {
latestRelease = await octokit.repos.getLatestRelease({
owner,
repo,
})
} catch (error) {
core.info('Could not fetch the latest release. Have you made one yet?')
core.setFailed(error)
}
const { data } = latestRelease
ref = `tags/${data.tag_name}`
try {
releaseCommit = await octokit.git.getRef({
owner,
repo,
ref
})
} catch (error) {
core.info(`Could not fetch the ref \`${ref}\`. Have you made one yet?`)
core.setFailed(error)
}
releaseHash = releaseCommit.data.object.sha
core.info(`Release hash \`${releaseHash}\``)
core.setOutput('url', data.url)
core.setOutput('assets_url', data.assets_url)
core.setOutput('upload_url', data.upload_url)
core.setOutput('html_url', data.html_url)
core.setOutput('id', data.id.toString())
core.setOutput('node_id', data.node_id)
core.setOutput('tag_name', data.tag_name)
core.setOutput('target_commitish', data.target_commitish)
core.setOutput('name', data.name)
core.setOutput('draft', data.draft)
core.setOutput('author_id', data.author.id.toString())
core.setOutput('author_node_id', data.author.node_id)
core.setOutput('author_url', data.author.url)
core.setOutput('author_login', data.author.login)
core.setOutput('author_html_url', data.author.html_url)
core.setOutput('author_type', data.author.type)
core.setOutput('author_site_admin', data.author.site_admin)
core.setOutput('sha', releaseHash)
}
try {
run()
} catch (error) {
core.setFailed(`Action failed with error ${error}`)
}