Skip to content

Commit b9702f6

Browse files
committed
Fix workflow runtime resolution for repository checkouts
1 parent 5528e56 commit b9702f6

2 files changed

Lines changed: 63 additions & 14 deletions

File tree

.github/actions/php/setup-composer/dev-tools-runtime-lib.sh

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,21 @@ resolve_dev_tools_runtime() {
1717

1818
DEV_TOOLS_WORKSPACE_ROOT="$(pwd)"
1919
DEV_TOOLS_SOURCE_DIRECTORY="$(resolve_dev_tools_workspace_path "${source_directory_input}")"
20-
DEV_TOOLS_LOCAL_BINARY="${DEV_TOOLS_WORKSPACE_ROOT}/vendor/bin/dev-tools"
2120
DEV_TOOLS_LOCAL_AUTOLOAD="${DEV_TOOLS_WORKSPACE_ROOT}/vendor/autoload.php"
21+
DEV_TOOLS_LOCAL_INSTALLED_BINARY="${DEV_TOOLS_WORKSPACE_ROOT}/vendor/bin/dev-tools"
22+
DEV_TOOLS_LOCAL_REPOSITORY_BINARY="${DEV_TOOLS_WORKSPACE_ROOT}/bin/dev-tools"
2223

23-
if [ -x "${DEV_TOOLS_LOCAL_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ]; then
24+
if [ -x "${DEV_TOOLS_LOCAL_INSTALLED_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ]; then
2425
DEV_TOOLS_RUNTIME_SOURCE='local'
25-
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_BINARY}"
26+
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_INSTALLED_BINARY}"
27+
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_LOCAL_AUTOLOAD}"
28+
29+
return 0
30+
fi
31+
32+
if [ -x "${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ]; then
33+
DEV_TOOLS_RUNTIME_SOURCE='local'
34+
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}"
2635
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_LOCAL_AUTOLOAD}"
2736

2837
return 0
@@ -42,7 +51,7 @@ resolve_dev_tools_runtime() {
4251
fi
4352

4453
DEV_TOOLS_RUNTIME_SOURCE='workflow'
45-
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_SOURCE_DIRECTORY}/vendor/bin/dev-tools"
54+
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_SOURCE_DIRECTORY}/bin/dev-tools"
4655
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_SOURCE_DIRECTORY}/vendor/autoload.php"
4756
}
4857

tests/GitHubActions/SetupComposerActionTest.php

Lines changed: 50 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ protected function tearDown(): void
8686
#[Test]
8787
public function detectRuntimeWillPreferTheConsumerLocalInstallation(): void
8888
{
89-
$this->createRuntimeFiles($this->workspace . '/vendor');
89+
$this->createInstalledRuntimeFiles($this->workspace);
9090
$resolvedWorkspace = realpath($this->workspace);
9191

9292
$files = $this->createGitHubActionFiles();
@@ -123,10 +123,33 @@ public function detectRuntimeWillFallbackToTheWorkflowSourceWhenTheConsumerDoesN
123123

124124
self::assertSame('workflow', $outputs['source']);
125125
self::assertSame('true', $outputs['needs-fallback']);
126-
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/vendor/bin/dev-tools', $outputs['binary']);
126+
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/bin/dev-tools', $outputs['binary']);
127127
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/vendor/autoload.php', $outputs['autoload']);
128128
}
129129

130+
/**
131+
* @return void
132+
*/
133+
#[Test]
134+
public function detectRuntimeWillPreferTheWorkspaceRootRepositoryCheckout(): void
135+
{
136+
$this->createRepositoryRuntimeFiles($this->workspace);
137+
$resolvedWorkspace = realpath($this->workspace);
138+
139+
$files = $this->createGitHubActionFiles();
140+
141+
$this->runActionScript('detect-dev-tools-runtime.sh', [
142+
'GITHUB_OUTPUT' => $files['output'],
143+
]);
144+
145+
$outputs = $this->parseKeyValueFile($files['output']);
146+
147+
self::assertSame('local', $outputs['source']);
148+
self::assertSame('false', $outputs['needs-fallback']);
149+
self::assertSame($resolvedWorkspace . '/bin/dev-tools', $outputs['binary']);
150+
self::assertSame($resolvedWorkspace . '/vendor/autoload.php', $outputs['autoload']);
151+
}
152+
130153
/**
131154
* @return void
132155
*/
@@ -135,7 +158,7 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
135158
{
136159
mkdir($this->workspace . '/.dev-tools-actions', 0o777, true);
137160
file_put_contents($this->workspace . '/.dev-tools-actions/composer.json', "{}\n");
138-
$this->createRuntimeFiles($this->workspace . '/.dev-tools-actions/vendor');
161+
$this->createRepositoryRuntimeFiles($this->workspace . '/.dev-tools-actions');
139162
$resolvedWorkspace = realpath($this->workspace);
140163

141164
$files = $this->createGitHubActionFiles();
@@ -154,7 +177,7 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
154177
$pathEntries = array_filter(explode("\n", trim(file_get_contents($files['path']))));
155178

156179
self::assertSame('workflow', $outputs['source']);
157-
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/vendor/bin/dev-tools', $outputs['binary']);
180+
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/bin/dev-tools', $outputs['binary']);
158181
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/vendor/autoload.php', $outputs['autoload']);
159182
self::assertSame($outputs['binary'], $environment['DEV_TOOLS_BINARY']);
160183
self::assertSame($outputs['autoload'], $environment['DEV_TOOLS_AUTOLOAD']);
@@ -170,19 +193,36 @@ public function exposeRuntimeWillPublishWrapperAndEnvironmentVariablesForTheWork
170193
}
171194

172195
/**
173-
* @param string $runtimeVendorDirectory
196+
* @param string $runtimeRoot
197+
*
198+
* @return void
199+
*/
200+
private function createInstalledRuntimeFiles(string $runtimeRoot): void
201+
{
202+
mkdir($runtimeRoot . '/vendor/bin', 0o777, true);
203+
file_put_contents(
204+
$runtimeRoot . '/vendor/bin/dev-tools',
205+
"#!/usr/bin/env bash\nprintf 'dev-tools:%s\\n' \"\$*\"\n",
206+
);
207+
chmod($runtimeRoot . '/vendor/bin/dev-tools', 0o755);
208+
file_put_contents($runtimeRoot . '/vendor/autoload.php', "<?php\n");
209+
}
210+
211+
/**
212+
* @param string $runtimeRoot
174213
*
175214
* @return void
176215
*/
177-
private function createRuntimeFiles(string $runtimeVendorDirectory): void
216+
private function createRepositoryRuntimeFiles(string $runtimeRoot): void
178217
{
179-
mkdir($runtimeVendorDirectory . '/bin', 0o777, true);
218+
mkdir($runtimeRoot . '/bin', 0o777, true);
219+
mkdir($runtimeRoot . '/vendor', 0o777, true);
180220
file_put_contents(
181-
$runtimeVendorDirectory . '/bin/dev-tools',
221+
$runtimeRoot . '/bin/dev-tools',
182222
"#!/usr/bin/env bash\nprintf 'dev-tools:%s\\n' \"\$*\"\n",
183223
);
184-
chmod($runtimeVendorDirectory . '/bin/dev-tools', 0o755);
185-
file_put_contents($runtimeVendorDirectory . '/autoload.php', "<?php\n");
224+
chmod($runtimeRoot . '/bin/dev-tools', 0o755);
225+
file_put_contents($runtimeRoot . '/vendor/autoload.php', "<?php\n");
186226
}
187227

188228
/**

0 commit comments

Comments
 (0)