@@ -396,8 +396,16 @@ def detect_repository_context() -> dict[str, str | bool]:
396396 - is_push: Whether we're on a regular commit/push
397397 - ref_name: The current ref (tag/branch name)
398398 - strategy: Recommended download strategy
399+ - is_github_actions: Whether running in GitHub Actions
399400 """
400- context : dict [str , str | bool ] = {"is_release" : False , "is_push" : False , "ref_name" : "unknown" , "strategy" : "artifacts_first" } # default strategy
401+ context : dict [str , str | bool ] = {"is_release" : False , "is_push" : False , "ref_name" : "unknown" , "strategy" : "artifacts_first" , "is_github_actions" : False } # default strategy
402+
403+ # Check if we're running in GitHub Actions
404+ is_github_actions = os .environ .get ("GITHUB_ACTIONS" ) == "true"
405+ context ["is_github_actions" ] = is_github_actions
406+
407+ if is_github_actions :
408+ log_message ("Running in GitHub Actions environment" )
401409
402410 # Check GitHub Actions environment variables
403411 github_event_name = os .environ .get ("GITHUB_EVENT_NAME" , "" )
@@ -513,15 +521,19 @@ def main() -> None:
513521 if not download_succeeded and config ["use_github_artifacts" ]:
514522 github_token = os .environ .get ("GITHUB_TOKEN" ) or os .environ .get ("GH_TOKEN" )
515523 if github_token :
516- log_message ("Trying GitHub Actions artifacts (fallback)" )
524+ token_source = "automatic" if repo_context ["is_github_actions" ] else "configured"
525+ log_message (f"Trying GitHub Actions artifacts (fallback) - using { token_source } token" )
517526 artifact_url = check_github_artifacts_for_examples (repo_owner , repo_name , github_token )
518527 if artifact_url :
519528 success = download_and_extract_examples (artifact_url , docs_dir )
520529 if success :
521530 log_message ("Successfully downloaded auto_examples from GitHub artifact" )
522531 download_succeeded = True
523532 else :
524- log_message ("No GitHub token available for artifact fallback" )
533+ if repo_context ["is_github_actions" ]:
534+ log_message ("Warning: No GITHUB_TOKEN available in GitHub Actions (this is unexpected)" )
535+ else :
536+ log_message ("No GitHub token available for artifact fallback" )
525537
526538 else : # artifacts_first strategy
527539 log_message ("Using artifacts-first strategy (detected push/commit)" )
@@ -530,15 +542,19 @@ def main() -> None:
530542 if config ["use_github_artifacts" ]:
531543 github_token = os .environ .get ("GITHUB_TOKEN" ) or os .environ .get ("GH_TOKEN" )
532544 if github_token :
533- log_message ("Trying GitHub Actions artifacts (primary for push/commit)" )
545+ token_source = "automatic" if repo_context ["is_github_actions" ] else "configured"
546+ log_message (f"Trying GitHub Actions artifacts (primary for push/commit) - using { token_source } token" )
534547 artifact_url = check_github_artifacts_for_examples (repo_owner , repo_name , github_token )
535548 if artifact_url :
536549 success = download_and_extract_examples (artifact_url , docs_dir )
537550 if success :
538551 log_message ("Successfully downloaded auto_examples from GitHub artifact" )
539552 download_succeeded = True
540553 else :
541- log_message ("No GitHub token available for artifact download" )
554+ if repo_context ["is_github_actions" ]:
555+ log_message ("Warning: No GITHUB_TOKEN available in GitHub Actions (this is unexpected)" )
556+ else :
557+ log_message ("No GitHub token available for artifact download" )
542558
543559 # Try releases as fallback for push/commit
544560 if not download_succeeded and config ["use_github_releases" ]:
@@ -570,6 +586,8 @@ def main() -> None:
570586
571587 if is_rtd or is_ci :
572588 github_token_available = bool (os .environ .get ("GITHUB_TOKEN" ) or os .environ .get ("GH_TOKEN" ))
589+ is_github_actions = repo_context ["is_github_actions" ]
590+
573591 error_msg += f"""
574592
575593Attempted sources (strategy: { repo_context ['strategy' ]} ):
@@ -579,16 +597,30 @@ def main() -> None:
579597
580598This will cause the documentation build to fail or be extremely slow.
581599
582- Solutions:
583- 1. Set GITHUB_TOKEN environment variable with 'actions:read' scope in RTD settings
584- 2. Create a GitHub release with auto_examples.zip asset
585- 3. Ensure workflow artifacts exist and haven't expired
586- 4. For RTD: Go to Project Settings → Environment Variables → Add GITHUB_TOKEN
587-
588- GitHub Token Requirements:
600+ Solutions:"""
601+
602+ if is_github_actions :
603+ error_msg += """
604+ - In GitHub Actions: GITHUB_TOKEN should be automatically available
605+ - Check workflow permissions in .github/workflows/*.yml:
606+ ```yaml
607+ permissions:
608+ actions: read # Required for downloading artifacts
609+ contents: read
610+ ```
611+ - Verify artifacts exist and haven't expired (30-day retention)
612+ - Note: Cross-workflow artifact access may require explicit permissions"""
613+ else :
614+ error_msg += """
615+ 1. For RTD: Set GITHUB_TOKEN environment variable with 'actions:read' scope
616+ - Go to Project Settings → Environment Variables → Add GITHUB_TOKEN
617+ - Create token at: GitHub Settings → Developer settings → Personal access tokens
618+ 2. Alternative: Create a GitHub release with auto_examples.zip asset
619+ 3. Ensure workflow artifacts exist and haven't expired (30-day retention)
620+
621+ GitHub Token Requirements for external services:
589622- Repository access (public repos: no additional scopes needed)
590- - actions:read scope (for downloading workflow artifacts)
591- """
623+ - actions:read scope (required for downloading workflow artifacts)"""
592624 log_message (error_msg )
593625 exit (1 )
594626 else :
0 commit comments