Skip to content

Commit

Permalink
Testing remote access after overriding remote
Browse files Browse the repository at this point in the history
  • Loading branch information
CatChen committed Oct 1, 2024
1 parent bbbdc96 commit a0e749c
Show file tree
Hide file tree
Showing 6 changed files with 75 additions and 51 deletions.
86 changes: 52 additions & 34 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,22 @@ jobs:
exit 1
fi
GIT_REMOTE_URL=$(git remote get-url origin)
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://github-actions[bot]' ]]
then
echo "::error::Expected git remote url to have login but got '$GIT_REMOTE_URL'"
exit 1
fi
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://github-actions[bot]:'"$TEST_TOKEN" ]]
then
echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
exit 1
fi
# GIT_REMOTE_URL=$(git remote get-url origin)
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://github-actions[bot]' ]]
# then
# echo "::error::Expected git remote url to have login but got '$GIT_REMOTE_URL'"
# exit 1
# fi
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://github-actions[bot]:'"$TEST_TOKEN" ]]
# then
# echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
# exit 1
# fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-user-app-installation-token:
name: Test with User App Installation Token
Expand Down Expand Up @@ -112,17 +115,22 @@ jobs:
exit 1
fi
GIT_REMOTE_URL=$(git remote get-url origin)
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]' ]]
then
echo "::error::Expected git remote url to have login and token but got '$GIT_REMOTE_URL'"
exit 1
fi
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]:'"$TEST_TOKEN" ]]
then
echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
exit 1
fi
# GIT_REMOTE_URL=$(git remote get-url origin)
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]' ]]
# then
# echo "::error::Expected git remote url to have login and token but got '$GIT_REMOTE_URL'"
# exit 1
# fi
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]:'"$TEST_TOKEN" ]]
# then
# echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
# exit 1
# fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-repo-app-installation-token:
name: Test with Repo App Installation Token
Expand Down Expand Up @@ -170,17 +178,22 @@ jobs:
exit 1
fi
GIT_REMOTE_URL=$(git remote get-url origin)
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]' ]]
then
echo "::error::Expected git remote url to have login and token but got '$GIT_REMOTE_URL'"
exit 1
fi
if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]:'"$TEST_TOKEN" ]]
then
echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
exit 1
fi
# GIT_REMOTE_URL=$(git remote get-url origin)
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]' ]]
# then
# echo "::error::Expected git remote url to have login and token but got '$GIT_REMOTE_URL'"
# exit 1
# fi
# if [[ ! "$GIT_REMOTE_URL" =~ ^'https://check-git-status-bot[bot]:'"$TEST_TOKEN" ]]
# then
# echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
# exit 1
# fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
test-with-classic-personal-access-token:
name: Test with Classic Personal Access Token
Expand Down Expand Up @@ -230,3 +243,8 @@ jobs:
echo "::error::Expected git remote url to have token but got '$GIT_REMOTE_URL'"
exit 1
fi
- name: Verify remote access
run: |
git ls-remote origin
gh repo view
3 changes: 2 additions & 1 deletion bundle/configGit.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 9 additions & 5 deletions bundle/index.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion bundle/index.js.map

Large diffs are not rendered by default.

19 changes: 10 additions & 9 deletions src/configGit.ts
Original file line number Diff line number Diff line change
@@ -1,26 +1,27 @@
import { group } from '@actions/core';
import { getExecOutput } from '@actions/exec';
import { Actor } from 'token-who-am-i-action';

export async function configGit(
githubToken: string,
username: string,
name?: string,
email?: string,
): Promise<void> {
export async function configGit(githubToken: string, me: Actor): Promise<void> {
await group('Configure git', async () => {
await getExecOutput('git', ['config', '--list']);
await getExecOutput('git', [
'config',
'--global',
'user.email',
email ?? '',
me.email ?? '',
]);
await getExecOutput('git', [
'config',
'--global',
'user.name',
name ?? username,
me.name ?? me.login,
]);

if (me.type === 'Bot') {
return;
}

const remoteOutput = await getExecOutput('git', [
'remote',
'get-url',
Expand All @@ -29,7 +30,7 @@ export async function configGit(
const originUrl = remoteOutput.stdout.trim();
const originUrlWithToken = originUrl.replace(
/^https:\/\//,
`https://${username}:${githubToken}@`,
`https://${me.login}:${githubToken}@`,
);
await getExecOutput('git', [
'remote',
Expand Down
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export async function configGitWithToken(githubToken: string): Promise<void> {

await configGh(githubToken);

await configGit(githubToken, me.login, me.name, me.email);
await configGit(githubToken, me);
}

async function run(): Promise<void> {
Expand Down

0 comments on commit a0e749c

Please sign in to comment.