|
| 1 | +# Repository Guidelines |
| 2 | + |
| 3 | +## Project Structure & Module Organization |
| 4 | + |
| 5 | +- `azure-pipelines.yml` defines the Azure Pipelines workflow. The pipeline is split into a containerized `BuildPackage` stage that produces a tarball artifact and a later publish stage that consumes that tarball. |
| 6 | +- `findPackage.js`, `getDistTag.js`, and `createPackageArtifactMetadata.js` are the core Node scripts used by the pipeline. |
| 7 | +- `test/` contains Mocha tests (`test-*.js`) plus shared helpers in `test/utils.js`. |
| 8 | +- `repo/` is the checkout folder for target repositories; locally it serves as a fixture project folder for pipeline testing. |
| 9 | +- Root files like `package.json` and `package-lock.json` define Node tooling and dependencies. |
| 10 | + |
| 11 | +## Build, Test, and Development Commands |
| 12 | + |
| 13 | +- `npm test` runs the Mocha test suite (`NODE_ENV=test` via `cross-env`). |
| 14 | +- `node findPackage.js <pkg-name> <search-path> <output-file>` locates a package.json by name and writes JSON output. |
| 15 | +- `node getDistTag.js <local_version> <latest_version>` prints the dist-tag to use when publishing. |
| 16 | +- `node createPackageArtifactMetadata.js <package-folder> <tarball-path> <dist-tag> <output-file>` writes the stage handoff metadata for a packed tarball. |
| 17 | + |
| 18 | +## Coding Style & Naming Conventions |
| 19 | + |
| 20 | +- JavaScript uses 2-space indentation, double quotes, and semicolons (match existing files). |
| 21 | +- Prefer clear, function-based modules exported via `module.exports`. |
| 22 | +- Tests follow `test-<module>.js` naming and use Mocha + Should. |
| 23 | +- Prettier is available in devDependencies for formatting when needed. |
| 24 | +- Add JSDoc types for new or modified functions where practical. |
| 25 | + |
| 26 | +## Testing Guidelines |
| 27 | + |
| 28 | +- Framework: Mocha with `should` assertions. |
| 29 | +- Add tests under `test/` and keep each file focused on one module. |
| 30 | +- Run all tests with `npm test` before submitting changes. |
| 31 | +- When modifying files, run `npm run lint` and `npm run format`. |
| 32 | +- Before committing, run `npm run format:check`. |
| 33 | +- Run `npm run typecheck` when type-related changes are made (JSDoc/tsconfig). |
| 34 | +- When changing `azure-pipelines.yml`, preserve end-to-end behavior for Git submodules, Git LFS fetches, and log visibility for clone/LFS failures because OpenUPM parses those logs. |
| 35 | +- When working from a plan, after finishing any item, always state the next |
| 36 | + concrete step. Continue doing this until the plan is genuinely complete so |
| 37 | + the user does not need to ask "what's next?". |
| 38 | + |
| 39 | +## Pipeline Guardrails |
| 40 | + |
| 41 | +- Treat the upstream package repository as untrusted input. |
| 42 | +- Keep untrusted package lifecycle hooks inside the containerized `BuildPackage` stage only. |
| 43 | +- Do not introduce OpenUPM publish credentials into `BuildPackage`. |
| 44 | +- `PublishPackage` and `PublishE2EPackage` must publish the tarball artifact, not the source checkout. |
| 45 | +- Keep `npm publish --ignore-scripts` in the publish stage so publish-time hooks cannot execute there. |
| 46 | +- Keep the `BuildPackage` container image aligned with `mise.toml` Node major. The YAML uses one hardcoded `nodeMajorVersion` and asserts it against `mise.toml`. |
| 47 | +- Read the npm version from `mise.toml` instead of hardcoding it in multiple places. |
| 48 | +- Keep `prepare`/Husky for local development, but disable Husky during CI dependency installation in `BuildPackage`. |
| 49 | +- Use `e2eTest=true` to route a run to the Verdaccio-based e2e publish stage. Omitted or `false` means normal OpenUPM publish. |
| 50 | + |
| 51 | +## Debugging Tips |
| 52 | + |
| 53 | +- For GitHub-side debugging, `gh` is allowed and preferred for inspecting workflow runs, PRs, and logs when GitHub context is relevant. |
| 54 | +- For Azure pipeline debugging, prefer preserving native command output instead of wrapping failures in generic helper scripts. |
| 55 | +- Keep clone/LFS/submodule operations in explicit script steps so their stderr/stdout remains parsable in Azure logs. |
| 56 | +- If Git LFS behavior changes, check both the container image contents and the effective Git config seen inside `BuildPackage`. |
| 57 | +- If a pipeline tool version changes, verify both the YAML `nodeMajorVersion` and the `mise.toml` values. |
| 58 | +- When queueing Azure via REST API from a non-default branch of this repo, set `sourceBranch` so the run uses that branch's pipeline definition instead of the default branch. |
| 59 | +- Verdaccio e2e config lives at `test/verdaccio/config.yaml`. |
| 60 | +- Manual e2e fixture for this repo: |
| 61 | + `repoUrl=https://github.com/favoyang/com.example.nuget-consumer` |
| 62 | + `repoBranch=1.0.1` |
| 63 | + `packageName=com.example.nuget-consumer` |
| 64 | + `packageVersion=1.0.1` |
| 65 | + `e2eTest=true` |
| 66 | +- Use `npm run test:e2e:azure` to queue the documented Azure fixture from the |
| 67 | + current branch and print the relevant publish logs automatically. |
| 68 | +- Use `node scripts/runAzureFixture.js --e2e-test false` for the normal publish |
| 69 | + validation that expects `409 Conflict`. |
| 70 | +- GitHub Actions runs the Azure-backed helper in a separate `Azure E2E` job |
| 71 | + only when the `AZURE_DEVOPS_TOKEN_OPENUPM_PIPELINE` repository secret is |
| 72 | + available. |
| 73 | +- Manual normal-publish validation should use `e2eTest=false` with a package |
| 74 | + version that is already published to OpenUPM. The expected result is a `409 |
| 75 | +Conflict` from the publish step. |
| 76 | + |
| 77 | +## Security Notes |
| 78 | + |
| 79 | +- Use `$AZURE_DEVOPS_TOKEN_OPENUPM_PIPELINE` for Azure DevOps authentication when manual debugging requires a token. |
| 80 | +- Treat `$AZURE_DEVOPS_TOKEN_OPENUPM_PIPELINE` as a secret. Never print it, echo it, paste it into commit content, or include it in conversation responses. |
| 81 | +- Do not add commands or logs that would expose registry credentials, Azure tokens, or generated auth files. |
| 82 | + |
| 83 | +## Commit & Pull Request Guidelines |
| 84 | + |
| 85 | +- Commit messages follow Conventional Commits (e.g., `feat:`, `fix:`, `chore:`, `docs:`) and may include scopes like `fix(ci):`. |
| 86 | +- Use a `BREAKING CHANGE:` footer when introducing incompatible changes. |
| 87 | +- PRs should describe the change, link related issues, and note test results (e.g., `npm test`). |
| 88 | + |
| 89 | +## Configuration & Environment Notes |
| 90 | + |
| 91 | +- Node tooling is pinned via mise in `mise.toml`. |
| 92 | +- Pipeline variables are expected by `azure-pipelines.yml`; see `README.md` for usage examples. |
| 93 | + |
| 94 | +<!-- @agentsnippet "@/pull-request-delivery-workflow.md" --> |
0 commit comments