Skip to content

Commit

Permalink
Add GitHub Enterprise support (#108)
Browse files Browse the repository at this point in the history
* * 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
  • Loading branch information
ZPascal authored May 3, 2022
1 parent 887c31b commit 694e694
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
name: Action CI

on:
pull_request_target:
types:
- opened
branches: [master, main]
push:
branches: [master, main]

Expand Down
4 changes: 4 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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: ''
Expand Down
6 changes: 5 additions & 1 deletion start.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,19 +42,23 @@ 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')], {
env: {
...process.env,
INPUT_BRANCH: branch,
INPUT_REPOSITORY: repository,
INPUT_GITHUB_URL_PROTOCOL: github_url_protocol,
INPUT_GITHUB_URL: github_url,
}
});
};
Expand Down
3 changes: 1 addition & 2 deletions start.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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;

0 comments on commit 694e694

Please sign in to comment.