-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
28 lines (24 loc) · 898 Bytes
/
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
// https://coolaj86.com/articles/vanilla-devops-git-credentials-cheatsheet/
const fs = require('fs')
const path = require('path')
const core = require('@actions/core')
const gitConfigTemplate = `
[url "https://api.github.com/"]
insteadOf = "https://github.com/"
[url "https://[email protected]/"]
insteadOf = "ssh://[email protected]/"
[url "https://[email protected]/"]
insteadOf = "[email protected]:"
`
try {
const authToken = core.getInput('github-auth-token')
const gitConfigPath = path.join(process.env.HOME, '.gitconfig')
fs.writeFileSync(gitConfigPath, gitConfigTemplate)
const askPassPath = `${process.env.HOME}/.git-askpass`
fs.writeFileSync(askPassPath, `echo ${authToken}`)
fs.chmodSync(askPassPath, '0700')
core.exportVariable('GIT_ASKPASS', askPassPath);
console.log(`Wrote ${gitConfigPath} and ${askPassPath}`)
} catch (error) {
core.setFailed(error.message)
}