Robust enterprise config: env-first, auto_create default true, simpli… #1
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: GitHub Copilot Cost Center Automation | ||
on: | ||
schedule: | ||
# Run every 6 hours (adjust as needed) | ||
- cron: '0 */6 * * *' | ||
# Allow manual triggering from GitHub UI | ||
workflow_dispatch: | ||
inputs: | ||
mode: | ||
description: 'Run mode' | ||
required: true | ||
default: 'incremental' | ||
type: choice | ||
options: | ||
- incremental | ||
- full | ||
jobs: | ||
update-cost-centers: | ||
runs-on: ubuntu-latest | ||
env: | ||
GITHUB_ENTERPRISE: ${{ secrets.GITHUB_ENTERPRISE_NAME }} | ||
GITHUB_TOKEN: ${{ secrets.COPILOT_GITHUB_TOKEN }} | ||
steps: | ||
- name: Checkout repository | ||
uses: actions/checkout@v4 | ||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: '3.11' | ||
cache: 'pip' | ||
- name: Install dependencies | ||
run: pip install -r requirements.txt | ||
- name: (Optional) Show effective config (debug) | ||
run: | | ||
echo "Enterprise: $GITHUB_ENTERPRISE" | ||
grep enterprise config/config.yaml || true | ||
python - <<'PY' | ||
import os, yaml | ||
with open('config/config.yaml') as f: | ||
data = yaml.safe_load(f) or {} | ||
print('YAML enterprise:', data.get('github', {}).get('enterprise')) | ||
print('ENV enterprise:', os.getenv('GITHUB_ENTERPRISE')) | ||
PY | ||
- name: Run incremental cost center update | ||
if: github.event.inputs.mode != 'full' | ||
run: | | ||
python main.py --create-cost-centers --assign-cost-centers --incremental --mode apply --yes --summary-report --verbose | ||
- name: Run full cost center update | ||
if: github.event.inputs.mode == 'full' | ||
run: | | ||
python main.py --create-cost-centers --assign-cost-centers --mode apply --yes --summary-report --verbose | ||
- name: Upload logs | ||
if: always() | ||
uses: actions/upload-artifact@v4 | ||
with: | ||
name: cost-center-logs-${{ github.run_number }} | ||
path: logs/ | ||
retention-days: 30 | ||
- name: Check for failures and notify | ||
if: failure() | ||
run: | | ||
echo "::error::Cost center automation failed. Check the logs for details." |