# Copyright (c) 2025, NVIDIA CORPORATION. All rights reserved. # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. name: Approve Test Queue on: schedule: - cron: '*/5 * * * *' # Runs every 5 minutes workflow_dispatch: # Allows manual triggering jobs: approve-queue: runs-on: ubuntu-latest environment: main steps: - name: Checkout repository uses: actions/checkout@v4 - name: Set up Python uses: actions/setup-python@v5 with: python-version: "3.12" - name: Install dependencies run: | python -m pip install --upgrade pip pip install requests - name: Approve waiting deployments env: GITHUB_TOKEN: ${{ secrets.PAT }} MAX_CONCURRENCY: ${{ vars.MAX_CONCURRENCY || 1 }} run: | python - <= MAX_CONCURRENCY: print("Maximum concurrency reached, no new approvals will be made") exit(0) # Get waiting CI workflows for test environment print("Fetching deployments...") pending_workflows = get_workflow_runs("waiting") pending_workflows = [run for run in pending_workflows if run["name"] == "CICD NeMo"] # Sort deployments by creation date (oldest first) print("Sorting workflows...") pending_workflows = sorted(pending_workflows, key=lambda x: x["created_at"]) # Process each deployment print("Processing ...") for workflow in pending_workflows: if total_workflows >= MAX_CONCURRENCY: print("Maximum concurrency reached, stopping approvals") break workflow_id = workflow["id"] workflow_name = workflow["display_title"] print(f"Approving workflow {workflow_name} with Run Id: {workflow_id}") deployment_url = f"actions/runs/{workflow_id}/pending_deployments" deployment = make_request(deployment_url)[0] environment_id = deployment["environment"]["id"] # Approve the deployment status_data = { "environment_ids": [environment_id], "state": "approved", "comment": "Automatically approved by queue manager" } result = make_request(deployment_url, method="POST", data=status_data) if result: total_workflows += 1 else: print(f"Failed to approve deployment {deployment['id']}") exit(1) EOF notify: if: failure() runs-on: ubuntu-latest needs: [approve-queue] steps: - name: Notify env: SLACK_WEBHOOK: ${{ secrets.SLACK_WEBHOOK }} SLACK_WEBHOOK_ADMIN: GITHUB_RUN_ID: ${{ github.run_id }} GITHUB_REPOSITORY: ${{ github.repository }} run: | curl -X POST \ -H 'Content-type: application/json' \ --data "{\"text\":\":robot_joy: failed. Please review manually.\n\ncc ${SLACK_WEBHOOK_ADMIN}\"}" \ $SLACK_WEBHOOK