From 9cf4330f60d59444bb9f9071ae03dfef58763029 Mon Sep 17 00:00:00 2001 From: Adam Ormsby Date: Sun, 13 Jun 2021 21:17:02 -0500 Subject: [PATCH] =?UTF-8?q?Add=20tests=20for=20private=20repo=20access=20w?= =?UTF-8?q?ith=20token=20=E2=80=A6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Created 2 entry points for running either the action or the tests - Added test for proving token access to a private repo - Added some default test data --- .gitignore | 3 +++ .vscode/settings.json | 19 +++++++++++++++++++ entry/run_action.sh | 19 +++++++++++++++++++ entry/run_tests.sh | 9 +++++++++ fork-sync.code-workspace | 26 ++++++++++++++++++++++++++ run/token_access.sh | 23 +++++++++++++++++++++++ 6 files changed, 99 insertions(+) create mode 100644 .vscode/settings.json create mode 100755 entry/run_action.sh create mode 100755 entry/run_tests.sh create mode 100644 fork-sync.code-workspace create mode 100755 run/token_access.sh diff --git a/.gitignore b/.gitignore index df7ebda..5576b00 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,6 @@ +# custom +test_key.txt + # Logs logs *.log diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..a8c1b5c --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,19 @@ +{ + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#2f7c47", + "activityBar.activeBorder": "#422c74", + "activityBar.background": "#2f7c47", + "activityBar.foreground": "#e7e7e7", + "activityBar.inactiveForeground": "#e7e7e799", + "activityBarBadge.background": "#422c74", + "activityBarBadge.foreground": "#e7e7e7", + "statusBar.background": "#215732", + "statusBar.foreground": "#e7e7e7", + "statusBarItem.hoverBackground": "#2f7c47", + "titleBar.activeBackground": "#215732", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveBackground": "#21573299", + "titleBar.inactiveForeground": "#e7e7e799" + }, + "peacock.color": "#215732" +} \ No newline at end of file diff --git a/entry/run_action.sh b/entry/run_action.sh new file mode 100755 index 0000000..4ddb5e5 --- /dev/null +++ b/entry/run_action.sh @@ -0,0 +1,19 @@ +#!/bin/sh + +# TODO: SPIKE on running 'live' tests through the action runner + +# TODO: update local mode vars to be a good functional example +# Set custom vars for LOCAL MODE run of action +if [ -z "${GITHUB_ACTIONS}" ] || [ "${GITHUB_ACTIONS}" = false ]; then + echo "Running action in LOCAL MODE..." + INPUT_GITHUB_TOKEN="$(cat ../test_key.txt)" +fi + +: ' +TODO: determine how to actually run this locally: + - place project inside the target repo? + - add var for path to repo? + - perform target repo checkout inside this project to perform actions? +' + +# . ../run/token_access.sh diff --git a/entry/run_tests.sh b/entry/run_tests.sh new file mode 100755 index 0000000..a06e332 --- /dev/null +++ b/entry/run_tests.sh @@ -0,0 +1,9 @@ +#!/bin/sh + +SUCCESS_TEST_REPO="aoAppDev/action-test-access-repo.git" +TEST_ACCESS_TOKEN=$(cat ../test_key.txt) + +FAIL_TEST_REPO="aoAppDev/action-test-access-fail-case.git" + +echo "Running action in TEST MODE..." +. ../run/token_access.sh && run_tests diff --git a/fork-sync.code-workspace b/fork-sync.code-workspace new file mode 100644 index 0000000..3517103 --- /dev/null +++ b/fork-sync.code-workspace @@ -0,0 +1,26 @@ +{ + "folders": [ + { + "path": "." + } + ], + "settings": { + "workbench.colorCustomizations": { + "activityBar.activeBackground": "#2f7c47", + "activityBar.activeBorder": "#422c74", + "activityBar.background": "#2f7c47", + "activityBar.foreground": "#e7e7e7", + "activityBar.inactiveForeground": "#e7e7e799", + "activityBarBadge.background": "#422c74", + "activityBarBadge.foreground": "#e7e7e7", + "statusBar.background": "#215732", + "statusBar.foreground": "#e7e7e7", + "statusBarItem.hoverBackground": "#2f7c47", + "titleBar.activeBackground": "#215732", + "titleBar.activeForeground": "#e7e7e7", + "titleBar.inactiveBackground": "#21573299", + "titleBar.inactiveForeground": "#e7e7e799" + }, + "peacock.color": "#215732" + } +} \ No newline at end of file diff --git a/run/token_access.sh b/run/token_access.sh new file mode 100755 index 0000000..7c606e5 --- /dev/null +++ b/run/token_access.sh @@ -0,0 +1,23 @@ +#!/bin/sh + +# TODO: rename file based on action/purpose +# TODO: extract user-adjustable vars into superscript for test runs + + +# TODO:improve console output +# Run with local test values - adjustable in `entry/run_tests.sh` +run_tests() { + echo "Token access test 1 -> Try to clone private repo with no access token / git clone should fail" + (git clone https://github.com/${FAIL_TEST_REPO} && \ + # (git clone https://github.com/aoAppDev/action-test-access-fail-case.git && \ + echo "Test 1 FAIL - git clone should failed") || \ + echo "Test 1 PASSED - git clone failed as expected" + + echo "Token access test 2 -> Try to clone private repo with access token / git clone should succeed" + (git clone https://${TEST_ACCESS_TOKEN}@github.com/${SUCCESS_TEST_REPO} && \ + # (git clone https://${INPUT_GITHUB_TOKEN}@github.com/aoAppDev/action-test-access-repo.git && \ + echo "Test 2 PASSED - git clone succeeded as expected") || \ + echo "Test 2 FAILED - git clone should have succeeded" + + # TODO: clean up cloned repo (now? or after later tests?) +}