Skip to content

Commit

Permalink
Merge pull request #38 from lldelisle/improve_autoupdate
Browse files Browse the repository at this point in the history
Improve autoupdate round 3
  • Loading branch information
lldelisle authored Sep 26, 2024
2 parents 2d82800 + 57082df commit 5339425
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 6 deletions.
24 changes: 22 additions & 2 deletions .github/workflows/autoupdate.yml
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ jobs:
echo "Running autoupdate command..."
cd "$REPO"
# This may fail
planemo autoupdate . --skiplist "${{ github.workspace }}/autoupdate/${{ matrix.upstream_repo_owner }}_${{ matrix.upstream_repo_name }}_skip_list" > "${{ github.workspace }}/autoupdate.log" || errors="${errors}\nCannot autoupdate $REPO"
planemo autoupdate . --skiplist "${{ github.workspace }}/autoupdate/${{ matrix.upstream_repo_owner }}_${{ matrix.upstream_repo_name }}_skip_list" 2>&1 1> "${{ github.workspace }}/autoupdate.log" | tee "${{ github.workspace }}/autoupdate.err" || errors="${errors}\nCannot autoupdate $REPO, last line of stderr is\n$(tail -n 1 "${{ github.workspace }}/autoupdate.err")"
rm -f tool_test_output.* tools.yml
cd -
# Check if it changed something
Expand Down Expand Up @@ -124,7 +124,9 @@ jobs:
DIFF_BRANCH="origin/$REPO"
else
# Check if a closed PR exists with the same title
if gh_pr_list_out=$(gh pr list --search "is:closed is:unmerged '$TITLE' in:title" | grep -P "^\d+\t[^\t]+\tplanemo-autoupdate:" | head -n 1); then
if gh_pr_list_out=$(gh pr list --search "is:closed is:unmerged '$TITLE' in:title" | grep -P "^\d+\t[^\t]+\tplanemo-autoupdate:"); then
# Only take the first one
gh_pr_list_out=$(echo "$gh_pr_list_out" | head -n 1)
echo "Found a closed PR with title: $TITLE"
OLD_TITLE=$(echo "$gh_pr_list_out" | cut -f 2)
PR_EXISTS=1
Expand All @@ -150,6 +152,15 @@ jobs:
fi
fi
if ! git diff $DIFF_BRANCH --quiet $FILE_TO_CHECK; then
# Check if it is only the date in workflows
if [[ "$REPO" = "workflows/"* ]]; then
if [ $(git diff --numstat $DIFF_BRANCH $FILE_TO_CHECK | cut -f 1) = "1" ]; then
echo "A single line was added, probably the date, nothing is changed"
# clean up for the next repo
git checkout -- .
continue
fi
fi
echo "There are changes"
if [ "$PR_EXISTS" -eq 1 ]; then
# Check if the last commit of the existing branch was manual
Expand Down Expand Up @@ -206,6 +217,15 @@ jobs:
if [ ! -z "$errors" ]; then
echo "ERRORS OCCURED DURING AUTOUPDATE:"
echo -e $errors
# Write these errors to an issue
body="$(date), there were errors when running autoupdate\n\n$errors"
echo -e $body > body.txt
if gh_issue_list=$(gh issue list --author "planemo-autoupdate" | grep -P "^\d+\t[^\t]+\tAutoupdate errors\t"); then
gh issue comment $(echo "$gh_issue_list" | cut -f 1 | head -n 1) -F body.txt
else
gh issue create -t "Autoupdate errors" -F body.txt
fi
rm body.txt
exit 1
fi
working-directory: ./tools_repo
5 changes: 5 additions & 0 deletions pr_text.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,11 @@
"For any comments, queries or criticism about the bot, not related to the tool being updated in this PR, please create an issue [here](https://github.com/planemo-autoupdate/autoupdate/issues/new)."
)

# Add info on the strategy
text.append("\nIf you want to skip this change, close this PR without deleting the branch. It will be reopened if another change is detected.")
text.append("Any commit from another author than 'planemo-autoupdate' will prevent more auto-updates.")
text.append("To ignore manual changes and allow autoupdates, delete the branch.")

with open(args.out, "w") as f:
f.write("\n\n".join(text))

Expand Down
16 changes: 12 additions & 4 deletions pr_text_iwc.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,19 +28,27 @@
)

with open(args.log) as f:
already_reported = {}
for line in f.readlines():
if " -> " in line:
words = line.split()
from_version = words[1]
to_version = words[3]
text.append(f"* `{from_version}` should be updated to `{to_version}`")
new_changelog_lines.append(
f"- `{from_version}` was updated to `{to_version}`"
)
if to_version not in already_reported.get(from_version, []):
text.append(f"* `{from_version}` should be updated to `{to_version}`")
new_changelog_lines.append(
f"- `{from_version}` was updated to `{to_version}`"
)
already_reported[from_version] = already_reported.get(from_version, []) + [to_version]
if "The workflow release number has been updated" in line:
release_line = line
text.append(f"\n{release_line}")

# Add info on the strategy
text.append("\nIf you want to skip this change, close this PR without deleting the branch. It will be reopened if another change is detected.")
text.append("Any commit from another author than 'planemo-autoupdate' will prevent more auto-updates.")
text.append("To ignore manual changes and allow autoupdates, delete the branch.")

with open(args.out, "w") as f:
f.write("\n".join(text))

Expand Down

0 comments on commit 5339425

Please sign in to comment.