diff --git a/.github/workflows/main-branch.yml b/.github/workflows/main-branch.yml index 1a89cd6..fffc57e 100644 --- a/.github/workflows/main-branch.yml +++ b/.github/workflows/main-branch.yml @@ -1,4 +1,4 @@ -name: Main Branch Workflow +name: Unified Build, Test, and Deploy on: push: @@ -22,12 +22,12 @@ concurrency: cancel-in-progress: true jobs: - build_artifacts: - name: Build and Upload Artifacts + ci: + name: Build, Test, and Package runs-on: ubuntu-latest - outputs: - status: ${{ steps.collect.outputs.status }} - results: ${{ steps.collect.outputs.results }} + environment: + name: github-pages + url: ${{ steps.deployment.outputs.page_url }} steps: - name: Checkout repository uses: actions/checkout@v4 @@ -36,151 +36,31 @@ jobs: uses: ./.github/actions/setup-python-playwright - name: Build static site - id: build-site + id: build_site continue-on-error: true run: python .github/scripts/build_static.py - name: Upload Pages artifact - if: github.event_name == 'push' && steps.build-site.outcome == 'success' + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.build_site.outcome == 'success' uses: actions/upload-pages-artifact@v3 with: path: dist - - name: Collect build metadata - id: collect - run: | - python - <<'PY' - import base64 - import json - import os - from pathlib import Path - - path = Path("build-results.json") - data: dict[str, object] = {} - status = "missing" - if path.exists(): - data = json.loads(path.read_text()) - status = data.get("status", "unknown") - encoded = base64.b64encode(json.dumps(data).encode("utf-8")).decode("utf-8") - with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as handle: - handle.write(f"status={status}\n") - handle.write(f"results={encoded}\n") - PY - - report_build_status: - name: Report Build Status - runs-on: ubuntu-latest - needs: build_artifacts - if: always() - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Restore build results - env: - BUILD_RESULTS_B64: ${{ needs.build_artifacts.outputs.results }} - run: | - python - <<'PY' - import base64 - import json - import os - from pathlib import Path - - raw = os.environ.get("BUILD_RESULTS_B64", "") - data: dict[str, object] = {} - if raw: - try: - decoded = base64.b64decode(raw.encode("utf-8")).decode("utf-8") - if decoded: - data = json.loads(decoded) - except Exception as exc: # noqa: BLE001 - data = {"status": "unknown", "message": f"Unable to decode build results: {exc}"} - Path("build-results.json").write_text(json.dumps(data)) - PY - - - name: Report Build Status - run: python .github/scripts/write_summary.py --include-build - - - name: Fail if build failed - if: needs.build_artifacts.outputs.status == 'failure' - run: exit 1 - - tests: - name: Run Tests - runs-on: ubuntu-latest - needs: build_artifacts - if: always() - outputs: - status: ${{ steps.collect.outputs.status }} - results: ${{ steps.collect.outputs.results }} - steps: - - name: Checkout repository - uses: actions/checkout@v4 - - - name: Set up Python environment - uses: ./.github/actions/setup-python-playwright - - - name: Run Tests - id: run-tests + - name: Run tests + id: run_tests + if: always() continue-on-error: true run: python .github/scripts/run_tests.py - - name: Collect test metadata - id: collect - run: | - python - <<'PY' - import base64 - import json - import os - from pathlib import Path - - path = Path("test-results.json") - data: dict[str, object] = {} - status = "missing" - if path.exists(): - data = json.loads(path.read_text()) - status = data.get("overall_status", "unknown") - encoded = base64.b64encode(json.dumps(data).encode("utf-8")).decode("utf-8") - with open(os.environ["GITHUB_OUTPUT"], "a", encoding="utf-8") as handle: - handle.write(f"status={status}\n") - handle.write(f"results={encoded}\n") - PY - - report_tests_statuses: - name: Report Tests Statuses - runs-on: ubuntu-latest - needs: tests - if: always() - steps: - - name: Checkout repository - uses: actions/checkout@v4 + - name: Publish workflow summary + if: always() + run: python .github/scripts/write_summary.py --include-build --include-tests - - name: Restore test results - env: - TEST_RESULTS_B64: ${{ needs.tests.outputs.results }} - run: | - python - <<'PY' - import base64 - import json - import os - from pathlib import Path + - name: Deploy to GitHub Pages + id: deployment + if: github.event_name == 'push' && github.ref == 'refs/heads/main' && steps.build_site.outcome == 'success' && steps.run_tests.outcome == 'success' + uses: actions/deploy-pages@v4 - raw = os.environ.get("TEST_RESULTS_B64", "") - data: dict[str, object] = {} - if raw: - try: - decoded = base64.b64decode(raw.encode("utf-8")).decode("utf-8") - if decoded: - data = json.loads(decoded) - except Exception as exc: # noqa: BLE001 - data = {"tests": [], "overall_status": "failed", "message": f"Unable to decode test results: {exc}"} - Path("test-results.json").write_text(json.dumps(data)) - PY - - - name: Report Tests Statuses - run: python .github/scripts/write_summary.py --include-tests - - - name: Fail if tests failed - if: needs.tests.outputs.status == 'failed' + - name: Fail workflow if build or tests failed + if: ${{ always() && (steps.build_site.outcome != 'success' || steps.run_tests.outcome != 'success') }} run: exit 1 - diff --git a/AI/index.html b/AI/index.html index 147506c..da94636 100644 --- a/AI/index.html +++ b/AI/index.html @@ -64,4 +64,4 @@ - \ No newline at end of file +