Skip to content

Commit d42d819

Browse files
committed
possible fix
1 parent 8b5a601 commit d42d819

2 files changed

Lines changed: 32 additions & 8 deletions

File tree

‎.github/scripts/monorepo-split-plan.php‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -454,16 +454,17 @@ function publishSplit(array $package, string $sha, ?string $tag, array &$errors)
454454
{
455455
$name = (string) $package['name'];
456456
$repository = (string) $package['repository'];
457+
$publishRepository = publishRepositoryUrl($repository);
457458

458459
if (null !== $tag) {
459-
publishTag($name, $repository, $sha, $tag, $errors);
460+
publishTag($name, $repository, $publishRepository, $sha, $tag, $errors);
460461

461462
return;
462463
}
463464

464465
$branch = (string) $package['branch'];
465466
$refspec = sprintf('%s:refs/heads/%s', $sha, $branch);
466-
$command = sprintf('git push %s %s 2>&1', escapeshellarg($repository), escapeshellarg($refspec));
467+
$command = sprintf('git push %s %s 2>&1', escapeshellarg($publishRepository), escapeshellarg($refspec));
467468
exec($command, $output, $exitCode);
468469
if (0 !== $exitCode) {
469470
$errors[] = sprintf('%s branch publish failed: %s', $name, implode(PHP_EOL, $output));
@@ -474,12 +475,12 @@ function publishSplit(array $package, string $sha, ?string $tag, array &$errors)
474475
fwrite(STDOUT, sprintf(' pushed: %s -> %s:%s', $sha, $repository, $branch) . PHP_EOL);
475476
}
476477

477-
function publishTag(string $name, string $repository, string $sha, string $tag, array &$errors): void
478+
function publishTag(string $name, string $repository, string $publishRepository, string $sha, string $tag, array &$errors): void
478479
{
479480
$remoteTagRef = 'refs/tags/' . $tag;
480481
$lookupCommand = sprintf(
481482
'git ls-remote --tags --refs %s %s 2>&1',
482-
escapeshellarg($repository),
483+
escapeshellarg($publishRepository),
483484
escapeshellarg($remoteTagRef),
484485
);
485486
exec($lookupCommand, $lookupOutput, $lookupExitCode);
@@ -503,7 +504,7 @@ function publishTag(string $name, string $repository, string $sha, string $tag,
503504
}
504505

505506
$refspec = sprintf('%s:%s', $sha, $remoteTagRef);
506-
$pushCommand = sprintf('git push %s %s 2>&1', escapeshellarg($repository), escapeshellarg($refspec));
507+
$pushCommand = sprintf('git push %s %s 2>&1', escapeshellarg($publishRepository), escapeshellarg($refspec));
507508
exec($pushCommand, $pushOutput, $pushExitCode);
508509
if (0 !== $pushExitCode) {
509510
$errors[] = sprintf('%s tag publish failed for %s: %s', $name, $tag, implode(PHP_EOL, $pushOutput));
@@ -514,6 +515,19 @@ function publishTag(string $name, string $repository, string $sha, string $tag,
514515
fwrite(STDOUT, sprintf(' pushed tag: %s -> %s:%s', $sha, $repository, $tag) . PHP_EOL);
515516
}
516517

518+
function publishRepositoryUrl(string $repository): string
519+
{
520+
if (preg_match('#^git@github\.com:([^/]+/[^/]+?)(?:\.git)?$#', $repository, $matches)) {
521+
return 'https://github.com/' . $matches[1] . '.git';
522+
}
523+
524+
if (preg_match('#^ssh://git@github\.com/([^/]+/[^/]+?)(?:\.git)?$#', $repository, $matches)) {
525+
return 'https://github.com/' . $matches[1] . '.git';
526+
}
527+
528+
return $repository;
529+
}
530+
517531
function commandExists(string $command): bool
518532
{
519533
exec(sprintf('command -v %s >/dev/null 2>&1', escapeshellarg($command)), $output, $exitCode);

‎.github/workflows/monorepo-split-plan.yml‎

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,19 @@ jobs:
9292
env:
9393
MONOREPO_SPLIT_TOKEN: ${{ steps.app-token.outputs.token }}
9494
run: |
95-
authenticated_url="https://x-access-token:${MONOREPO_SPLIT_TOKEN}@github.com/"
96-
git config --global "url.${authenticated_url}.insteadOf" "git@github.com:"
97-
git config --global "url.${authenticated_url}.insteadOf" "ssh://git@github.com/"
95+
askpass="$RUNNER_TEMP/monorepo-split-git-askpass.sh"
96+
{
97+
echo '#!/usr/bin/env sh'
98+
echo 'case "$1" in'
99+
echo ' *Username*) printf "%s\n" "x-access-token" ;;'
100+
echo ' *Password*) printf "%s\n" "$MONOREPO_SPLIT_TOKEN" ;;'
101+
echo ' *) printf "\n" ;;'
102+
echo 'esac'
103+
} > "$askpass"
104+
chmod 700 "$askpass"
105+
echo "GIT_ASKPASS=$askpass" >> "$GITHUB_ENV"
106+
echo "GIT_TERMINAL_PROMPT=0" >> "$GITHUB_ENV"
107+
echo "MONOREPO_SPLIT_TOKEN=$MONOREPO_SPLIT_TOKEN" >> "$GITHUB_ENV"
98108
- name: Validate split config
99109
run: php .github/scripts/monorepo-split-plan.php
100110
- name: Plan pull request package splits

0 commit comments

Comments
 (0)