diff --git a/.github/workflows/maintain-docs.yml b/.github/workflows/maintain-docs.yml index d42646c..19ef135 100644 --- a/.github/workflows/maintain-docs.yml +++ b/.github/workflows/maintain-docs.yml @@ -80,6 +80,9 @@ env: EXTERNAL_PACKAGE_SOURCE_POLICY: description: Version 1 JSON policy authorizing Docs Agent standalone native packages. required: true + PUBLISH_TOKEN: + description: Optional token for checkout and publication. Defaults to the caller-scoped github.token. Pass a GitHub App installation token so the docs pull request opens as that app and triggers the repository's pull_request workflows, which GitHub suppresses for github.token. + required: false outputs: job_status: description: Docs Agent run status. @@ -373,5 +376,5 @@ jobs: dry_run: ${{ inputs.dry_run }} secrets: OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }} - ACCESS_TOKEN: ${{ github.token }} + ACCESS_TOKEN: ${{ secrets.PUBLISH_TOKEN || github.token }} EXTERNAL_PACKAGE_SOURCE_POLICY: ${{ secrets.EXTERNAL_PACKAGE_SOURCE_POLICY }} diff --git a/README.md b/README.md index f2e629a..693d021 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,8 @@ jobs: Docs Agent targets the calling repository and forwards its scoped `${{ github.token }}` to WP Codebox for checkout and publication. The consumer must grant `contents: write`, `pull-requests: write`, and `issues: write`; no `ACCESS_TOKEN` secret is required for this same-repository contract. `OPENAI_API_KEY` is optional in the reusable workflow schema but required for a live `run_agent: true` OpenAI run. `EXTERNAL_PACKAGE_SOURCE_POLICY` is a separate required secret: WP Codebox uses it to authorize the selected Docs Agent package and the complete WordPress-native runtime closure. Replace the prior v1 secret value with the exact value below; its secret name and workflow mapping are unchanged. +`PUBLISH_TOKEN` is optional. When it is empty, Docs Agent uses `${{ github.token }}` as above. GitHub does not start `pull_request` workflows for pull requests opened with `github.token`, so docs pull requests opened that way get no CI. To get CI on them, store a fine-grained personal access token as a repository secret and pass it as `PUBLISH_TOKEN`. Limit the token to the calling repository, with `contents`, `pull-requests`, and `issues` write. The pull request then opens as that token's account. Prefer a dedicated machine account, because the token reaches the agent run's checkout and publication. A GitHub App installation token minted in an earlier caller job does not work: GitHub drops job outputs that contain secrets, so the token cannot reach a reusable workflow call. + Configure `DOCS_AGENT_EXTERNAL_PACKAGE_SOURCE_POLICY` with this exact v1 JSON value: ```json diff --git a/tests/validate-docs-agent-packages.php b/tests/validate-docs-agent-packages.php index 9c67a88..f1f58c9 100644 --- a/tests/validate-docs-agent-packages.php +++ b/tests/validate-docs-agent-packages.php @@ -95,7 +95,7 @@ $assert( str_contains( $maintain_docs_workflow, 'artifact:{name:"docs_agent_completion_report",type:"DocsAgentCompletionReport",path:$path}' ), 'The mandatory completion drift check must declare the generic WP Codebox command artifact shape.' ); $assert( str_contains( $maintain_docs_workflow, 'output_projections:' ), 'maintain-docs.yml must project the bounded runner publication result.' ); $assert( str_contains( $maintain_docs_workflow, 'OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}' ), 'maintain-docs.yml must explicitly forward OPENAI_API_KEY to the native runner.' ); -$assert( str_contains( $maintain_docs_workflow, 'ACCESS_TOKEN: ${{ github.token }}' ), 'maintain-docs.yml must forward the caller-scoped GitHub token to the native runner.' ); +$assert( str_contains( $maintain_docs_workflow, 'ACCESS_TOKEN: ${{ secrets.PUBLISH_TOKEN || github.token }}' ), 'maintain-docs.yml must forward an optional PUBLISH_TOKEN and fall back to the caller-scoped GitHub token.' ); $assert( str_contains( $maintain_docs_workflow, 'EXTERNAL_PACKAGE_SOURCE_POLICY: ${{ secrets.EXTERNAL_PACKAGE_SOURCE_POLICY }}' ), 'maintain-docs.yml must explicitly forward the external package source policy.' ); $assert( str_contains( $maintain_docs_workflow, 'runtime_sources: ${{ needs.prepare.outputs.runtime_sources }}' ), 'maintain-docs.yml must pass its complete native runtime closure to WP Codebox.' ); diff --git a/tests/validate-external-native-package-sources.php b/tests/validate-external-native-package-sources.php index 898c908..71d7f95 100644 --- a/tests/validate-external-native-package-sources.php +++ b/tests/validate-external-native-package-sources.php @@ -73,8 +73,9 @@ $assert( ! str_contains( $workflow, 'pipeline_slug' ) && ! str_contains( $workflow, 'flow_slug' ) && ! str_contains( $workflow, 'bundle_path' ), 'The active workflow must not pass legacy bundle envelopes.' ); $assert( str_contains( $workflow, 'EXTERNAL_PACKAGE_SOURCE_POLICY:' ) && str_contains( $workflow, 'EXTERNAL_PACKAGE_SOURCE_POLICY: ${{ secrets.EXTERNAL_PACKAGE_SOURCE_POLICY }}' ), 'The policy secret must be required and forwarded without serialization.' ); $assert( str_contains( $workflow, 'OPENAI_API_KEY: ${{ secrets.OPENAI_API_KEY }}' ), 'OPENAI_API_KEY must be forwarded without serialization.' ); -$assert( str_contains( $workflow, 'ACCESS_TOKEN: ${{ github.token }}' ), 'Same-repository publication must use the caller-scoped GitHub token.' ); -$assert( ! str_contains( $workflow, 'secrets.ACCESS_TOKEN' ), 'Docs Agent must not require a consumer ACCESS_TOKEN override.' ); +$assert( str_contains( $workflow, 'ACCESS_TOKEN: ${{ secrets.PUBLISH_TOKEN || github.token }}' ), 'Same-repository publication must default to the caller-scoped GitHub token.' ); +$assert( ! str_contains( $workflow, 'secrets.ACCESS_TOKEN' ), 'Docs Agent must not accept a raw ACCESS_TOKEN override.' ); +$assert( preg_match( '/ PUBLISH_TOKEN:\n(?: .*\n)*? required: false/m', $workflow ) === 1, 'PUBLISH_TOKEN must stay optional so callers need no extra secret.' ); $readme = (string) file_get_contents( $root . '/README.md' ); $policy_json = '{"version":1,"repositories":{"automattic/docs-agent":["bundles/technical-docs-agent/native/technical-docs-bootstrap-agent.agent.json","bundles/technical-docs-agent/native/technical-docs-maintenance-agent.agent.json","bundles/user-docs-agent/native/user-docs-bootstrap-agent.agent.json","bundles/user-docs-agent/native/user-docs-maintenance-agent.agent.json","bundles/skills-agent/native/skills-maintenance-agent.agent.json"]},"runtime_sources":{"automattic/agents-api":["."],"wordpress/php-ai-client":["."]},"runtime_artifacts":[{"url":"https://downloads.wordpress.org/plugin/ai-provider-for-openai.1.0.3.zip","sha256":"48f3c0c714b3164cda79d320829830d5a0ea1116e0b19653da8af898a22d3bb6"}]}'; diff --git a/tests/validate-wp-codebox-run-agent-task-contract.php b/tests/validate-wp-codebox-run-agent-task-contract.php index 6a28d06..9657b53 100644 --- a/tests/validate-wp-codebox-run-agent-task-contract.php +++ b/tests/validate-wp-codebox-run-agent-task-contract.php @@ -202,7 +202,7 @@ } } -$assert( '${{ github.token }}' === ( $caller_secrets['ACCESS_TOKEN'] ?? null ), 'Docs Agent must explicitly forward the caller-scoped GitHub token as ACCESS_TOKEN.' ); +$assert( '${{ secrets.PUBLISH_TOKEN || github.token }}' === ( $caller_secrets['ACCESS_TOKEN'] ?? null ), 'Docs Agent must forward ACCESS_TOKEN as the optional PUBLISH_TOKEN, falling back to the caller-scoped GitHub token.' ); $assert( '${{ secrets.OPENAI_API_KEY }}' === ( $caller_secrets['OPENAI_API_KEY'] ?? null ), 'Docs Agent must explicitly forward OPENAI_API_KEY.' ); $assert( '${{ secrets.EXTERNAL_PACKAGE_SOURCE_POLICY }}' === ( $caller_secrets['EXTERNAL_PACKAGE_SOURCE_POLICY'] ?? null ), 'Docs Agent must explicitly forward the external package policy secret.' ); $assert( preg_match( '/secrets:\n OPENAI_API_KEY:\n(?: .*\n)* required: false/m', $workflow ) === 1, 'Docs Agent must expose OPENAI_API_KEY as an optional reusable-workflow secret.' );