Skip to content

Commit

Permalink
refactor: check for pr and build error [skip ci]
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Jan 14, 2025
1 parent de851c1 commit 8b676db
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 84 deletions.
128 changes: 54 additions & 74 deletions .github/workflows/create_rc_pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,8 @@ on:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
AGENT6_RELEASE_BRANCH: '6.53.x'
AGENT_CI_ONCALL_CHANNEL: 'C0701E5KYSX'
SLACK_DATADOG_AGENT_CI_WEBHOOK: ${{ secrets.SLACK_DATADOG_AGENT_CI_WEBHOOK }}
IS_AGENT6_RELEASE: ${{ github.event.schedule == '0 9 * * 1' }}
# IS_AGENT6_RELEASE: ${{ github.event.schedule == '0 9 * * 1' }}
IS_AGENT6_RELEASE: 'true'
permissions: {}

jobs:
Expand Down Expand Up @@ -42,33 +41,14 @@ jobs:
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' }}
env:
DD_SITE: 'datadoghq.com'
DD_API_KEY: ${{ secrets.DD_API_KEY }}
DD_APP_KEY: ${{ secrets.DD_APP_KEY }}
SLACK_DATADOG_AGENT_CI_WEBHOOK: ${{ secrets.SLACK_DATADOG_AGENT_CI_WEBHOOK }}
run: |
error_message=$(inv release.check-agent6-build-status ${{ env.AGENT_CI_ONCALL_CHANNEL }} | tail -n 1)
if [ -n "$error_message" ]; then
echo -e "$error_message"
exit 1
fi
inv -e release.check-previous-agent6-rc
- name: Determine the release active branches
id: branches
Expand All @@ -85,57 +65,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
9 changes: 7 additions & 2 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,13 @@ def get_pulls(self, milestone=None, labels=None):
issues = self._repository.get_issues(milestone=m, state='all', labels=labels)
return [i.as_pull_request() for i in issues if i.pull_request is not None]

def get_pr_for_branch(self, branch_name):
return self._repository.get_pulls(state="open", head=f'DataDog:{branch_name}')
def get_pr_for_branch(self, head_branch_name=None, base_branch_name=None):
query_params = {"state": "open"}
if head_branch_name:
query_params["head"] = f'DataDog:{head_branch_name}'
if base_branch_name:
query_params["base"] = base_branch_name
return self._repository.get_pulls(**query_params)

def get_tags(self, pattern=""):
"""
Expand Down
29 changes: 22 additions & 7 deletions tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -1271,7 +1271,6 @@ def update_current_milestone(ctx, major_version: int = 7, upstream="origin"):
)


@task
def send_slack_msg(ctx, channel_id, message, webhook=None):
webhook = webhook or os.environ.get("SLACK_DATADOG_AGENT_CI_WEBHOOK")
payload = {
Expand All @@ -1282,20 +1281,36 @@ def send_slack_msg(ctx, channel_id, message, webhook=None):


@task
def check_agent6_build_status(ctx, channel_id):
def check_previous_agent6_rc(ctx):
"""
Checks if there is an agent 6 build pipeline in the last week
Validates that there are no existing Agent 6 release candidate pull requests
and checks if an Agent 6 build pipeline has been run in the past week
"""
err_msg = ""
agent6_prs = ""
github = GithubAPI()
prs = github.get_pr_for_branch(None, "6.53.x")
for pr in prs:
if "Update release.json and Go modules for 6.53" in pr.title and pr.draft:
agent6_prs += f"\n- {pr.title}: {pr.url}"
if agent6_prs:
err_msg += "AGENT 6 ERROR: The following Agent 6 release candidate PRs already exist. Please address these PRs before creating a new release candidate"
err_msg += agent6_prs

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=-7)),
filter_from=(datetime.now() + relativedelta(days=-1)),
filter_to=datetime.now(),
page_limit=5,
)
if not response.data:
err_msg = "\nAGENT 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)
err_msg += "\nAGENT 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."

if err_msg:
print(err_msg)
agent_ci_oncall_channel_id = 'C0701E5KYSX'
send_slack_msg(ctx, "C085P12CTFX", err_msg)
sys.exit(1)
2 changes: 1 addition & 1 deletion tasks/requirements_release_tasks.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ atlassian-python-api==3.41.3
yattag==1.15.2
reno==3.5.0
pandoc==2.4
types-python-dateutil==2.9.0
types-python-dateutil==2.9.0.20241206

0 comments on commit 8b676db

Please sign in to comment.