Код: Выделить всё
main.py
[*]
Код: Выделить всё
main.py
Я отлаживает журнал на различных этапах.
Код: Выделить всё
.github/workflows/...yml
Код: Выделить всё
jobs:
analyze-milestones:
runs-on: ubuntu-latest
steps:
# ... checkout, setup python ...
- name: Run Milestone Assistant
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# OPENROUTER_API_KEY: ...
DEBUG: ${{ github.event.inputs.debug_mode == 'true' && '1' || '0' }} # Debug flag
run: |
cd tools/milestone-assistant
python -m src.main \
# ... other args ...
${{ github.event.inputs.debug_mode == 'true' && '--debug' || '' }}
< /code>
[b] Загрузка конфигурации (src/config.py
Код: Выделить всё
import os
import logging
logger = logging.getLogger(__name__)
DEFAULT_CONFIG = { "github": { "token": "", ... }, ... }
def load_config():
config = DEFAULT_CONFIG.copy()
github_token_env = os.environ.get("GITHUB_TOKEN")
if github_token_env:
config["github"]["token"] = github_token_env
# Log right after reading
logger.debug(f"Read token from GITHUB_TOKEN. Type: {type(github_token_env)}, Length: {len(github_token_env)}")
# ... load other config ...
return config
< /code>
[b] фрагмент основного сценария (src/main.py
Код: Выделить всё
import argparse
import logging
import os
from .config import load_config
from .github.client import GitHubClient
logger = logging.getLogger(__name__)
def main():
args = parse_args() # Parses --debug flag
setup_logging(logging.DEBUG if args.debug else logging.INFO)
config = load_config()
config_token = config["github"]["token"]
# Log length retrieved from dict
logger.debug(f"Initializing GitHub client with token length: {len(config_token)}")
# Initialize client (fails with 401 when token is short)
github_client = GitHubClient(
token=config_token,
repository=config["github"]["repository"]
)
# ... rest of script ...
if __name__ == "__main__":
main()
При запуске рабочего процесса с разрешением отладки (
Код: Выделить всё
DEBUG=1
Код: Выделить всё
# Inside config.py, load_config()
DEBUG - Read token from GITHUB_TOKEN. Type: , Length: 40
# Inside main.py, after config = load_config()
DEBUG - Initializing GitHub client with token length: 14 #
Подробнее здесь: [url]https://stackoverflow.com/questions/79562863/why-is-my-github-token-truncated-when-retrieved-from-config-dict-in-github-actio[/url]