Skip to content

Commit 0dc32af

Browse files
committed
Fix workflow runtime resolution and CLI invocations
1 parent b9702f6 commit 0dc32af

9 files changed

Lines changed: 64 additions & 18 deletions

File tree

.github/actions/changelog/create-dependabot-entry/run.sh

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ git switch -C "${INPUT_HEAD_REF}" "refs/remotes/origin/${INPUT_HEAD_REF}"
99
git config user.name "github-actions[bot]"
1010
git config user.email "41898282+github-actions[bot]@users.noreply.github.com"
1111

12-
if dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
12+
if dev-tools changelog:check --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
1313
{
1414
echo "created=false"
1515
echo "status=already-present"
@@ -19,7 +19,7 @@ if dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="orig
1919
exit 0
2020
fi
2121

22-
dev-tools changelog:entry -- --type=changed --file="${INPUT_CHANGELOG_FILE}" "${entry_message}"
22+
dev-tools changelog:entry --type=changed --file="${INPUT_CHANGELOG_FILE}" "${entry_message}"
2323
git add "${INPUT_CHANGELOG_FILE}"
2424

2525
if git diff --cached --quiet -- "${INPUT_CHANGELOG_FILE}"; then
@@ -35,7 +35,7 @@ fi
3535
git commit -m "Add changelog entry for Dependabot PR #${INPUT_PULL_REQUEST_NUMBER}"
3636
git push origin "HEAD:${INPUT_HEAD_REF}"
3737

38-
if ! dev-tools changelog:check -- --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
38+
if ! dev-tools changelog:check --file="${INPUT_CHANGELOG_FILE}" --against="origin/${INPUT_BASE_REF}" >/dev/null 2>&1; then
3939
{
4040
echo "created=false"
4141
echo "status=missing"

.github/actions/changelog/render-release-notes/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
set -euo pipefail
33

44
mkdir -p "$(dirname "${INPUT_OUTPUT_FILE}")"
5-
dev-tools changelog:show -- "${INPUT_VERSION}" --file="${INPUT_CHANGELOG_FILE}" > "${INPUT_OUTPUT_FILE}"
5+
dev-tools changelog:show "${INPUT_VERSION}" --file="${INPUT_CHANGELOG_FILE}" > "${INPUT_OUTPUT_FILE}"

.github/actions/changelog/resolve-version/run.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ if [ -n "${INPUT_VERSION}" ]; then
55
version="${INPUT_VERSION}"
66
source="input"
77
else
8-
version="$(dev-tools changelog:next-version -- --file="${INPUT_CHANGELOG_FILE}")"
8+
version="$(dev-tools changelog:next-version --file="${INPUT_CHANGELOG_FILE}")"
99
source="inferred"
1010
fi
1111

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

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,25 @@ resolve_dev_tools_workspace_path() {
1212
printf '%s/%s\n' "$(pwd)" "${input_path#./}"
1313
}
1414

15+
workspace_is_dev_tools_repository() {
16+
local workspace_root="${1:?Workspace root is required}"
17+
local composer_json="${workspace_root}/composer.json"
18+
19+
if [ ! -f "${composer_json}" ]; then
20+
return 1
21+
fi
22+
23+
php -r '
24+
$composer = json_decode((string) file_get_contents($argv[1]), true);
25+
26+
if (! is_array($composer)) {
27+
exit(1);
28+
}
29+
30+
exit(($composer["name"] ?? null) === "fast-forward/dev-tools" ? 0 : 1);
31+
' "${composer_json}"
32+
}
33+
1534
resolve_dev_tools_runtime() {
1635
local source_directory_input="${INPUT_DEV_TOOLS_SOURCE_DIRECTORY:-.dev-tools-actions}"
1736

@@ -29,7 +48,7 @@ resolve_dev_tools_runtime() {
2948
return 0
3049
fi
3150

32-
if [ -x "${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ]; then
51+
if [ -x "${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}" ] && [ -f "${DEV_TOOLS_LOCAL_AUTOLOAD}" ] && workspace_is_dev_tools_repository "${DEV_TOOLS_WORKSPACE_ROOT}"; then
3352
DEV_TOOLS_RUNTIME_SOURCE='local'
3453
DEV_TOOLS_RUNTIME_BINARY="${DEV_TOOLS_LOCAL_REPOSITORY_BINARY}"
3554
DEV_TOOLS_RUNTIME_AUTOLOAD="${DEV_TOOLS_LOCAL_AUTOLOAD}"
@@ -43,8 +62,8 @@ resolve_dev_tools_runtime() {
4362
return 1
4463
fi
4564

46-
if [ ! -f "${DEV_TOOLS_SOURCE_DIRECTORY}/composer.json" ]; then
47-
echo "The DevTools workflow source directory does not contain composer.json: ${DEV_TOOLS_SOURCE_DIRECTORY}" >&2
65+
if ! workspace_is_dev_tools_repository "${DEV_TOOLS_SOURCE_DIRECTORY}"; then
66+
echo "The DevTools workflow source directory does not point to the fast-forward/dev-tools package: ${DEV_TOOLS_SOURCE_DIRECTORY}" >&2
4867
echo "Checkout the full php-fast-forward/dev-tools source into ${source_directory_input} before using this action." >&2
4968

5069
return 1

.github/workflows/changelog.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ jobs:
131131
pull-request-title: ${{ env.PULL_REQUEST_TITLE }}
132132

133133
- name: Verify changelog update
134-
run: dev-tools changelog:check -- --file="${CHANGELOG_FILE}" --against="origin/${BASE_REF}"
134+
run: dev-tools changelog:check --file="${CHANGELOG_FILE}" --against="origin/${BASE_REF}"
135135

136136
- uses: ./.dev-tools-actions/.github/actions/summary/write
137137
with:
@@ -217,7 +217,7 @@ jobs:
217217
RELEASE_VERSION: ${{ steps.version.outputs.value }}
218218
run: |
219219
release_date="$(date -u +%F)"
220-
dev-tools changelog:promote -- "${RELEASE_VERSION}" --file="${CHANGELOG_FILE}" --date="${release_date}"
220+
dev-tools changelog:promote "${RELEASE_VERSION}" --file="${CHANGELOG_FILE}" --date="${release_date}"
221221
222222
- name: Render release notes preview
223223
uses: ./.dev-tools-actions/.github/actions/changelog/render-release-notes

.github/workflows/reports.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ jobs:
8989
- name: Generate reports
9090
env:
9191
COMPOSER_ROOT_VERSION: ${{ env.REPORTS_ROOT_VERSION }}
92-
run: dev-tools reports -- --target="${REPORTS_TARGET}" --coverage="${REPORTS_TARGET}/coverage" --metrics="${REPORTS_TARGET}/metrics"
92+
run: dev-tools reports --target="${REPORTS_TARGET}" --coverage="${REPORTS_TARGET}/coverage" --metrics="${REPORTS_TARGET}/metrics"
9393

9494
- name: Fix permissions
9595
run: |

.github/workflows/tests.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ jobs:
116116
- name: Run PHPUnit tests
117117
env:
118118
COMPOSER_ROOT_VERSION: ${{ env.TESTS_ROOT_VERSION }}
119-
run: dev-tools tests -- --coverage=.dev-tools/coverage --min-coverage=${{ steps.minimum-coverage.outputs.value }}
119+
run: dev-tools tests --coverage=.dev-tools/coverage --min-coverage=${{ steps.minimum-coverage.outputs.value }}
120120

121121
- name: Publish required test status
122122
if: ${{ always() && inputs.publish-required-statuses }}
@@ -168,7 +168,7 @@ jobs:
168168
- name: Run dependency health check
169169
env:
170170
COMPOSER_ROOT_VERSION: ${{ env.TESTS_ROOT_VERSION }}
171-
run: dev-tools dependencies -- --max-outdated=${{ inputs.max-outdated || -1 }}
171+
run: dev-tools dependencies --max-outdated=${{ inputs.max-outdated || -1 }}
172172

173173
summarize:
174174
if: ${{ always() }}

.github/workflows/wiki-preview.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ jobs:
7777
- name: Create Docs Markdown
7878
env:
7979
COMPOSER_ROOT_VERSION: dev-${{ github.event.pull_request.head.ref }}
80-
run: dev-tools wiki -- --target=.github/wiki
80+
run: dev-tools wiki --target=.github/wiki
8181

8282
- name: Commit & push wiki preview branch
8383
id: wiki_commit

tests/GitHubActions/SetupComposerActionTest.php

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,7 @@ public function detectRuntimeWillPreferTheConsumerLocalInstallation(): void
109109
#[Test]
110110
public function detectRuntimeWillFallbackToTheWorkflowSourceWhenTheConsumerDoesNotInstallDevTools(): void
111111
{
112-
mkdir($this->workspace . '/.dev-tools-actions', 0o777, true);
113-
file_put_contents($this->workspace . '/.dev-tools-actions/composer.json', "{}\n");
112+
$this->createRepositoryRuntimeFiles($this->workspace . '/.dev-tools-actions');
114113
$resolvedWorkspace = realpath($this->workspace);
115114

116115
$files = $this->createGitHubActionFiles();
@@ -150,6 +149,30 @@ public function detectRuntimeWillPreferTheWorkspaceRootRepositoryCheckout(): voi
150149
self::assertSame($resolvedWorkspace . '/vendor/autoload.php', $outputs['autoload']);
151150
}
152151

152+
/**
153+
* @return void
154+
*/
155+
#[Test]
156+
public function detectRuntimeWillIgnoreAnUnrelatedWorkspaceRepositoryBinary(): void
157+
{
158+
$this->createRepositoryRuntimeFiles($this->workspace, 'example/consumer');
159+
$this->createRepositoryRuntimeFiles($this->workspace . '/.dev-tools-actions');
160+
$resolvedWorkspace = realpath($this->workspace);
161+
162+
$files = $this->createGitHubActionFiles();
163+
164+
$this->runActionScript('detect-dev-tools-runtime.sh', [
165+
'GITHUB_OUTPUT' => $files['output'],
166+
]);
167+
168+
$outputs = $this->parseKeyValueFile($files['output']);
169+
170+
self::assertSame('workflow', $outputs['source']);
171+
self::assertSame('true', $outputs['needs-fallback']);
172+
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/bin/dev-tools', $outputs['binary']);
173+
self::assertSame($resolvedWorkspace . '/.dev-tools-actions/vendor/autoload.php', $outputs['autoload']);
174+
}
175+
153176
/**
154177
* @return void
155178
*/
@@ -209,19 +232,23 @@ private function createInstalledRuntimeFiles(string $runtimeRoot): void
209232
}
210233

211234
/**
235+
* @param string $packageName
212236
* @param string $runtimeRoot
213237
*
214238
* @return void
215239
*/
216-
private function createRepositoryRuntimeFiles(string $runtimeRoot): void
217-
{
240+
private function createRepositoryRuntimeFiles(
241+
string $runtimeRoot,
242+
string $packageName = 'fast-forward/dev-tools'
243+
): void {
218244
mkdir($runtimeRoot . '/bin', 0o777, true);
219245
mkdir($runtimeRoot . '/vendor', 0o777, true);
220246
file_put_contents(
221247
$runtimeRoot . '/bin/dev-tools',
222248
"#!/usr/bin/env bash\nprintf 'dev-tools:%s\\n' \"\$*\"\n",
223249
);
224250
chmod($runtimeRoot . '/bin/dev-tools', 0o755);
251+
file_put_contents($runtimeRoot . '/composer.json', \sprintf("{\n \"name\": \"%s\"\n}\n", $packageName));
225252
file_put_contents($runtimeRoot . '/vendor/autoload.php', "<?php\n");
226253
}
227254

0 commit comments

Comments
 (0)