forked from mikeal/publish-to-github-action
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fa26238
commit 6d86bd6
Showing
1 changed file
with
62 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
import * as util from './util'; | ||
import * as config from './config'; | ||
import * as core from '@actions/core'; | ||
import { email, name } from './config/git'; | ||
import { getEnvRequired } from './util'; | ||
|
||
try { | ||
const remote = { | ||
name: 'publisher', | ||
url: config.git.remote | ||
}; | ||
|
||
const TZ = util.getEnv('TZ'); | ||
const force = `${util.getEnv('FORCE')}` == 'true'; | ||
const ref = util.git.revParse({ ref: util.getEnv('REF') || 'HEAD' }); | ||
const branch = util.getEnv('BRANCH') || ref; | ||
const pull = !(`${util.getEnv('PULL')}` == 'false'); | ||
const push = !(`${util.getEnv('PUSH')}` == 'false'); | ||
const rebase = !(`${util.getEnv('REBASE')}` == 'false'); | ||
process.env.TZ = TZ; | ||
|
||
core.info(`Branch on ${ref}`); | ||
if (TZ) { | ||
core.info(`TZ on ${process.env.TZ}`); | ||
} else { | ||
core.info('TZ was not set.'); | ||
core.info('TZ will be UTC'); | ||
} | ||
|
||
util.git.addRemote(remote); | ||
|
||
util.git.config({ | ||
'user.name': name, | ||
'user.email': email, | ||
'http.sslVerify': 'false' | ||
}); | ||
|
||
util.git.addAll(); | ||
|
||
const timestamp = Date.now(); | ||
|
||
const message = [ | ||
getEnvRequired('TASK_NAME'), | ||
getEnvRequired('GITHUB_SHA'), | ||
new Date(timestamp), | ||
timestamp | ||
] | ||
.join(' '); | ||
|
||
const diff = util.git.diff(['HEAD']); | ||
if (diff.length) { util.git.commit({ message }); } else { core.info('Nothing to commit'); } | ||
|
||
if (branch != ref) { | ||
util.git.branch({ name: branch, force }); | ||
util.git.branch({ upstream: ref, name: branch, force }); | ||
} | ||
if (pull) { util.git.pull({ rebase }); } | ||
|
||
if (push) { util.git.push({ remote: remote.name, branch, force }); } | ||
} catch (err: any) { | ||
core.setFailed(`Action failed with error ${err}`); | ||
} |