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

Automate the since updater #7240

Merged
merged 3 commits into from
Sep 12, 2024
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
41 changes: 41 additions & 0 deletions .github/workflows/run-since-updater.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: Run update-since-todo.py

on:
schedule:
- cron: "0 16 * * THU"
workflow_dispatch:

permissions:
contents: write
pull-requests: write

jobs:
since_updater:
runs-on: ubuntu-latest
if: ${{ github.repository_owner == 'jenkinsci' }}
steps:
- uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Run update-since-todo.py
run: |
body=$(./update-since-todo.py)

{
echo 'PROGRESS<<EOF'
echo "${body}"
echo 'EOF'
} >> $GITHUB_OUTPUT
id: run_script
shell: bash
- name: Create Pull Request
uses: peter-evans/create-pull-request@8867c4aba1b742c39f8d0ba35429c2dfa4b6cb20 # v7
with:
token: ${{ secrets.GITHUB_TOKEN }}
commit-message: Fill in since annotations
title: Fill in since annotations
body: ${{ steps.run_script.outputs.PROGRESS }}
base: master
labels: skip-changelog
branch: actions/update-since-todo
delete-branch: true
16 changes: 12 additions & 4 deletions update-since-todo.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import argparse
import fileinput
import io
import os
import shutil
import subprocess

Expand All @@ -18,7 +19,7 @@ def update_file(file, lineno, old, new):
:param old: The old substring.
:param new: The new substring.
"""
print("\tUpdating file in place")
print("* Updating file in place")
with fileinput.FileInput(file, inplace=True) as f:
for line in f:
if f.lineno() == lineno and old in line:
Expand All @@ -44,13 +45,13 @@ def analyze_file(file, lineno, commits_and_tags, dry_run=False):
.split("\n", 1)[0]
.split(" ", 1)[0]
)
print(f"\tfirst sha: {line_sha}")
print(f"* first sha: {line_sha}")
first_tag = subprocess.check_output(
[GIT, "tag", "--sort=creatordate", "--contains", line_sha, "jenkins-*"],
text=True,
).split("\n", 1)[0]
if first_tag:
print(f"\tfirst tag was {first_tag}")
print(f"* first tag was {first_tag}")
commits_and_tags[line_sha] = first_tag
if not dry_run:
since_version = first_tag.replace("jenkins-", "")
Expand All @@ -75,10 +76,11 @@ def analyze_file(file, lineno, commits_and_tags, dry_run=False):

else:
print(
"\tNot updating file, no tag found. "
"* Not updating file, no tag found. "
"Normal if the associated PR/commit is not merged and released yet; "
"otherwise make sure to fetch tags from jenkinsci/jenkins"
)
print() # Add a newline for markdown rendering


def analyze_files(commits_and_tags, dry_run=False):
Expand All @@ -99,6 +101,10 @@ def analyze_files(commits_and_tags, dry_run=False):
"*.jelly",
"*.js",
]

runningInCI = os.environ.get("CI", "false") == "true"
if runningInCI:
print("<details><summary>Detailed output</summary>\n\n")
with subprocess.Popen(cmd, stdout=subprocess.PIPE) as proc:
for line in io.TextIOWrapper(proc.stdout):
parts = line.rstrip().split(":", 2)
Expand All @@ -107,6 +113,8 @@ def analyze_files(commits_and_tags, dry_run=False):
if retcode:
raise subprocess.CalledProcessError(retcode, cmd)
print()
if runningInCI:
print("</details>\n")


def display_results(commits_and_tags):
Expand Down
Loading