Skip to content

Commit

Permalink
test error case [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 13, 2025
1 parent e7e0c88 commit 14f9cf3
Show file tree
Hide file tree
Showing 2 changed files with 114 additions and 73 deletions.
152 changes: 80 additions & 72 deletions .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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'
Expand All @@ -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: |
Expand All @@ -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
35 changes: 34 additions & 1 deletion tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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.* [email protected]: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)

0 comments on commit 14f9cf3

Please sign in to comment.