-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathindex.js
193 lines (167 loc) · 6.18 KB
/
index.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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
/*
* Copyright (c) 2020-present unTill Pro, Ltd. and Contributors
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
*/
const core = require('@actions/core')
const github = require('@actions/github')
const execute = require('./common').execute
const rejectHiddenFolders = require('./rejectHiddenFolders')
const checkSources = require('./checkSources')
const publish = require('./publish')
const getInputAsArray = function (name) {
let input = core.getInput(name)
return !input ? [] : input.split(',').map(it => it.trim())
}
async function run() {
try {
const ignore = getInputAsArray('ignore')
const organization = getInputAsArray('organization')
const token = core.getInput('token')
const codecovToken = core.getInput('codecov-token')
const codecovGoRace = core.getInput ('codecov-go-race') === 'true'
const publishAsset = core.getInput('publish-asset')
const publishToken = core.getInput('publish-token')
const publishKeep = core.getInput('publish-keep')
const repository = core.getInput('repository')
const runModTidy = core.getInput('run-mod-tidy') === 'false'
const mainBranch = core.getInput('main-branch')
const ignoreCopyright = core.getInput('ignore-copyright') === 'true'
const ignoreRunBuild = core.getInput('ignore-build')
const testfolder = core.getInput('test-folder')
const shorttest = core.getInput ('short-test')
const buildcmd = core.getInput ('build-cmd')
const repositoryOwner = repository.split('/')[0] ||
github.context.payload && github.context.payload.repository && github.context.payload.repository.owner && github.context.payload.repository.owner.login
const repositoryName = repository && repository.split('/')[1] ||
github.context.payload && github.context.payload.repository && github.context.payload.repository.name
const isNotFork = github.context.payload && github.context.payload.repository && !github.context.payload.repository.fork
let branchName = github.context.ref
if (branchName && branchName.indexOf('refs/heads/') > -1)
branchName = branchName.slice('refs/heads/'.length)
// // Print githubJson
// core.startGroup("githubJson")
// const githubJson = JSON.stringify(github, undefined, 2)
// core.info(githubJson)
// core.endGroup()
// Print data from webhook context
core.startGroup("Context")
core.info(`github.repository: ${github.repository}`)
core.info(`github.token: ${github.token}`)
//core.info(`github.context.repo: ${github.context.repo}`)
core.info(`repository: ${repository}`)
core.info(`organization: ${organization}`)
core.info(`repositoryOwner: ${repositoryOwner}`)
core.info(`repositoryName: ${repositoryName}`)
core.info(`actor: ${github.context.actor}`)
core.info(`eventName: ${github.context.eventName}`)
core.info(`isNotFork: ${isNotFork}`)
core.info(`branchName: ${branchName}`)
core.endGroup()
// Reject ".*" folders
rejectHiddenFolders(ignore)
// Reject sources which do not have "Copyright" word in first comment
// Reject sources which have LICENSE word in first comment but LICENSE file does not exist
checkSources.checkFirstCommentInSources(ignore, ignoreCopyright)
let language = checkSources.detectLanguage()
if (language === "go") {
core.info('Go project detected')
// Reject go.mod with local replaces
checkSources.checkGoMod()
// Build
core.startGroup('Build & test')
try {
for (const i in organization) {
process.env.GOPRIVATE = (process.env.GOPRIVATE ? process.env.GOPRIVATE + ',' : '') + `github.com/${organization[i]}/*`
if (token) {
await execute(`git config --global url."https://${token}:[email protected]/${organization[i]}".insteadOf "https://github.com/${organization[i]}"`)
}
}
if (testfolder.length != 0) {
await execute('cd ' + testfolder)
}
if (runModTidy === "true") {
await execute('go mod tidy')
}
if (ignoreRunBuild !== "true") {
await execute('go build ./...')
}
// run Codecov / test
if ( codecovToken.length > 0 ) {
core.startGroup('Codecov')
await execute('go install github.com/heeus/gocov@latest')
let tststr=''
/*
if (codecovGoRace)
tststr='gocov -t="-race -covermode=atomic" -v'
else
tststr='gocov -t="-covermode=atomic" -v'
*/
if (codecovGoRace)
tststr = 'go test ./... -race -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...'
else
tststr ='go test ./... -coverprofile=coverage.txt -covermode=atomic -coverpkg=./...'
if (shorttest === "true"){
tststr=tststr + ' -short'
}
await execute(tststr)
core.endGroup()
await execute(`bash -c "bash <(curl -Os https://uploader.codecov.io/latest/linux/codecov) -t ${codecovToken}"`)
} else {
let tststr='go test ./...'
if (codecovGoRace)
tststr=tststr + ' -race'
if (shorttest === "true"){
tststr=tststr + ' -short'
}
await execute(tststr)
}
if (testfolder.length != 0) {
await execute('cd .')
}
if (buildcmd !== '') {
await execute(buildcmd)
}
} finally {
core.endGroup()
}
} if (language === "node_js") {
core.info('Node.js project detected')
// Build
core.startGroup('Build')
try {
await execute('npm install')
await execute('npm run build --if-present')
await execute('npm test')
// run Codecov
if (codecovToken) {
core.endGroup()
core.startGroup('Codecov')
await execute('npm install -g codecov')
await execute('istanbul cover ./node_modules/mocha/bin/_mocha --reporter lcovonly -- -R spec')
await execute(`codecov --token=${codecovToken}`)
}
} finally {
core.endGroup()
}
}
let publishResult = null
// Publish asset
if (branchName === mainBranch && publishAsset) {
core.startGroup("Publish")
try {
publishResult = await publish.publishAsRelease(publishAsset, publishToken, publishKeep, repositoryOwner, repositoryName, github.context.sha)
} finally {
core.endGroup()
}
}
if (publishResult !== null)
for (const name in publishResult)
core.setOutput(name, `${publishResult[name] || ''}`)
} catch (error) {
core.setFailed(error.message)
}
}
run()