|
| 1 | +# SPDX-FileCopyrightText: Copyright (c) 2025-2026 NVIDIA CORPORATION & AFFILIATES. All rights reserved. |
| 2 | +# SPDX-License-Identifier: Apache-2.0 |
| 3 | + |
| 4 | +name: SDK Proto Sync |
| 5 | + |
| 6 | +on: |
| 7 | + schedule: |
| 8 | + - cron: "0 6 * * *" |
| 9 | + workflow_dispatch: |
| 10 | + |
| 11 | +env: |
| 12 | + MISE_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 13 | + |
| 14 | +permissions: |
| 15 | + actions: read |
| 16 | + contents: read |
| 17 | + packages: read |
| 18 | + |
| 19 | +concurrency: |
| 20 | + group: sdk-proto-sync |
| 21 | + cancel-in-progress: true |
| 22 | + |
| 23 | +jobs: |
| 24 | + load_config: |
| 25 | + name: Load SDK configuration |
| 26 | + runs-on: ubuntu-latest |
| 27 | + timeout-minutes: 5 |
| 28 | + outputs: |
| 29 | + matrix: ${{ steps.config.outputs.matrix }} |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 32 | + - id: config |
| 33 | + run: echo "matrix=$(jq -c '.include' tasks/sdk-sync-config.json)" >> "$GITHUB_OUTPUT" |
| 34 | + |
| 35 | + sdk_sync_check: |
| 36 | + name: Sync Check (${{ matrix.sdk.name }}) |
| 37 | + needs: load_config |
| 38 | + runs-on: linux-amd64-cpu8 |
| 39 | + timeout-minutes: 30 |
| 40 | + container: |
| 41 | + image: ghcr.io/nvidia/openshell/ci:5b9daab9351b1e053f9a5e0ce4c899f5d3f674b0 |
| 42 | + credentials: |
| 43 | + username: ${{ github.actor }} |
| 44 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 45 | + strategy: |
| 46 | + fail-fast: false |
| 47 | + matrix: |
| 48 | + sdk: ${{ fromJSON(needs.load_config.outputs.matrix) }} |
| 49 | + steps: |
| 50 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 51 | + - name: Install tools |
| 52 | + run: mise install --locked |
| 53 | + - name: Check proto drift and build |
| 54 | + env: |
| 55 | + SDK_NAME: ${{ matrix.sdk.name }} |
| 56 | + DRIFT_TASK: ${{ matrix.sdk.drift_task }} |
| 57 | + BUILD_CHECK_TASK: ${{ matrix.sdk.build_check_task }} |
| 58 | + run: | |
| 59 | + mkdir -p report |
| 60 | + mise run "$DRIFT_TASK" > report/drift.json 2> report/drift.stderr || true |
| 61 | + if ! jq -e 'type == "object" and has("synced") and (.synced | type == "boolean") and (has("error") | not)' report/drift.json >/dev/null 2>&1; then |
| 62 | + jq -n --arg sdk "$SDK_NAME" '{sdk:$sdk, has_drift:"error", build_failed:"false"}' > report/status.json |
| 63 | + exit 0 |
| 64 | + fi |
| 65 | + SYNCED=$(jq -r '.synced' report/drift.json) |
| 66 | + if [ "$SYNCED" = "true" ]; then |
| 67 | + jq -n --arg sdk "$SDK_NAME" '{sdk:$sdk, has_drift:"false", build_failed:"false"}' > report/status.json |
| 68 | + exit 0 |
| 69 | + fi |
| 70 | + if mise run "$BUILD_CHECK_TASK" > report/build.json 2> report/build.stderr; then |
| 71 | + BUILD_FAILED=false |
| 72 | + else |
| 73 | + BUILD_FAILED=true |
| 74 | + fi |
| 75 | + jq -n --arg sdk "$SDK_NAME" --arg build_failed "$BUILD_FAILED" \ |
| 76 | + '{sdk:$sdk, has_drift:"true", build_failed:$build_failed}' > report/status.json |
| 77 | + - name: Upload SDK report |
| 78 | + if: always() |
| 79 | + uses: actions/upload-artifact@043fb46d1a93c77aae656e7c1c64a875d1fc6a0a # v7.0.1 |
| 80 | + with: |
| 81 | + name: sdk-sync-${{ matrix.sdk.name }} |
| 82 | + path: report/ |
| 83 | + if-no-files-found: error |
| 84 | + retention-days: 1 |
| 85 | + |
| 86 | + issue_management: |
| 87 | + name: Manage Drift Issue (${{ matrix.sdk.name }}) |
| 88 | + needs: [load_config, sdk_sync_check] |
| 89 | + if: always() && needs.load_config.result == 'success' && needs.sdk_sync_check.result == 'success' |
| 90 | + runs-on: linux-amd64-cpu8 |
| 91 | + timeout-minutes: 5 |
| 92 | + permissions: |
| 93 | + contents: read |
| 94 | + issues: write |
| 95 | + packages: read |
| 96 | + container: |
| 97 | + image: ghcr.io/nvidia/openshell/ci:5b9daab9351b1e053f9a5e0ce4c899f5d3f674b0 |
| 98 | + credentials: |
| 99 | + username: ${{ github.actor }} |
| 100 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 101 | + strategy: |
| 102 | + fail-fast: false |
| 103 | + matrix: |
| 104 | + sdk: ${{ fromJSON(needs.load_config.outputs.matrix) }} |
| 105 | + steps: |
| 106 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 107 | + - uses: actions/download-artifact@3e5f45b2cfb9172054b4087a40e8e0b5a5461e7c # v8.0.1 |
| 108 | + with: |
| 109 | + name: sdk-sync-${{ matrix.sdk.name }} |
| 110 | + path: report |
| 111 | + - name: Read SDK status |
| 112 | + id: status |
| 113 | + run: | |
| 114 | + echo "has_drift=$(jq -r '.has_drift' report/status.json)" >> "$GITHUB_OUTPUT" |
| 115 | + echo "build_failed=$(jq -r '.build_failed' report/status.json)" >> "$GITHUB_OUTPUT" |
| 116 | + - name: Warn on drift detection error |
| 117 | + if: steps.status.outputs.has_drift == 'error' |
| 118 | + run: | |
| 119 | + echo "::error::Drift detection failed for ${{ matrix.sdk.name }} SDK" |
| 120 | + cat report/drift.stderr |
| 121 | + exit 1 |
| 122 | + - name: Install tools |
| 123 | + if: steps.status.outputs.has_drift == 'true' |
| 124 | + run: mise install --locked |
| 125 | + - name: Create or update drift issue |
| 126 | + if: steps.status.outputs.has_drift == 'true' |
| 127 | + env: |
| 128 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 129 | + run: | |
| 130 | + set +e |
| 131 | + RESULT=$(uv run python tasks/scripts/sdk_sync.py manage-issue \ |
| 132 | + --drift-report "$(cat report/drift.json)" \ |
| 133 | + --build-report "$(cat report/build.json)" \ |
| 134 | + --sdk "${{ matrix.sdk.name }}" \ |
| 135 | + --repo "$GITHUB_REPOSITORY" \ |
| 136 | + --label "${{ matrix.sdk.label }}") |
| 137 | + STATUS=$? |
| 138 | + set -e |
| 139 | + if ! printf '%s\n' "$RESULT" | jq .; then |
| 140 | + printf '%s\n' "$RESULT" |
| 141 | + fi |
| 142 | + if [ "$STATUS" -ne 0 ]; then |
| 143 | + echo "::error::Issue management command failed with exit code $STATUS" |
| 144 | + exit "$STATUS" |
| 145 | + fi |
| 146 | + if ! ACTION=$(printf '%s\n' "$RESULT" | jq -er '.action // "unknown"'); then |
| 147 | + ACTION=unknown |
| 148 | + fi |
| 149 | + if [ "$ACTION" != "created" ] && [ "$ACTION" != "updated" ]; then |
| 150 | + echo "::error::Issue management for ${{ matrix.sdk.name }} failed: $ACTION" |
| 151 | + exit 1 |
| 152 | + fi |
| 153 | + - name: Close resolved drift issue |
| 154 | + if: steps.status.outputs.has_drift == 'false' |
| 155 | + env: |
| 156 | + GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 157 | + run: | |
| 158 | + ISSUE=$(gh issue list --repo "$GITHUB_REPOSITORY" --label "${{ matrix.sdk.label }}" --state open --json number --jq '.[0].number') |
| 159 | + if [ -n "$ISSUE" ]; then |
| 160 | + gh issue close "$ISSUE" --repo "$GITHUB_REPOSITORY" --comment "The SDK proto drift check passed. Closing automatically." |
| 161 | + echo "Closed issue #$ISSUE" |
| 162 | + fi |
0 commit comments