Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add github workflow to bump integrations core #33455

Merged
merged 4 commits into from
Jan 29, 2025
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions .github/workflows/bump_integrations_core.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
name: Bump Integrations Core

on:
workflow_dispatch:
schedule:
- cron: '0 4 * * 1,3' # Run on Monday, Wednesday at 4:00 UTC
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
permissions: {}

jobs:
bump_integrations_core:
runs-on: ubuntu-latest
permissions:
contents: write
pull-requests: write
steps:
- name: Checkout the main branch
uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
with:
fetch-depth: 0
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 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: Bump Integrations Core
run: |
inv release.bump-integrations-core --slack-webhook ${{ secrets.BUMP_INTEGRATIONS_CORE_SLACK_WEBHOOK }}

24 changes: 16 additions & 8 deletions tasks/libs/ciproviders/github_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,14 +641,11 @@ def get_user_query(login):
return query + string_var


def create_release_pr(title, base_branch, target_branch, version, changelog_pr=False, milestone=None):
def create_datadog_agent_pr(title, base_branch, target_branch, milestone_name, other_labels=None):
print(color_message("Creating PR", "bold"))

github = GithubAPI(repository=GITHUB_REPO_NAME)

# Find milestone based on what the next final version is. If the milestone does not exist, fail.
milestone_name = milestone or str(version)

milestone = github.get_milestone_by_name(milestone_name)

if not milestone or not milestone.number:
Expand Down Expand Up @@ -679,12 +676,10 @@ def create_release_pr(title, base_branch, target_branch, version, changelog_pr=F
labels = [
"changelog/no-changelog",
"qa/no-code-change",
"team/agent-delivery",
"team/agent-release-management",
]

if changelog_pr:
labels.append(f"backport/{get_default_branch()}")
if other_labels:
labels += other_labels

updated_pr = github.update_pr(
pull_number=pr.number,
Expand All @@ -704,6 +699,19 @@ def create_release_pr(title, base_branch, target_branch, version, changelog_pr=F
return updated_pr.html_url


def create_release_pr(title, base_branch, target_branch, version, changelog_pr=False, milestone=None):
milestone_name = milestone or str(version)

labels = [
"team/agent-delivery",
"team/agent-release-management",
]
if changelog_pr:
labels.append(f"backport/{get_default_branch()}")

return create_datadog_agent_pr(title, base_branch, target_branch, milestone_name, labels)


def ask_review_actor(pr):
for event in pr.get_issue_events():
if event.event == "labeled" and event.label.name == "ask-review":
Expand Down
15 changes: 11 additions & 4 deletions tasks/libs/common/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -254,16 +254,23 @@ def get_last_commit(ctx, repo, branch):
)


def get_git_references(ctx, repo, ref):
"""
Fetches a specific reference (ex: branch, tag, or HEAD) from a remote Git repository
"""
return ctx.run(
rf'git ls-remote https://github.com/DataDog/{repo} "{ref}"',
hide=True,
).stdout.strip()


def get_last_release_tag(ctx, repo, pattern):
import re
from functools import cmp_to_key

import semver

tags = ctx.run(
rf'git ls-remote -t https://github.com/DataDog/{repo} "{pattern}"',
hide=True,
).stdout.strip()
tags = get_git_references(ctx, repo, pattern)
if not tags:
raise Exit(
color_message(
Expand Down
3 changes: 2 additions & 1 deletion tasks/libs/releasing/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,9 @@
# The order matters, eg. when fetching matching tags for an Agent 6 entry,
# tags starting with 6 will be preferred to tags starting with 7.
COMPATIBLE_MAJOR_VERSIONS = {6: ["6", "7"], 7: ["7"]}
INTEGRATIONS_CORE_JSON_FIELD = "INTEGRATIONS_CORE_VERSION"
RELEASE_JSON_FIELDS_TO_UPDATE = [
"INTEGRATIONS_CORE_VERSION",
INTEGRATIONS_CORE_JSON_FIELD,
"OMNIBUS_SOFTWARE_VERSION",
"OMNIBUS_RUBY_VERSION",
"MACOS_BUILD_VERSION",
Expand Down
58 changes: 57 additions & 1 deletion tasks/release.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
from invoke import Failure, task
from invoke.exceptions import Exit

from tasks.libs.ciproviders.github_api import GithubAPI, create_release_pr
from tasks.libs.ciproviders.github_api import GithubAPI, create_datadog_agent_pr, create_release_pr
from tasks.libs.ciproviders.gitlab_api import get_gitlab_repo
from tasks.libs.common.color import Color, color_message
from tasks.libs.common.constants import (
Expand All @@ -32,6 +32,7 @@
check_clean_branch_state,
clone,
get_default_branch,
get_git_references,
get_last_commit,
get_last_release_tag,
is_agent6,
Expand All @@ -56,6 +57,7 @@
from tasks.libs.releasing.json import (
DEFAULT_BRANCHES,
DEFAULT_BRANCHES_AGENT6,
INTEGRATIONS_CORE_JSON_FIELD,
UNFREEZE_REPOS,
_get_release_json_value,
_save_release_json,
Expand Down Expand Up @@ -1340,3 +1342,57 @@ def check_previous_agent6_rc(ctx):
payload = {'message': err_msg}
send_slack_msg(ctx, payload, os.environ.get("SLACK_DATADOG_AGENT_CI_WEBHOOK"))
raise Exit(message=err_msg, code=1)


@task
def bump_integrations_core(ctx, slack_webhook=None):
"""
Create a PR to bump the integrations core fields in the release.json file
"""
if os.environ.get("GITHUB_ACTIONS"):
chouquette marked this conversation as resolved.
Show resolved Hide resolved
set_git_config('user.name', 'github-actions[bot]')
set_git_config('user.email', 'github-actions[bot]@users.noreply.github.com')

commit_hash = get_git_references(ctx, "integrations-core", "HEAD").split()[0]

rj = load_release_json()

for nightly in ["nightly", "nightly-a7"]:
rj[nightly][INTEGRATIONS_CORE_JSON_FIELD] = commit_hash

_save_release_json(rj)

main_branch = "main"
bump_integrations_core_branch = f"bump-integrations-core-{int(time.time())}"
ctx.run(f"git checkout -b {bump_integrations_core_branch}")
ctx.run("git add release.json")

commit_message = "Update integrations core to HEAD"
ok = try_git_command(ctx, f"git commit -m '{commit_message}'")
if not ok:
raise Exit(
color_message(
f"Could not create commit. Please commit manually with:\ngit commit -m {commit_message}\n, push the {bump_integrations_core_branch} branch and then open a PR against {main_branch}.",
"red",
),
code=1,
)

if not ctx.run(f"git push --set-upstream origin {bump_integrations_core_branch}", warn=True):
raise Exit(
color_message(
f"Could not push branch {bump_integrations_core_branch} to the upstream 'origin'. Please push it manually and then open a PR against {main_branch}.",
"red",
),
code=1,
)

# to find the correct current milestone 'devel' is set to False even though this will only run on development branches
current = current_version(ctx, 7)
current.rc = False
current.devel = False
pr_url = create_datadog_agent_pr(commit_message, main_branch, bump_integrations_core_branch, str(current))

if slack_webhook:
payload = {'pr_url': pr_url}
send_slack_msg(ctx, payload, slack_webhook)
Loading