diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 23270e4..89b166a 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -1,10 +1,6 @@ name: Action CI on: - pull_request_target: - types: - - opened - branches: [master, main] push: branches: [master, main] diff --git a/action.yml b/action.yml index 7470474..d382fad 100644 --- a/action.yml +++ b/action.yml @@ -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: '' diff --git a/start.js b/start.js index f47677c..dc54931 100644 --- a/start.js +++ b/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, } }); }; diff --git a/start.sh b/start.sh index 375f837..5faf53a 100755 --- a/start.sh +++ b/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;