mirror of
https://github.com/f-droid/fdroidserver.git
synced 2025-09-13 06:22:27 +03:00
gitlab-ci: update gradle: job to only check files in
While we are at it, also upgrade to Debian/trixie and rules: this now handles making the merge requests: https://gitlab.com/fdroid/gradle-transparency-log/-/merge_requests/2
This commit is contained in:
parent
c6c4764b33
commit
97b0b0eaf8
2 changed files with 9 additions and 82 deletions
|
@ -467,35 +467,20 @@ macOS:
|
|||
|
||||
|
||||
gradle:
|
||||
image: debian:bookworm-slim
|
||||
rules:
|
||||
- if: "$PERSONAL_ACCESS_TOKEN"
|
||||
image: debian:trixie-slim
|
||||
<<: *apt-template
|
||||
variables:
|
||||
GIT_DEPTH: 1000
|
||||
rules:
|
||||
- changes:
|
||||
- .gitlab-ci.yml
|
||||
- gradlew-fdroid
|
||||
- makebuildserver
|
||||
script:
|
||||
- apt-get install
|
||||
ca-certificates
|
||||
git
|
||||
openssh-client
|
||||
python3-bs4
|
||||
python3-colorama
|
||||
python3-git
|
||||
python3-gitlab
|
||||
python3-packaging
|
||||
python3-requests
|
||||
# if this is a merge request fork, then only check if relevant files changed
|
||||
- if [ "$CI_PROJECT_NAMESPACE" != "fdroid" ]; then
|
||||
set -x;
|
||||
git fetch https://gitlab.com/fdroid/fdroidserver.git;
|
||||
for f in `git diff --name-only --diff-filter=d FETCH_HEAD...HEAD`; do
|
||||
test "$f" == "makebuildserver" && export CHANGED="$f $CHANGED";
|
||||
test "$f" == "gradlew-fdroid" && export CHANGED="$f $CHANGED";
|
||||
done;
|
||||
test -z "$CHANGED" && exit;
|
||||
echo $CHANGED;
|
||||
set +x;
|
||||
fi
|
||||
- ./tests/gradle-release-checksums.py
|
||||
|
||||
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import git
|
||||
import gitlab
|
||||
import os
|
||||
import re
|
||||
import requests
|
||||
|
@ -90,62 +88,6 @@ plugin_v_pat = re.compile(r'\nplugin_v=\(([0-9. ]+)\)')
|
|||
with open('gradlew-fdroid', 'w') as fp:
|
||||
fp.write(plugin_v_pat.sub('\nplugin_v=(%s)' % plugin_v, gradlew_fdroid))
|
||||
|
||||
if os.getenv('CI_PROJECT_NAMESPACE') != 'fdroid':
|
||||
p = subprocess.run(['git', '--no-pager', 'diff'])
|
||||
print(p.stdout)
|
||||
sys.exit(errors)
|
||||
|
||||
# This only runs after commits are pushed to fdroid/fdroidserver
|
||||
git_repo = git.repo.Repo('.')
|
||||
modified = git_repo.git().ls_files(modified=True).split()
|
||||
if git_repo.is_dirty() and ('gradlew-fdroid' in modified or 'makebuildserver' in modified):
|
||||
private_token = os.getenv('PERSONAL_ACCESS_TOKEN')
|
||||
if not private_token:
|
||||
print(Fore.RED
|
||||
+ 'ERROR: GitLab Token not found in PERSONAL_ACCESS_TOKEN!'
|
||||
+ Style.RESET_ALL)
|
||||
sys.exit(1)
|
||||
|
||||
branch = git_repo.create_head(os.path.basename(__file__), force=True)
|
||||
branch.checkout()
|
||||
git_repo.index.add(['gradlew-fdroid', 'makebuildserver'])
|
||||
author = git.Actor('fdroid-bot', 'fdroid-bot@f-droid.org')
|
||||
git_repo.index.commit('gradle v' + version, author=author)
|
||||
project_path = 'fdroid-bot/' + os.getenv('CI_PROJECT_NAME')
|
||||
url = ('https://gitlab-ci-token:%s@%s/%s.git'
|
||||
% (os.getenv('PERSONAL_ACCESS_TOKEN'), os.getenv('CI_SERVER_HOST'), project_path))
|
||||
remote_name = 'fdroid-bot'
|
||||
try:
|
||||
remote = git_repo.create_remote(remote_name, url)
|
||||
# See https://github.com/PyCQA/pylint/issues/2856 .
|
||||
# pylint: disable-next=no-member
|
||||
except git.exc.GitCommandError:
|
||||
remote = git.remote.Remote(git_repo, remote_name)
|
||||
remote.set_url(url)
|
||||
remote.push(force=True)
|
||||
git.remote.Remote.rm(git_repo, remote_name)
|
||||
|
||||
gl = gitlab.Gitlab(os.getenv('CI_SERVER_URL'), api_version=4,
|
||||
private_token=private_token)
|
||||
project = gl.projects.get(project_path, lazy=True)
|
||||
description = (
|
||||
'see <https://gitlab.com/fdroid/gradle-transparency-log/-/blob/master/checksums.json>'
|
||||
'\n\n<p><small>generated by <a href="%s/-/jobs/%s">GitLab CI Job #%s</a></small></p>'
|
||||
% (os.getenv('CI_PROJECT_URL'), os.getenv('CI_JOB_ID'), os.getenv('CI_JOB_ID'))
|
||||
)
|
||||
try:
|
||||
mr = project.mergerequests.create({
|
||||
'source_branch': branch.name,
|
||||
'target_project_id': 36527, # fdroid/fdroidserver
|
||||
'target_branch': 'master',
|
||||
'title': 'update to gradle v' + version,
|
||||
'description': description,
|
||||
'labels': ['fdroid-bot', 'gradle'],
|
||||
'remove_source_branch': True,
|
||||
})
|
||||
mr.save()
|
||||
except gitlab.exceptions.GitlabCreateError as e:
|
||||
if e.response_code == 409: # Another open merge request already exists for this source branch
|
||||
print(e.error_message)
|
||||
else:
|
||||
raise e
|
||||
p = subprocess.run(['git', '--no-pager', 'diff'])
|
||||
errors += p.returncode
|
||||
sys.exit(errors)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue