Add GitHub Enterprise support (#108)
* * Add GitHub url and GitHub Enterprise support * Update the GitHub action * Update build.yml Remove push command * Update the PR and remove the test mode * Delete build-pr.yml * Update README.md
This commit is contained in:
parent
887c31bd83
commit
694e694af3
4
.github/workflows/build.yml
vendored
4
.github/workflows/build.yml
vendored
@ -1,10 +1,6 @@
|
||||
name: Action CI
|
||||
|
||||
on:
|
||||
pull_request_target:
|
||||
types:
|
||||
- opened
|
||||
branches: [master, main]
|
||||
push:
|
||||
branches: [master, main]
|
||||
|
||||
|
@ -9,6 +9,10 @@ inputs:
|
||||
description: 'GitHub token or PAT token'
|
||||
required: true
|
||||
default: ${{ github.token }}
|
||||
github_url:
|
||||
description: 'GitHub url or GitHub Enterprise url'
|
||||
required: true
|
||||
default: ${{ github.server_url }}
|
||||
repository:
|
||||
description: 'Repository name to push. Default or empty value represents current github repository (${GITHUB_REPOSITORY})'
|
||||
default: ''
|
||||
|
6
start.js
6
start.js
@ -42,12 +42,14 @@ const trim = (value, charlist) => trimLeft(trimRight(value, charlist));
|
||||
const main = async () => {
|
||||
let branch = process.env.INPUT_BRANCH;
|
||||
const repository = trim(process.env.INPUT_REPOSITORY || process.env.GITHUB_REPOSITORY);
|
||||
const github_url_protocol = trim(process.env.INPUT_GITHUB_URL).split("//")[0];
|
||||
const github_url = trim(process.env.INPUT_GITHUB_URL).split("//")[1];
|
||||
if (!branch) {
|
||||
const headers = {
|
||||
'User-Agent': 'github.com/ad-m/github-push-action'
|
||||
};
|
||||
if (process.env.INPUT_GITHUB_TOKEN) headers.Authorization = `token ${process.env.INPUT_GITHUB_TOKEN}`;
|
||||
const body = JSON.parse(await get(`https://api.github.com/repos/${repository}`, { headers }))
|
||||
const body = JSON.parse(await get(`${process.env.GITHUB_API_URL}/repos/${repository}`, { headers }))
|
||||
branch = body.default_branch;
|
||||
}
|
||||
await exec('bash', [path.join(__dirname, './start.sh')], {
|
||||
@ -55,6 +57,8 @@ const main = async () => {
|
||||
...process.env,
|
||||
INPUT_BRANCH: branch,
|
||||
INPUT_REPOSITORY: repository,
|
||||
INPUT_GITHUB_URL_PROTOCOL: github_url_protocol,
|
||||
INPUT_GITHUB_URL: github_url,
|
||||
}
|
||||
});
|
||||
};
|
||||
|
3
start.sh
3
start.sh
@ -23,8 +23,7 @@ fi
|
||||
|
||||
cd ${INPUT_DIRECTORY}
|
||||
|
||||
remote_repo="https://${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@github.com/${REPOSITORY}.git"
|
||||
|
||||
remote_repo="${INPUT_GITHUB_URL_PROTOCOL}//${GITHUB_ACTOR}:${INPUT_GITHUB_TOKEN}@${INPUT_GITHUB_URL}/${REPOSITORY}.git"
|
||||
git config --local --add safe.directory ${INPUT_DIRECTORY}
|
||||
|
||||
git push "${remote_repo}" HEAD:${INPUT_BRANCH} --follow-tags $_FORCE_OPTION $_TAGS;
|
||||
|
Loading…
x
Reference in New Issue
Block a user