From 648230c9e87d4d8c43682f505179915cc5b5910d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Jul 2024 18:31:51 +0000 Subject: [PATCH 1/5] Support wildcard branches --- src/VCS/Adapter/Git/GitHub.php | 6 ++++-- tests/VCS/Adapter/GitHubTest.php | 22 ++++++++++++++++++++++ 2 files changed, 26 insertions(+), 2 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index cbcf769..9925bf4 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -542,8 +542,10 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri $commands[] = "git pull origin {$commitHash}"; break; case self::CLONE_TYPE_TAG: - $tagName = escapeshellarg($version); - $commands[] = "git pull origin {$tagName}"; + $version = \implode('[0-9]*', \explode('*', $version)); + $version = \implode('\\.', \explode('.', $version)); + $tagRegex = escapeshellarg($version); + $commands[] = "git pull origin $(git describe --tags --match={$tagRegex} --abbrev=0 HEAD)"; break; } diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index cd0b8c4..a588c4e 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -275,6 +275,28 @@ public function testGenerateCloneCommandWithTag(): void $this->assertEquals(0, $resultCode); $this->assertFileExists('/tmp/clone-tag/README.md'); + + $gitCloneCommand = $this->vcsAdapter->generateCloneCommand('test-kh', 'test2', '0.1.*', GitHub::CLONE_TYPE_TAG, '/tmp/clone-tag2', '*'); + $this->assertNotEmpty($gitCloneCommand); + $this->assertStringContainsString('sparse-checkout', $gitCloneCommand); + + $output = ''; + $resultCode = null; + \exec($gitCloneCommand, $output, $resultCode); + $this->assertEquals(0, $resultCode); + + $this->assertFileExists('/tmp/clone-tag2/README.md'); + + $gitCloneCommand = $this->vcsAdapter->generateCloneCommand('test-kh', 'test2', '0.*.*', GitHub::CLONE_TYPE_TAG, '/tmp/clone-tag3', '*'); + $this->assertNotEmpty($gitCloneCommand); + $this->assertStringContainsString('sparse-checkout', $gitCloneCommand); + + $output = ''; + $resultCode = null; + \exec($gitCloneCommand, $output, $resultCode); + $this->assertEquals(0, $resultCode); + + $this->assertFileExists('/tmp/clone-tag3/README.md'); } public function testUpdateComment(): void From a221e7bd0caa4f3967e8e517c9768f490af646d6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Jul 2024 18:35:46 +0000 Subject: [PATCH 2/5] Debug logs --- tests/VCS/Adapter/GitHubTest.php | 1 + 1 file changed, 1 insertion(+) diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index a588c4e..035675a 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -267,6 +267,7 @@ public function testGenerateCloneCommandWithTag(): void { $gitCloneCommand = $this->vcsAdapter->generateCloneCommand('test-kh', 'test2', '0.1.0', GitHub::CLONE_TYPE_TAG, '/tmp/clone-tag', '*'); $this->assertNotEmpty($gitCloneCommand); + \var_dump($gitCloneCommand); $this->assertStringContainsString('sparse-checkout', $gitCloneCommand); $output = ''; From 85c210c985cffef06da6798e109b47e409a89747 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Jul 2024 18:45:35 +0000 Subject: [PATCH 3/5] Fix failing tag search --- src/VCS/Adapter/Git/GitHub.php | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/src/VCS/Adapter/Git/GitHub.php b/src/VCS/Adapter/Git/GitHub.php index 9925bf4..0b3efab 100644 --- a/src/VCS/Adapter/Git/GitHub.php +++ b/src/VCS/Adapter/Git/GitHub.php @@ -542,10 +542,8 @@ public function generateCloneCommand(string $owner, string $repositoryName, stri $commands[] = "git pull origin {$commitHash}"; break; case self::CLONE_TYPE_TAG: - $version = \implode('[0-9]*', \explode('*', $version)); - $version = \implode('\\.', \explode('.', $version)); - $tagRegex = escapeshellarg($version); - $commands[] = "git pull origin $(git describe --tags --match={$tagRegex} --abbrev=0 HEAD)"; + $tagName = escapeshellarg($version); + $commands[] = "git pull origin $(git ls-remote --tags origin {$tagName} | tail -n 1 | awk -F '/' '{print $3}')"; break; } From 5e097b42068e9d37fa24b4b55554bc433b78ef57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Jul 2024 18:48:13 +0000 Subject: [PATCH 4/5] Failure test assertion --- tests/VCS/Adapter/GitHubTest.php | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index 035675a..6f48ffe 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -243,7 +243,6 @@ public function testGenerateCloneCommand(): void $output = ''; $resultCode = null; \exec($gitCloneCommand, $output, $resultCode); - \var_dump($output); $this->assertEquals(0, $resultCode); $this->assertFileExists('/tmp/clone-branch/README.md'); @@ -267,7 +266,6 @@ public function testGenerateCloneCommandWithTag(): void { $gitCloneCommand = $this->vcsAdapter->generateCloneCommand('test-kh', 'test2', '0.1.0', GitHub::CLONE_TYPE_TAG, '/tmp/clone-tag', '*'); $this->assertNotEmpty($gitCloneCommand); - \var_dump($gitCloneCommand); $this->assertStringContainsString('sparse-checkout', $gitCloneCommand); $output = ''; @@ -298,6 +296,18 @@ public function testGenerateCloneCommandWithTag(): void $this->assertEquals(0, $resultCode); $this->assertFileExists('/tmp/clone-tag3/README.md'); + + + $gitCloneCommand = $this->vcsAdapter->generateCloneCommand('test-kh', 'test2', '0.2.*', GitHub::CLONE_TYPE_TAG, '/tmp/clone-tag4', '*'); + $this->assertNotEmpty($gitCloneCommand); + $this->assertStringContainsString('sparse-checkout', $gitCloneCommand); + + $output = ''; + $resultCode = null; + \exec($gitCloneCommand, $output, $resultCode); + $this->assertEquals(0, $resultCode); + + $this->assertFileDoesNotExist('/tmp/clone-tag4/README.md'); } public function testUpdateComment(): void From 5bffa504a48b2269af9ad15c85f653ab7bf1b2d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Matej=20Ba=C4=8Do?= Date: Mon, 29 Jul 2024 18:50:34 +0000 Subject: [PATCH 5/5] Fix failure assertion --- tests/VCS/Adapter/GitHubTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/VCS/Adapter/GitHubTest.php b/tests/VCS/Adapter/GitHubTest.php index 6f48ffe..9e8b4c9 100644 --- a/tests/VCS/Adapter/GitHubTest.php +++ b/tests/VCS/Adapter/GitHubTest.php @@ -305,7 +305,7 @@ public function testGenerateCloneCommandWithTag(): void $output = ''; $resultCode = null; \exec($gitCloneCommand, $output, $resultCode); - $this->assertEquals(0, $resultCode); + $this->assertNotEquals(0, $resultCode); $this->assertFileDoesNotExist('/tmp/clone-tag4/README.md'); }