Skip to content

Commit 58e11bb

Browse files
warengonzagadependabot[bot]Copilotdevin-ai-integration[bot]
authored
🔧update: actions/checkout to v6.0.3 and resolve package paths (#38)
* ☕ chore: Bump actions/checkout from 6.0.2 to 6.0.3 (#35) Bumps [actions/checkout](https://github.com/actions/checkout) from 6.0.2 to 6.0.3. - [Release notes](https://github.com/actions/checkout/releases) - [Changelog](https://github.com/actions/checkout/blob/main/CHANGELOG.md) - [Commits](actions/checkout@v6.0.2...v6.0.3) --- updated-dependencies: - dependency-name: actions/checkout dependency-version: 6.0.3 dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> * 🔧 update: resolve package paths from workflow workspace in composite action (#37) * Initial plan * fix: resolve package paths from workflow workspace * fix: trim package paths safely * fix: trigger checkout-required for absolute paths under GITHUB_WORKSPACE and add CI assertion * 🔧 update: align auto-checkout to actions/checkout@v6.0.3 to match CI --------- Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com> * Normalize resolved package paths before checkout detection --------- Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com> Co-authored-by: devin-ai-integration[bot] <158243242+devin-ai-integration[bot]@users.noreply.github.com>
1 parent b794ec3 commit 58e11bb

5 files changed

Lines changed: 215 additions & 18 deletions

File tree

.github/workflows/ci.yml

Lines changed: 83 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ jobs:
1818

1919
steps:
2020
- name: Checkout code
21-
uses: actions/checkout@v6.0.2
21+
uses: actions/checkout@v6.0.3
2222

2323
- name: Assert bot detection script behavior
2424
shell: bash
@@ -52,13 +52,92 @@ jobs:
5252
run_case "warengonzaga" "true" "false" ""
5353
run_case "dependabot[bot]" "false" "false" ""
5454
55+
package-path-resolution:
56+
name: Package Path Resolution
57+
runs-on: ubuntu-latest
58+
59+
steps:
60+
- name: Checkout code
61+
uses: actions/checkout@v6.0.3
62+
63+
- name: Setup Node.js
64+
uses: actions/setup-node@v4
65+
with:
66+
node-version: '20'
67+
68+
- name: Prepare local action copy and consumer fixture
69+
shell: bash
70+
run: |
71+
set -euo pipefail
72+
73+
mkdir -p local-action
74+
rsync -a --exclude '.git' --exclude 'local-action' ./ ./local-action/
75+
76+
cat > package.json <<'EOF'
77+
{
78+
"name": "@wgtechlabs/path-resolution-fixture",
79+
"version": "0.1.0",
80+
"scripts": {
81+
"build": "echo path-resolution-build",
82+
"test": "echo path-resolution-test"
83+
}
84+
}
85+
EOF
86+
87+
- name: Run action from nested action path
88+
id: nested-action
89+
uses: ./local-action
90+
with:
91+
package-manager: npm
92+
registry: github
93+
github-token: ${{ github.token }}
94+
publish-enabled: 'false'
95+
audit-enabled: 'false'
96+
pr-comment-enabled: 'false'
97+
98+
- name: Assert checkout-required resolver detection
99+
shell: bash
100+
run: |
101+
set -euo pipefail
102+
103+
run_resolver() {
104+
local pkg_path="$1"
105+
local pkg_paths="${2:-}"
106+
local out
107+
out=$(mktemp)
108+
PACKAGE_PATH="$pkg_path" PACKAGE_PATHS="$pkg_paths" \
109+
GITHUB_WORKSPACE="$GITHUB_WORKSPACE" GITHUB_OUTPUT="$out" \
110+
bash ./scripts/resolve-package-paths.sh > /dev/null
111+
grep '^checkout-required=' "$out" | cut -d= -f2
112+
rm -f "$out"
113+
}
114+
115+
# relative path to missing file → checkout required
116+
test "$(run_resolver "./nonexistent-package.json")" = "true"
117+
118+
# absolute path under GITHUB_WORKSPACE to missing file → checkout required
119+
test "$(run_resolver "$GITHUB_WORKSPACE/nonexistent-package.json")" = "true"
120+
121+
# absolute path outside GITHUB_WORKSPACE → checkout not required
122+
test "$(run_resolver "/tmp/nonexistent-package.json")" = "false"
123+
124+
# existing file (relative) → checkout not required
125+
test "$(run_resolver "./package.json")" = "false"
126+
127+
- name: Assert nested action outputs
128+
shell: bash
129+
run: |
130+
test "${{ steps.nested-action.outputs.build-skipped }}" = "false"
131+
test -n "${{ steps.nested-action.outputs.package-version }}"
132+
test "${{ steps.nested-action.outputs.github-published }}" = "false"
133+
55134
single-package-bun:
56135
name: Single Package Bun
57136
runs-on: ubuntu-latest
58137

59138
steps:
60139
- name: Checkout code
61-
uses: actions/checkout@v6.0.2
140+
uses: actions/checkout@v6.0.3
62141
with:
63142
fetch-depth: 0
64143

@@ -132,7 +211,7 @@ jobs:
132211

133212
steps:
134213
- name: Checkout code
135-
uses: actions/checkout@v6.0.2
214+
uses: actions/checkout@v6.0.3
136215
with:
137216
fetch-depth: 0
138217

@@ -204,7 +283,7 @@ jobs:
204283

205284
steps:
206285
- name: Checkout code
207-
uses: actions/checkout@v6.0.2
286+
uses: actions/checkout@v6.0.3
208287
with:
209288
fetch-depth: 0
210289

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919

2020
steps:
2121
- name: Checkout code
22-
uses: actions/checkout@v6.0.2
22+
uses: actions/checkout@v6.0.3
2323
with:
2424
ref: ${{ github.event.workflow_run.head_branch }}
2525
fetch-depth: 0

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,7 +174,7 @@ Tag: patch
174174

175175
| Input | Description | Default | Required |
176176
|-------|-------------|---------|----------|
177-
| `package-path` | Path to package.json | `./package.json` | No |
177+
| `package-path` | Path to package.json. Relative paths are resolved from the workflow workspace, and repository contents are checked out automatically when needed. | `./package.json` | No |
178178
| `build-script` | NPM script to run before publishing | `build` | No |
179179
| `package-manager` | Package manager to use: `npm`, `yarn`, `pnpm`, `bun`, or `auto` (auto-detects from lockfile) | `auto` | No |
180180
| `version-prefix` | Accepted for backward compatibility but ignored at runtime because npm package versions must remain valid SemVer | - | No |
@@ -222,8 +222,8 @@ Tag: patch
222222
| Input | Description | Default | Required |
223223
|-------|-------------|---------|----------|
224224
| `monorepo` | Enable monorepo mode | `false` | No |
225-
| `package-paths` | Comma-separated list of package.json paths (monorepo mode only). Takes priority over workspace-detection. Either this OR workspace-detection with valid workspaces field is required when monorepo is true. | - | Conditional* |
226-
| `workspace-detection` | Auto-detect workspaces from the package.json resolved from `package-path` (default `./package.json`). Reads its `workspaces` field and discovers all non-private packages. | `true` | No |
225+
| `package-paths` | Comma-separated list of package.json paths (monorepo mode only). Relative paths are resolved from the workflow workspace. Takes priority over workspace-detection. Either this OR workspace-detection with valid workspaces field is required when monorepo is true. | - | Conditional* |
226+
| `workspace-detection` | Auto-detect workspaces from the package.json resolved from `package-path` (default `./package.json`). The root package path is resolved from the workflow workspace. Reads its `workspaces` field and discovers all non-private packages. | `true` | No |
227227
| `changed-only` | Only build/publish packages that changed relative to the event-specific git diff base (monorepo mode only). Uses git diff to detect changes. | `true` | No |
228228
| `dependency-order` | Build packages in dependency order using topological sort (monorepo mode only). Analyzes workspace dependencies and builds packages in the correct order. Works with Bun-only monorepos through the same runtime-aware helper execution used elsewhere in the action. Set to `false` to use discovery order. Has no effect when using explicit `package-paths` without workspace discovery metadata. | `true` | No |
229229

action.yml

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ inputs:
4545

4646
# Package Configuration
4747
package-path:
48-
description: 'Path to package.json'
48+
description: 'Path to package.json. Relative paths are resolved from the workflow workspace, and repository contents are checked out automatically when needed.'
4949
required: false
5050
default: './package.json'
5151

@@ -113,7 +113,7 @@ inputs:
113113
default: 'false'
114114

115115
package-paths:
116-
description: 'Comma-separated list of package.json paths (monorepo mode)'
116+
description: 'Comma-separated list of package.json paths (monorepo mode). Relative paths are resolved from the workflow workspace.'
117117
required: false
118118
default: ''
119119

@@ -294,6 +294,23 @@ runs:
294294
BUILD_SKIP_TYPES: ${{ inputs.build-skip-types }}
295295
PR_TITLE: ${{ github.event.pull_request.title }}
296296

297+
- name: Resolve Package Paths
298+
id: resolve-paths
299+
if: steps.commit-gate.outputs.should-build != 'false'
300+
shell: bash
301+
run: |
302+
bash ${{ github.action_path }}/scripts/resolve-package-paths.sh
303+
env:
304+
PACKAGE_PATH: ${{ inputs.package-path }}
305+
PACKAGE_PATHS: ${{ inputs.package-paths }}
306+
307+
- name: Checkout Repository Contents
308+
if: steps.commit-gate.outputs.should-build != 'false' && steps.resolve-paths.outputs.checkout-required == 'true'
309+
uses: actions/checkout@v6.0.3
310+
with:
311+
fetch-depth: 0
312+
token: ${{ inputs.github-token }}
313+
297314
# =============================================================================
298315
# MONOREPO MODE
299316
# =============================================================================
@@ -309,8 +326,8 @@ runs:
309326
GITHUB_CONTEXT: ${{ toJson(github) }}
310327
MAIN_BRANCH: ${{ inputs.main-branch }}
311328
DEV_BRANCH: ${{ inputs.dev-branch }}
312-
PACKAGE_PATH: ${{ inputs.package-path }}
313-
PACKAGE_PATHS: ${{ inputs.package-paths }}
329+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
330+
PACKAGE_PATHS: ${{ steps.resolve-paths.outputs.package-paths }}
314331
WORKSPACE_DETECTION: ${{ inputs.workspace-detection }}
315332
CHANGED_ONLY: ${{ inputs.changed-only }}
316333
DEPENDENCY_ORDER: ${{ inputs.dependency-order }}
@@ -381,7 +398,7 @@ runs:
381398
GITHUB_CONTEXT: ${{ toJson(github) }}
382399
MAIN_BRANCH: ${{ inputs.main-branch }}
383400
DEV_BRANCH: ${{ inputs.dev-branch }}
384-
PACKAGE_PATH: ${{ inputs.package-path }}
401+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
385402
VERSION_PREFIX: ${{ inputs.version-prefix }}
386403

387404
- name: Configure Registries
@@ -397,7 +414,7 @@ runs:
397414
GITHUB_TOKEN: ${{ inputs.github-token }}
398415
GITHUB_REGISTRY_URL: ${{ inputs.github-registry-url }}
399416
PACKAGE_SCOPE: ${{ inputs.package-scope }}
400-
PACKAGE_PATH: ${{ inputs.package-path }}
417+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
401418
GITHUB_REPOSITORY_OWNER: ${{ github.repository_owner }}
402419

403420
- name: Build and Publish Package
@@ -410,7 +427,7 @@ runs:
410427
REGISTRY: ${{ inputs.registry }}
411428
PACKAGE_VERSION: ${{ steps.detect-flow.outputs.version }}
412429
NPM_TAG: ${{ steps.detect-flow.outputs.npm-tag }}
413-
PACKAGE_PATH: ${{ inputs.package-path }}
430+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
414431
BUILD_SCRIPT: ${{ inputs.build-script }}
415432
PACKAGE_MANAGER: ${{ inputs.package-manager }}
416433
PUBLISH_ENABLED: ${{ inputs.publish-enabled }}
@@ -431,7 +448,7 @@ runs:
431448
env:
432449
AUDIT_LEVEL: ${{ inputs.audit-level }}
433450
FAIL_ON_AUDIT: ${{ inputs.fail-on-audit }}
434-
PACKAGE_PATH: ${{ inputs.package-path }}
451+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
435452
PACKAGE_MANAGER: ${{ inputs.package-manager }}
436453

437454
- name: Generate Outputs
@@ -442,7 +459,7 @@ runs:
442459
bash ${{ github.action_path }}/scripts/generate-outputs.sh
443460
env:
444461
PACKAGE_VERSION: ${{ steps.detect-flow.outputs.version }}
445-
PACKAGE_PATH: ${{ inputs.package-path }}
462+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
446463
REGISTRY: ${{ inputs.registry }}
447464
NPM_REGISTRY_URL: ${{ inputs.npm-registry-url }}
448465
GITHUB_REGISTRY_URL: ${{ inputs.github-registry-url }}
@@ -462,7 +479,7 @@ runs:
462479
BUILD_FLOW_TYPE: ${{ steps.detect-flow.outputs.build-flow-type }}
463480
PACKAGE_VERSION: ${{ steps.detect-flow.outputs.version }}
464481
NPM_TAG: ${{ steps.detect-flow.outputs.npm-tag }}
465-
PACKAGE_PATH: ${{ inputs.package-path }}
482+
PACKAGE_PATH: ${{ steps.resolve-paths.outputs.package-path }}
466483
REGISTRY: ${{ inputs.registry }}
467484
NPM_REGISTRY_URL: ${{ inputs.npm-registry-url }}
468485
GITHUB_REGISTRY_URL: ${{ inputs.github-registry-url }}

scripts/resolve-package-paths.sh

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
#!/bin/bash
2+
set -e
3+
4+
echo "🧭 Resolving package paths..."
5+
6+
WORKSPACE_ROOT="${GITHUB_WORKSPACE:-$PWD}"
7+
PACKAGE_PATH_INPUT="${PACKAGE_PATH:-./package.json}"
8+
PACKAGE_PATHS_INPUT="${PACKAGE_PATHS:-}"
9+
CHECKOUT_REQUIRED="false"
10+
11+
normalize_path() {
12+
local absolute_path="$1"
13+
local -a path_stack=()
14+
local IFS='/'
15+
read -ra path_parts <<< "$absolute_path"
16+
17+
for part in "${path_parts[@]}"; do
18+
case "$part" in
19+
''|'.')
20+
continue
21+
;;
22+
'..')
23+
if [ "${#path_stack[@]}" -gt 0 ]; then
24+
unset 'path_stack[${#path_stack[@]}-1]'
25+
fi
26+
;;
27+
*)
28+
path_stack+=("$part")
29+
;;
30+
esac
31+
done
32+
33+
printf '/%s\n' "$(IFS=/; echo "${path_stack[*]}")"
34+
}
35+
36+
resolve_path() {
37+
local input_path="$1"
38+
local candidate_path
39+
40+
if [ -z "$input_path" ]; then
41+
return 0
42+
fi
43+
44+
if [[ "$input_path" = /* ]]; then
45+
candidate_path="$input_path"
46+
else
47+
input_path="${input_path#./}"
48+
candidate_path="$WORKSPACE_ROOT/$input_path"
49+
fi
50+
51+
normalize_path "$candidate_path"
52+
}
53+
54+
RESOLVED_PACKAGE_PATH="$(resolve_path "$PACKAGE_PATH_INPUT")"
55+
56+
if [[ "$RESOLVED_PACKAGE_PATH" == "$WORKSPACE_ROOT"/* ]] && [ ! -f "$RESOLVED_PACKAGE_PATH" ]; then
57+
CHECKOUT_REQUIRED="true"
58+
fi
59+
60+
RESOLVED_PACKAGE_PATHS=""
61+
62+
if [ -n "$PACKAGE_PATHS_INPUT" ]; then
63+
declare -a RESOLVED_PATH_ARRAY=()
64+
65+
IFS=',' read -ra PACKAGE_PATH_ARRAY <<< "$PACKAGE_PATHS_INPUT"
66+
for raw_path in "${PACKAGE_PATH_ARRAY[@]}"; do
67+
trimmed_path="${raw_path#"${raw_path%%[![:space:]]*}"}"
68+
trimmed_path="${trimmed_path%"${trimmed_path##*[![:space:]]}"}"
69+
70+
if [ -z "$trimmed_path" ]; then
71+
continue
72+
fi
73+
74+
resolved_path="$(resolve_path "$trimmed_path")"
75+
RESOLVED_PATH_ARRAY+=("$resolved_path")
76+
77+
if [[ "$resolved_path" == "$WORKSPACE_ROOT"/* ]] && [ ! -f "$resolved_path" ]; then
78+
CHECKOUT_REQUIRED="true"
79+
fi
80+
done
81+
82+
if [ "${#RESOLVED_PATH_ARRAY[@]}" -gt 0 ]; then
83+
RESOLVED_PACKAGE_PATHS="$(IFS=,; echo "${RESOLVED_PATH_ARRAY[*]}")"
84+
fi
85+
fi
86+
87+
echo "📍 Workspace root: $WORKSPACE_ROOT"
88+
echo "📄 Resolved package-path: $RESOLVED_PACKAGE_PATH"
89+
90+
if [ -n "$RESOLVED_PACKAGE_PATHS" ]; then
91+
echo "📚 Resolved package-paths: $RESOLVED_PACKAGE_PATHS"
92+
fi
93+
94+
if [ "$CHECKOUT_REQUIRED" = "true" ]; then
95+
echo "📥 Repository contents are not present yet; checkout will be requested"
96+
fi
97+
98+
echo "workspace-root=$WORKSPACE_ROOT" >> "$GITHUB_OUTPUT"
99+
echo "package-path=$RESOLVED_PACKAGE_PATH" >> "$GITHUB_OUTPUT"
100+
echo "package-paths=$RESOLVED_PACKAGE_PATHS" >> "$GITHUB_OUTPUT"
101+
echo "checkout-required=$CHECKOUT_REQUIRED" >> "$GITHUB_OUTPUT"

0 commit comments

Comments
 (0)