Skip to content

Commit 81a545b

Browse files
committed
feat(init): infer runtime from source template
1 parent 161a853 commit 81a545b

4 files changed

Lines changed: 24 additions & 14 deletions

File tree

‎.github/scripts/init-repo.sh‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ force=false
1111
languages="${REPO_FOUNDRY_LANGUAGES:-auto}"
1212
features="${REPO_FOUNDRY_FEATURES:-all}"
1313
package_manager="${REPO_FOUNDRY_PACKAGE_MANAGER:-auto}"
14-
runtime_repository="${REPO_FOUNDRY_RUNTIME_REPOSITORY:-0xPlayerOne/code-foundry}"
14+
runtime_repository="${REPO_FOUNDRY_RUNTIME_REPOSITORY:-}"
1515
bootstrap=true
1616
release_type="${REPO_FOUNDRY_RELEASE_TYPE:-auto}"
1717
npm_publish="${REPO_FOUNDRY_NPM_PUBLISH:-false}"
@@ -38,7 +38,7 @@ Options:
3838
--features LIST all or comma-separated optional features:
3939
ci,codeql,security,test,draft-pr,release-pr,release,dependabot
4040
--package-manager NAME auto, bun, pnpm, yarn, or npm
41-
--runtime-repository OWNER/REPO Reusable workflow runtime repository
41+
--runtime-repository OWNER/REPO Reusable workflow runtime repository (auto from source)
4242
--release-type NAME auto, node, python, rust, or simple
4343
--license NAME agpl-3.0-or-later, mit, preserve, or none
4444
--license-file PATH Use an exact custom license file
@@ -111,9 +111,9 @@ sync_args=(
111111
--languages "$languages"
112112
--features "$features"
113113
--package-manager "$package_manager"
114-
--runtime-repository "$runtime_repository"
115114
--license "$license"
116115
)
116+
if [ -n "$runtime_repository" ]; then sync_args+=(--runtime-repository "$runtime_repository"); fi
117117
if [ -n "$license_file" ]; then sync_args+=(--license-file "$license_file"); fi
118118
if [ "$dry_run" = true ]; then sync_args+=(--check); else sync_args+=(--apply); fi
119119
if [ "$prune" = true ]; then sync_args+=(--prune); fi

‎.github/scripts/sync-template.sh‎

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -370,16 +370,22 @@ for file in "${files[@]}"; do
370370
done
371371

372372
# Reusable workflow callers must use a literal repository/ref. Render the
373-
# selected runtime repository while leaving custom workflows untouched.
373+
# selected runtime repository while leaving custom workflows untouched. Read
374+
# the source's configured runtime first so forks remain self-contained.
375+
source_runtime_repository=""
376+
if [ -f "$template_root/.github/template.yml" ]; then
377+
source_runtime_repository="$(awk -F': ' '/^runtime_repository:/ {print $2; exit}' "$template_root/.github/template.yml")"
378+
fi
379+
[ -n "$source_runtime_repository" ] || source_runtime_repository="0xPlayerOne/code-foundry"
374380
for file in .github/workflows/ci.yml .github/workflows/test.yml .github/workflows/security.yml .github/workflows/codeql.yml; do
375381
[ -f "$file" ] || continue
376-
if grep -q '0xPlayerOne/code-foundry' "$file"; then
382+
if grep -qF "$source_runtime_repository" "$file" && [ "$source_runtime_repository" != "$runtime_repository" ]; then
377383
changed=$((changed + 1))
378384
if [ "$mode" = "check" ]; then
379385
printf 'Would render runtime repository in %s\n' "$file"
380386
else
381387
rendered_workflow="$(mktemp)"
382-
sed "s#0xPlayerOne/code-foundry#$runtime_repository#g" "$file" > "$rendered_workflow"
388+
sed "s#${source_runtime_repository}#${runtime_repository}#g" "$file" > "$rendered_workflow"
383389
mv "$rendered_workflow" "$file"
384390
printf 'Rendered runtime repository in %s\n' "$file"
385391
fi

‎README.md‎

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,11 +36,12 @@ npx code-foundry init --license agpl-3.0-or-later
3636
npx code-foundry init --license-file ./legal/LICENSE.txt
3737
```
3838

39-
Reusable workflow callers default to this package's public runtime. Use
40-
`--runtime-repository OWNER/REPO` when initializing from an organization fork;
41-
the selected repository is saved in `.github/template.yml` and rendered into
42-
the small `ci.yml` and `test.yml` wrappers automatically. The equivalent
43-
environment variable is `REPO_FOUNDRY_RUNTIME_REPOSITORY`.
39+
Reusable workflow callers use the source template's runtime automatically. For
40+
example, initializing from `NiftyLeague/template-repo` selects that fork's
41+
runtime without extra flags. Use `--runtime-repository OWNER/REPO` (or
42+
`REPO_FOUNDRY_RUNTIME_REPOSITORY`) only when you want to override it. The
43+
selected repository is saved in `.github/template.yml` and rendered into the
44+
small CI, Test, Security, and CodeQL wrappers automatically.
4445

4546
Normal synchronization imports only the local hook, agent-facing command,
4647
profile/release, initializer, doctor, ownership, and protection entrypoints.

‎src/cli.mjs‎

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,10 @@ function parseArgs(argv) {
5050
languages: process.env.REPO_FOUNDRY_LANGUAGES || 'auto',
5151
features: process.env.REPO_FOUNDRY_FEATURES || 'all',
5252
packageManager: process.env.REPO_FOUNDRY_PACKAGE_MANAGER || 'auto',
53-
runtimeRepository: process.env.REPO_FOUNDRY_RUNTIME_REPOSITORY || '0xPlayerOne/code-foundry',
53+
// Leave this empty unless the caller explicitly selects a runtime. The
54+
// initializer can then derive the runtime from --source, which keeps
55+
// organization forks plug-and-play.
56+
runtimeRepository: process.env.REPO_FOUNDRY_RUNTIME_REPOSITORY || '',
5457
releaseType: process.env.REPO_FOUNDRY_RELEASE_TYPE || 'auto',
5558
license: process.env.REPO_FOUNDRY_LICENSE || (command === 'init' ? 'agpl-3.0-or-later' : 'preserve'),
5659
licenseFile: process.env.REPO_FOUNDRY_LICENSE_FILE || '',
@@ -123,7 +126,7 @@ function main() {
123126
if (options.licenseFile) common.push('--license-file', options.licenseFile)
124127
if (options.languagesSet) common.push('--languages', options.languages)
125128
if (options.featuresSet) common.push('--features', options.features)
126-
common.push('--runtime-repository', options.runtimeRepository)
129+
if (options.runtimeRepository) common.push('--runtime-repository', options.runtimeRepository)
127130
if (options.prune) common.push('--prune')
128131
if (options.force) common.push('--force')
129132
if (options.dryRun) common.push('--check')
@@ -137,10 +140,10 @@ function main() {
137140
'--languages', options.languages,
138141
'--features', options.features,
139142
'--package-manager', options.packageManager,
140-
'--runtime-repository', options.runtimeRepository,
141143
'--release-type', options.releaseType,
142144
'--license', options.license,
143145
]
146+
if (options.runtimeRepository) initArgs.push('--runtime-repository', options.runtimeRepository)
144147
if (options.licenseFile) initArgs.push('--license-file', options.licenseFile)
145148
if (options.protection) initArgs.push('--protection')
146149
if (options.dryRun) initArgs.push('--dry-run')

0 commit comments

Comments
 (0)