Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
20 changes: 8 additions & 12 deletions .github/workflows/update-kube-stack-version.yml
Original file line number Diff line number Diff line change
Expand Up @@ -21,10 +21,15 @@ jobs:
with:
python-version: '3.13'

- name: Set up Git configuration
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"

- name: Run kube-stack version update script
run: |
cd scripts
python update_kube_stack_version.py
python update_kube_stack_version.py --prepare-git

- name: Check for changes
id: verify-changed-files
Expand All @@ -35,18 +40,9 @@ jobs:
echo "changed=false" >> $GITHUB_OUTPUT
fi

- name: Commit and push changes
if: steps.verify-changed-files.outputs.changed == 'true'
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git add docset.yml
git commit -m "chore: update kube-stack version [skip ci]"
git push

- name: Create Pull Request
if: steps.verify-changed-files.outputs.changed == 'true'
uses: peter-evans/create-pull-request@v5
uses: peter-evans/create-pull-request@v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: "chore: update kube-stack version"
Expand All @@ -58,7 +54,7 @@ jobs:
- Updated kube-stack version in docset.yml

This PR was created automatically by the weekly kube-stack version update workflow.
branch: update-kube-stack-version
branch: update-kube-stack-version-${{ github.run_id }}
delete-branch: true
labels: |
automated
Expand Down
58 changes: 53 additions & 5 deletions scripts/update_kube_stack_version.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,19 +18,24 @@
import sys
import argparse
import subprocess
import os
import datetime
from pathlib import Path


def fetch_url_content(url):
"""Fetch content from a URL"""
try:
print(f"Attempting to fetch: {url}")
with urllib.request.urlopen(url) as response:
with urllib.request.urlopen(url, timeout=30) as response:
content = response.read().decode('utf-8')
return content
except urllib.error.URLError as e:
print(f"Failed to retrieve content: {e.reason}")
return None
except Exception as e:
print(f"Unexpected error fetching URL: {e}")
return None


def get_latest_collector_version():
Expand All @@ -40,7 +45,11 @@ def get_latest_collector_version():

# Run git command to get the latest semantic version tag
cmd = ['git', 'ls-remote', '--tags', 'https://github.com/elastic/elastic-agent.git']
result = subprocess.run(cmd, capture_output=True, text=True, check=True)
result = subprocess.run(cmd, capture_output=True, text=True, check=True, timeout=60)

if not result.stdout.strip():
print("No output from git ls-remote command")
return None

# Extract version tags and find the latest semantic version
tags = []
Expand All @@ -67,8 +76,13 @@ def version_key(tag):
print(f"Latest collector version: {version}")
return version

except subprocess.TimeoutExpired:
print("Timeout while fetching tags from elastic-agent repository")
return None
except subprocess.CalledProcessError as e:
print(f"Error fetching tags from elastic-agent repository: {e}")
if e.stderr:
print(f"Error details: {e.stderr}")
return None
except Exception as e:
print(f"Error getting latest collector version: {e}")
Expand Down Expand Up @@ -146,10 +160,34 @@ def update_docset_kube_stack_version(version, docset_path, dry_run=False):
return False


def prepare_git_changes(version, dry_run=False):
"""Prepare git changes for PR creation (used by GitHub Actions)"""
if dry_run:
print(f"[DRY RUN] Would prepare git changes for kube-stack version {version}")
return True

try:
# Add and commit changes
subprocess.run(['git', 'add', 'docset.yml'], check=True)
subprocess.run(['git', 'commit', '-m', f'chore: update kube-stack version to {version} [skip ci]'], check=True)

print(f"Git changes prepared for kube-stack version {version}")
return True

except subprocess.CalledProcessError as e:
print(f"Error preparing git changes: {e}")
return False
except Exception as e:
print(f"Error preparing git changes: {e}")
return False


def main():
parser = argparse.ArgumentParser(description='Update kube-stack version in docset.yml')
parser.add_argument('--dry-run', action='store_true',
help='Show what would be updated without making changes')
parser.add_argument('--prepare-git', action='store_true', default=False,
help='Prepare git changes for PR creation (used by GitHub Actions)')
args = parser.parse_args()

# Get the script directory and construct paths relative to it
Expand Down Expand Up @@ -178,10 +216,20 @@ def main():
success = update_docset_kube_stack_version(kube_stack_version, docset_path, args.dry_run)

if success:
print("Kube-stack version update completed successfully")
sys.exit(0)
if args.prepare_git:
# Prepare git changes for GitHub Actions PR creation
git_success = prepare_git_changes(kube_stack_version, args.dry_run)
if git_success:
print("Kube-stack version update and git changes prepared successfully")
sys.exit(0)
else:
print("Kube-stack version updated but git preparation failed")
sys.exit(1)
else:
print("Kube-stack version update completed successfully")
sys.exit(0)
else:
print("No update was needed")
print("No update was needed - kube-stack version is already up to date")
sys.exit(0)


Expand Down
Loading