From 14f9cf3c3301a984ff953acdaaa18fc0f25719b3 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" <41898282+github-actions[bot]@users.noreply.github.com> Date: Sun, 12 Jan 2025 23:24:27 -0500 Subject: [PATCH] test error case [skip ci] --- .github/workflows/create_rc_pr.yml | 152 +++++++++++++++-------------- tasks/release.py | 35 ++++++- 2 files changed, 114 insertions(+), 73 deletions(-) diff --git a/.github/workflows/create_rc_pr.yml b/.github/workflows/create_rc_pr.yml index 61ab14fa861b1b..ffdcdf9c2f82be 100644 --- a/.github/workflows/create_rc_pr.yml +++ b/.github/workflows/create_rc_pr.yml @@ -10,7 +10,9 @@ on: env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} AGENT6_RELEASE_BRANCH: '6.53.x' - IS_AGENT6_RELEASE: ${{ github.event.schedule == '0 9 * * 1' }} + AGENT_CI_ONCALL_CHANNEL: 'C085P12CTFX' + # IS_AGENT6_RELEASE: ${{ github.event.schedule == '0 9 * * 1' }} + IS_AGENT6_RELEASE: 'true' permissions: {} jobs: @@ -20,28 +22,8 @@ jobs: branches: ${{ steps.branches.outputs.value }} warning: ${{ steps.warning.outputs.value }} steps: - - name: Check if agent 6 rc PR already exists - if: ${{ env.IS_AGENT6_RELEASE == 'true' }} - run: | - prs=$(gh pr list \ - --repo "$GITHUB_REPOSITORY" \ - --base "$AGENT6_RELEASE_BRANCH" \ - --json url,title \ - --draft=false \ - --search "Update release.json and Go modules for in:title") - - if [ "$(echo "$prs" | jq 'length')" -gt 0 ]; then - pr_list=$(echo "$prs" | jq -r '.[] | "- \(.title): \(.url)"') - error_message="AGENT 6 ERROR: The following Agent 6 release candidate PRs already exist. Please address these PRs before creating a new release candidate:\n$pr_list" - curl -X POST -H 'Content-Type: application/json' \ - --data "{ 'channel_id': 'C0701E5KYSX', 'message': '$error_message' }" \ - ${{ secrets.SLACK_DATADOG_AGENT_CI_WEBHOOK }} - echo -e "\n$error_message" - exit 1 - fi - - name: Checkout repository - + uses: actions/checkout@0ad4b8fadaa221de15dcec353f45205ec38ea70b # v4.1.4 with: sparse-checkout: 'tasks' @@ -62,6 +44,32 @@ jobs: pip install -r tasks/libs/requirements-github.txt pip install -r tasks/requirements_release_tasks.txt + - name: Check if agent 6 rc PR already exists + if: ${{ env.IS_AGENT6_RELEASE == 'true' }} + run: | + prs=$(gh pr list \ + --repo "$GITHUB_REPOSITORY" \ + --base "$AGENT6_RELEASE_BRANCH" \ + --json url,title \ + --draft=false \ + --search "Update release.json and Go modules for in:title") + + if [ "$(echo "$prs" | jq 'length')" -gt 0 ]; then + pr_list=$(echo "$prs" | jq -r '.[] | "- \(.title): \(.url)"') + error_message="AGENT 6 ERROR: The following Agent 6 release candidate PRs already exist. Please address these PRs before creating a new release candidate:\n$pr_list" + inv release.send-slack-msg ${{ env.AGENT_CI_ONCALL_CHANNEL }} $error_message + echo -e "\n$error_message" + exit 1 + fi + - name: Check if an Agent 6 build pipeline has run in the past week + if: ${{ env.IS_AGENT6_RELEASE == 'true' }} + run: | + err_msg=$(inv release.check-agent6-build-status ${{ env.AGENT_CI_ONCALL_CHANNEL }}) + if [-n "$err_msg" ]; then + echo "$err_msg" + exit 1 + fi + - name: Determine the release active branches id: branches run: | @@ -77,57 +85,57 @@ jobs: run: | echo "value=-w" >> $GITHUB_OUTPUT - create_rc_pr: - runs-on: ubuntu-latest - needs: find_release_branches - permissions: - contents: write - pull-requests: write - strategy: - matrix: - value: ${{fromJSON(needs.find_release_branches.outputs.branches)}} - fail-fast: false - steps: - - name: Checkout the main branch - uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 - with: - persist-credentials: true + # create_rc_pr: + # runs-on: ubuntu-latest + # needs: find_release_branches + # permissions: + # contents: write + # pull-requests: write + # strategy: + # matrix: + # value: ${{fromJSON(needs.find_release_branches.outputs.branches)}} + # fail-fast: false + # steps: + # - name: Checkout the main branch + # uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2 + # with: + # persist-credentials: true - - name: Install python - uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 - with: - python-version-file: .python-version - cache: "pip" + # - name: Install python + # uses: actions/setup-python@0b93645e9fea7318ecaed2b359559ac225c90a2b # v5.3.0 + # with: + # python-version-file: .python-version + # cache: "pip" - - name: Install Python dependencies - run: | - python -m pip install --upgrade pip - pip install -r requirements.txt - pip install -r tasks/libs/requirements-github.txt - pip install -r tasks/requirements_release_tasks.txt + # - name: Install Python dependencies + # run: | + # python -m pip install --upgrade pip + # pip install -r requirements.txt + # pip install -r tasks/libs/requirements-github.txt + # pip install -r tasks/requirements_release_tasks.txt - - name: Check for changes since last RC - id: check_for_changes - env: - ATLASSIAN_USERNAME: ${{ secrets.ATLASSIAN_USERNAME }} - ATLASSIAN_PASSWORD: ${{ secrets.ATLASSIAN_PASSWORD }} - SLACK_API_TOKEN : ${{ secrets.SLACK_DATADOG_AGENT_BOT_TOKEN }} - MATRIX: ${{ matrix.value }} - WARNING: ${{ needs.find_release_branches.outputs.warning }} - run: | - if [ -n "${{ needs.find_release_branches.outputs.warning }}" ]; then - echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX" "$WARNING")" >> $GITHUB_OUTPUT - else - echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX")" >> $GITHUB_OUTPUT - fi + # - name: Check for changes since last RC + # id: check_for_changes + # env: + # ATLASSIAN_USERNAME: ${{ secrets.ATLASSIAN_USERNAME }} + # ATLASSIAN_PASSWORD: ${{ secrets.ATLASSIAN_PASSWORD }} + # SLACK_API_TOKEN : ${{ secrets.SLACK_DATADOG_AGENT_BOT_TOKEN }} + # MATRIX: ${{ matrix.value }} + # WARNING: ${{ needs.find_release_branches.outputs.warning }} + # run: | + # if [ -n "${{ needs.find_release_branches.outputs.warning }}" ]; then + # echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX" "$WARNING")" >> $GITHUB_OUTPUT + # else + # echo "CHANGES=$(inv -e release.check-for-changes -r "$MATRIX")" >> $GITHUB_OUTPUT + # fi - - name: Create RC PR - if: ${{ steps.check_for_changes.outputs.CHANGES == 'true' || env.IS_AGENT6_RELEASE == 'true' }} - env: - MATRIX: ${{ matrix.value }} - run: | - if ${{ env.IS_AGENT6_RELEASE == 'true' }}; then - inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT6_RELEASE_SLACK_WEBHOOK }} --patch-version - else - inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }} - fi + # - name: Create RC PR + # if: ${{ steps.check_for_changes.outputs.CHANGES == 'true' || env.IS_AGENT6_RELEASE == 'true' }} + # env: + # MATRIX: ${{ matrix.value }} + # run: | + # if ${{ env.IS_AGENT6_RELEASE == 'true' }}; then + # inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT6_RELEASE_SLACK_WEBHOOK }} --patch-version + # else + # inv -e release.create-rc -r "$MATRIX" --slack-webhook=${{ secrets.AGENT_RELEASE_SYNC_SLACK_WEBHOOK }} + # fi diff --git a/tasks/release.py b/tasks/release.py index 87295516eeb98a..ed144058127fb3 100644 --- a/tasks/release.py +++ b/tasks/release.py @@ -13,9 +13,12 @@ import tempfile import time from collections import defaultdict -from datetime import date +from datetime import date, datetime from time import sleep +from datadog_api_client import ApiClient, Configuration +from datadog_api_client.v2.api.ci_visibility_pipelines_api import CIVisibilityPipelinesApi +from dateutil.relativedelta import relativedelta from gitlab import GitlabError from invoke import task from invoke.exceptions import Exit @@ -1266,3 +1269,33 @@ def update_current_milestone(ctx, major_version: int = 7, upstream="origin"): milestone_branch, next, ) + + +@task +def send_slack_msg(ctx, channel_id, message, webhook=None): + webhook = webhook or os.environ.get("SLACK_DATADOG_AGENT_CI_WEBHOOK") + payload = { + "channel_id": channel_id, + "message": message, + } + ctx.run(f"curl -X POST -H 'Content-Type: application/json' --data '{json.dumps(payload)}' {webhook}") + + +@task +def check_agent6_build_status(ctx, channel_id): + """ + Checks if there has been an agent 6 build in the last week + """ + configuration = Configuration() + with ApiClient(configuration) as api_client: + api_instance = CIVisibilityPipelinesApi(api_client) + response = api_instance.list_ci_app_pipeline_events( + filter_query='ci_level:pipeline @ci.pipeline.name:"DataDog/datadog-agent" @git.tag:6.53.* -@ci.pipeline.downstream:true', + filter_from=(datetime.now() + relativedelta(days=-1)), + filter_to=datetime.now(), + page_limit=5, + ) + if not response.data: + err_msg = "AGENT 6 ERROR: No Agent 6 build pipelines have run in the past week. Please trigger a build pipeline for the next agent 6 release candidate." + send_slack_msg(ctx, channel_id, err_msg) + print(err_msg)