From b12c4c5a8c273208bc785d20bf0891064119f185 Mon Sep 17 00:00:00 2001 From: Robin Date: Thu, 28 Oct 2021 16:59:16 +0200 Subject: [PATCH] add private github package support using pat --- CONTRIBUTING.md | 2 +- action.yml | 5 +++++ action/entrypoint.sh | 1 + action/steps/set_gitcredential.sh | 23 +++++++++++++++++++++++ src/model/docker.js | 2 ++ src/model/input.js | 2 ++ 6 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 action/steps/set_gitcredential.sh diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index b42be7e..b16c62e 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -19,7 +19,7 @@ When fixing a bug it is fine to submit a pull request right away. Steps to be performed to submit a pull request: -1. Fork the repository and create your branch from `master`. +1. Fork the repository and create your branch from `main`. 2. Run `yarn` in the repository root. 3. If you've fixed a bug or added code that should be tested, add tests! 4. Fill out the description, link any related issues and submit your pull request. diff --git a/action.yml b/action.yml index 99e17af..453615f 100644 --- a/action.yml +++ b/action.yml @@ -32,6 +32,11 @@ inputs: required: false default: '' description: 'SSH Agent path to forward to the container' + gitPrivateToken: + required: false + default: '' + description: > + Github private token to pull from github githubToken: required: false default: '' diff --git a/action/entrypoint.sh b/action/entrypoint.sh index 1a71e9f..7eafc8e 100644 --- a/action/entrypoint.sh +++ b/action/entrypoint.sh @@ -14,6 +14,7 @@ mkdir -p "$ACTIVATE_LICENSE_PATH" source /steps/activate.sh source /steps/run_tests.sh source /steps/return_license.sh +source /steps/set_gitcredential.sh # # Remove license activation directory diff --git a/action/steps/set_gitcredential.sh b/action/steps/set_gitcredential.sh new file mode 100644 index 0000000..ab25663 --- /dev/null +++ b/action/steps/set_gitcredential.sh @@ -0,0 +1,23 @@ +#!/usr/bin/env bash + +if [ -z "${GIT_PRIVATE_TOKEN}" ] +then + echo "GIT_PRIVATE_TOKEN unset skipping" +else + echo "GIT_PRIVATE_TOKEN is set configuring git credentials" + + git config --global credential.helper store + git config --global --replace-all url.https://github.com/.insteadOf ssh://git@github.com/ + git config --global --add url.https://github.com/.insteadOf git@github.com + + git config --global url."https://token:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "https://github.com/" + git config --global url."https://ssh:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "ssh://git@github.com/" + git config --global url."https://git:$GIT_PRIVATE_TOKEN@github.com/".insteadOf "git@github.com:" + +fi + +echo "---------- git config --list -------------" +git config --list + +echo "---------- git config --list --show-origin -------------" +git config --list --show-origin diff --git a/src/model/docker.js b/src/model/docker.js index 5621b57..06bc078 100644 --- a/src/model/docker.js +++ b/src/model/docker.js @@ -28,6 +28,7 @@ class Docker { customParameters, sshAgent, githubToken, + gitPrivateToken, } = parameters; const command = `docker run \ @@ -58,6 +59,7 @@ class Docker { --env RUNNER_TOOL_CACHE \ --env RUNNER_TEMP \ --env RUNNER_WORKSPACE \ + --env GIT_PRIVATE_TOKEN="${gitPrivateToken}" \ ${sshAgent ? '--env SSH_AUTH_SOCK=/ssh-agent' : ''} \ --volume "/var/run/docker.sock":"/var/run/docker.sock" \ --volume "/home/runner/work/_temp/_github_home":"/root" \ diff --git a/src/model/input.js b/src/model/input.js index 7e88809..a975e23 100644 --- a/src/model/input.js +++ b/src/model/input.js @@ -25,6 +25,7 @@ class Input { const sshAgent = getInput('sshAgent') || ''; const githubToken = getInput('githubToken') || ''; const checkName = getInput('checkName') || 'Test Results'; + const gitPrivateToken = getInput('gitPrivateToken') || ''; // Validate input if (!includes(this.testModes, testMode)) { @@ -62,6 +63,7 @@ class Input { sshAgent, githubToken, checkName, + gitPrivateToken, }; } }