Skip to content
Merged
1 change: 1 addition & 0 deletions changelog.d/4665.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
- `apm install` now tells you to set `GITHUB_HOST` when a GitHub Enterprise Server host in a positional argument is not recognised. (#4665)
15 changes: 15 additions & 0 deletions docs/src/content/docs/getting-started/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,21 @@ write `github.com/owner/repo` for packages on GitHub:
+ - github.com/microsoft/apm-sample-package#v1.0.0
```

The same works from one command, for example for user scope. Keep
`GITHUB_HOST` set whenever you reinstall: APM writes the server's entries as
shorthand and keeps the `github.com/` prefix on the others:

```bash frame="terminal"
export GITHUB_HOST=github.contoso.com
export GITHUB_APM_PAT_PLATFORM=ghp_... # token for the server's org
apm install --global \
github.contoso.com/platform/internal-skills/.agents/skills/jdk-installer#v2.1.0 \
github.com/contoso-oss/android-skills/performance/analyzer#main
```

Each package keeps its own host, subpath and ref in `apm.yml` and its host
and commit in `apm.lock.yaml`.

Enterprise Managed User tokens cannot read public `github.com` repositories;
public packages install without one.

Expand Down
18 changes: 18 additions & 0 deletions packages/apm-guide/.apm/skills/apm-usage/authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -310,6 +310,24 @@ apm install myorg/internal-package # resolves to github.company.com
apm pack # marketplace.json also resolves against github.company.com
```

Mixed hosts in one command: the server's package and explicit `github.com/`
packages each keep their own host, subpath and ref. The server's entry is
written as shorthand, so keep `GITHUB_HOST` set when reinstalling:

```bash
export GITHUB_HOST=github.company.com
apm install --global \
github.company.com/myorg/internal-skills/.agents/skills/jdk-installer#v2.1.0 \
github.com/example/android-skills/performance/analyzer#main
```

Without `GITHUB_HOST`, a custom host is not GitHub-class: the package is
refused with a hint to set `GITHUB_HOST` (and write `github.com/` before
GitHub entries in apm.yml) or to use a `git:` + `path:` object entry. When
`GITHUB_HOST` already names another server, keep it and add the second
server's package as a `git:` + `path:` object entry; changing `GITHUB_HOST`
would re-home existing shorthand entries.

## GitLab (SaaS or self-managed)

GitLab `path:` single-file sparse fetches follow the clone transport policy:
Expand Down
17 changes: 15 additions & 2 deletions src/apm_cli/install/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,11 +192,24 @@ def _generic_host_ambiguous_subpath_hint(dep_ref) -> str | None:
segments = repository_path_segments(dep_ref.repo_url)
if len(segments) <= 2:
return None
configured = default_host().strip().lower()
if configured and configured != "github.com":
# Switching GITHUB_HOST would re-home the existing shorthand entries.
ghes_clause = (
f"GITHUB_HOST already names {configured}; keep it and, if this is "
f"another GitHub Enterprise Server, add this package as an explicit "
f"'git:' + 'path:' entry in apm.yml."
)
else:
ghes_clause = (
f"If this is GitHub Enterprise Server, set GITHUB_HOST={host}, write "
f"github.com/ before apm.yml entries for packages on GitHub, and re-run."
)
return (
f"'{host}' was treated as a single repository path "
f"('{dep_ref.repo_url}') because it isn't recognised as GitHub, "
f"Azure DevOps, or GitLab. If this is a self-hosted GitLab instance, "
f"set GITLAB_HOST={host} (or add it to the comma-separated "
f"Azure DevOps, or GitLab. {ghes_clause} If this is a self-hosted GitLab "
f"instance, set GITLAB_HOST={host} (or add it to the comma-separated "
f"APM_GITLAB_HOSTS) and re-run to enable repo/subpath resolution for "
f"nested groups. Otherwise, use an explicit 'git:' + 'path:' entry "
f"in apm.yml."
Expand Down
22 changes: 22 additions & 0 deletions tests/fixtures/lifecycle_bug_ledger/bugs/2775.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
{
"issue": 2775,
"fixed_in": "Unreleased",
"summary": "An unrecognised GitHub Enterprise Server host in a mixed-host install was refused without naming GITHUB_HOST as its configuration.",
"failure_modes": [
"routing",
"outcome"
],
"properties": [
"auth.credentials_isolated",
"transaction.failed_command_preserves_state"
],
"regression_tests": [
"tests/lifecycle/scenarios/test_explicit_host_identity.py::test_mixed_host_global_lifecycle_keeps_each_package_host",
"tests/lifecycle/scenarios/test_explicit_host_identity.py::test_strict_host_credentials_keep_the_ghes_token_on_ghes",
"tests/lifecycle/scenarios/test_explicit_host_identity.py::test_unconfigured_ghes_host_is_refused_with_working_remedies",
"tests/lifecycle/scenarios/test_explicit_host_identity.py::test_frozen_reload_without_the_configured_host_fails_closed",
"tests/lifecycle/scenarios/test_explicit_host_identity.py::test_configured_server_keeps_shorthand_and_object_form_adds_another",
"tests/unit/install/test_validation_error_handling.py::TestGenericHostAmbiguousSubpathHint::test_unrecognised_selfhosted_ambiguous_path_returns_hint",
"tests/unit/install/test_validation_error_handling.py::TestGenericHostAmbiguousSubpathHint::test_configured_github_host_keeps_it_and_recommends_object_form"
]
}
Loading
Loading