Fix auto-updater upgrader
This commit is contained in:
parent
0a0cf347bd
commit
9248a59585
3 changed files with 68 additions and 33 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -6,6 +6,7 @@
|
||||||
builds
|
builds
|
||||||
tools/README-generator/venv/
|
tools/README-generator/venv/
|
||||||
tools/bot-repo-cleanup/.github_token
|
tools/bot-repo-cleanup/.github_token
|
||||||
|
tools/autoupdater-upgrader/.*
|
||||||
|
|
||||||
tools/autopatches/login
|
tools/autopatches/login
|
||||||
tools/autopatches/token
|
tools/autopatches/token
|
||||||
|
|
|
@ -10,5 +10,7 @@ source venv/bin/activate
|
||||||
pip install -r requirements.txt
|
pip install -r requirements.txt
|
||||||
```
|
```
|
||||||
|
|
||||||
This script requires a `.github_token` file with a token with public.repo permission.
|
This script requires the following files:
|
||||||
|
- `.github_token` containing a token with `public.repo` and `workflow` permission
|
||||||
|
- `.github_login` containing the author's username
|
||||||
|
- `.github_email` containing the author's email address
|
||||||
|
|
|
@ -4,11 +4,12 @@ import sys, os, time
|
||||||
import urllib.request, json
|
import urllib.request, json
|
||||||
import re
|
import re
|
||||||
|
|
||||||
|
from github import Github
|
||||||
|
import github
|
||||||
|
|
||||||
# Debug
|
# Debug
|
||||||
from rich.traceback import install
|
from rich.traceback import install
|
||||||
install(show_locals=True)
|
install(width=150, show_locals=True, locals_max_length=None, locals_max_string=None)
|
||||||
|
|
||||||
from github import Github
|
|
||||||
|
|
||||||
#####
|
#####
|
||||||
#
|
#
|
||||||
|
@ -22,6 +23,9 @@ g = Github(open(".github_token").read().strip())
|
||||||
# Path to the file to be updated
|
# Path to the file to be updated
|
||||||
path=".github/workflows/updater.yml"
|
path=".github/workflows/updater.yml"
|
||||||
|
|
||||||
|
# Title of the PR
|
||||||
|
title="[autopatch] Upgrade auto-updater"
|
||||||
|
|
||||||
# Body of the PR message
|
# Body of the PR message
|
||||||
body="""
|
body="""
|
||||||
Auto-updater actions need upgrading to continue working:
|
Auto-updater actions need upgrading to continue working:
|
||||||
|
@ -29,9 +33,21 @@ Auto-updater actions need upgrading to continue working:
|
||||||
- peter-evans/create-pull-request@v4
|
- peter-evans/create-pull-request@v4
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
# Author of the commit
|
||||||
|
author=github.InputGitAuthor(open(".github_login").read().strip(), open(".github_email").read().strip())
|
||||||
|
|
||||||
# Name of the branch created for the PR
|
# Name of the branch created for the PR
|
||||||
new_branch="upgrade-auto-updater"
|
new_branch="upgrade-auto-updater"
|
||||||
|
|
||||||
|
#####
|
||||||
|
#
|
||||||
|
# CACHE
|
||||||
|
#
|
||||||
|
#####
|
||||||
|
|
||||||
|
with open('processed.txt') as f:
|
||||||
|
processed = f.read().splitlines()
|
||||||
|
|
||||||
#####
|
#####
|
||||||
#
|
#
|
||||||
# CRAWL REPOSITORIES
|
# CRAWL REPOSITORIES
|
||||||
|
@ -42,25 +58,34 @@ u = g.get_user("yunohost-bot")
|
||||||
org = g.get_organization("yunohost-apps")
|
org = g.get_organization("yunohost-apps")
|
||||||
|
|
||||||
# For each repositories belonging to the bot (user `u`)
|
# For each repositories belonging to the bot (user `u`)
|
||||||
|
i=0
|
||||||
for repo in org.get_repos():
|
for repo in org.get_repos():
|
||||||
# Determine base branch, either `testing` or default branch
|
if repo.full_name not in processed:
|
||||||
try:
|
|
||||||
base_branch = repo.get_branch("testing").name
|
# Determine base branch, either `testing` or default branch
|
||||||
except:
|
try:
|
||||||
base_branch = repo.default_branch
|
base_branch = repo.get_branch("testing").name
|
||||||
# Make sure the repository has an auto-updater
|
except:
|
||||||
try:
|
base_branch = repo.default_branch
|
||||||
repo.get_contents(path, ref="refs/heads/"+base_branch)
|
|
||||||
except:
|
# Make sure the repository has an auto-updater
|
||||||
print("No updater in "+repo.full_name)
|
try:
|
||||||
continue
|
repo.get_contents(path, ref="refs/heads/"+base_branch)
|
||||||
# Process the repo
|
except:
|
||||||
try:
|
with open('processed.txt', 'a') as pfile:
|
||||||
|
pfile.write(repo.full_name+'\n')
|
||||||
|
time.sleep(1.5)
|
||||||
|
continue
|
||||||
|
|
||||||
|
# Process the repo
|
||||||
print("Processing "+repo.full_name)
|
print("Processing "+repo.full_name)
|
||||||
|
|
||||||
# Get the commit base for the new branch, and create it
|
try:
|
||||||
commit_sha = repo.get_branch(base_branch).commit.sha
|
# Get the commit base for the new branch, and create it
|
||||||
new_branch_ref = repo.create_git_ref(ref="refs/heads/"+new_branch, sha=commit_sha)
|
commit_sha = repo.get_branch(base_branch).commit.sha
|
||||||
|
new_branch_ref = repo.create_git_ref(ref="refs/heads/"+new_branch, sha=commit_sha)
|
||||||
|
except:
|
||||||
|
new_branch_ref = repo.get_git_ref(ref="heads/"+new_branch)
|
||||||
|
|
||||||
# Get current file contents
|
# Get current file contents
|
||||||
contents = repo.get_contents(path, ref=new_branch_ref.ref)
|
contents = repo.get_contents(path, ref=new_branch_ref.ref)
|
||||||
|
@ -69,19 +94,26 @@ for repo in org.get_repos():
|
||||||
updater_yml = contents.decoded_content.decode("unicode_escape")
|
updater_yml = contents.decoded_content.decode("unicode_escape")
|
||||||
updater_yml = re.sub(r'(?m)uses: actions/checkout@v[\d]+', "uses: actions/checkout@v3", updater_yml)
|
updater_yml = re.sub(r'(?m)uses: actions/checkout@v[\d]+', "uses: actions/checkout@v3", updater_yml)
|
||||||
updater_yml = re.sub(r'(?m)uses: peter-evans/create-pull-request@v[\d]+', "uses: peter-evans/create-pull-request@v4", updater_yml)
|
updater_yml = re.sub(r'(?m)uses: peter-evans/create-pull-request@v[\d]+', "uses: peter-evans/create-pull-request@v4", updater_yml)
|
||||||
updated = repo.update_file(path=contents.path,
|
updated = repo.update_file(contents.path,
|
||||||
message="Upgrade auto-updater",
|
message=title,
|
||||||
content=updater_yml,
|
content=updater_yml,
|
||||||
sha=contents.sha,
|
sha=contents.sha,
|
||||||
branch=new_branch)
|
branch=new_branch,
|
||||||
|
author=author)
|
||||||
|
|
||||||
|
# Wait a bit to preserve the API rate limit
|
||||||
|
time.sleep(1.5)
|
||||||
|
|
||||||
# Open the PR
|
# Open the PR
|
||||||
pr = repo.create_pull(title="Upgrade auto-updater", body=body, head=new_branch, base=base_branch)
|
pr = repo.create_pull(title="Upgrade auto-updater", body=body, head=new_branch, base=base_branch)
|
||||||
|
|
||||||
print(repo.full_name+" updated with PR \#"+ pr.id)
|
print(repo.full_name+" updated with PR #"+ str(pr.id))
|
||||||
break
|
i=i+1
|
||||||
except Exception as e:
|
|
||||||
print(e)
|
# Wait a bit to preserve the API rate limit
|
||||||
print("...failed. Deleting new branch.")
|
time.sleep(1.5)
|
||||||
repo.get_git_ref("heads/"+new_branch).delete()
|
|
||||||
break
|
with open('processed.txt', 'a') as pfile:
|
||||||
|
pfile.write(repo.full_name+'\n')
|
||||||
|
|
||||||
|
print("Done. "+str(i)+" repos processed")
|
||||||
|
|
Loading…
Reference in a new issue