Skip to content

Commit e96ec76

Browse files
authored
Merge pull request #228 from EESSI/develop
merge v0.1.1 into main
2 parents 94b909f + 510a74b commit e96ec76

File tree

5 files changed

+194
-13
lines changed

5 files changed

+194
-13
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,13 +67,13 @@ At the [app settings page](https://github.com/settings/apps) click "`New GitHub
6767
python3 -c 'import secrets; print(secrets.token_hex(64))'
6868
```
6969
- Permissions: assign the required permissions to the app (e.g., read access to commits, issues, pull requests);
70-
- Make sure to assign read and write access to the Pull request in "Repository permissions" section; these permisions can be changed later on;
70+
- Make sure to assign read and write access to the Pull requests and Issues in "Repository permissions" section; these permisions can be changed later on;
7171
- Make sure to accept the new permissions from the "Install App" section that you can reach via the menu on the left hand side.
7272
- Then select the wheel right next to your installed app, or use the link `https://github.com/settings/installations/INSTALLATION_ID`
7373
- Once the page is open you will be able to accept the new permissions there.
7474
- Some permissions (e.g., metadata) will be selected automatically because of others you have chosen.
7575

76-
- Events: subscribe the app to events it shall react on (e.g., related to pull requests)
76+
- Events: subscribe the app to events it shall react on (e.g., related to pull requests and comments)
7777
- Select that the app can only be installed by this (your) GitHub account or organisation.
7878

7979
Click on "`Create GitHub App`" to complete this step.

RELEASE_NOTES

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
11
This file contains a description of the major changes to the EESSI
22
build-and-deploy bot. For more detailed information, please see the git log.
33

4-
v0.1.0 (29 september 2023)
4+
v0.1.1 (14 November 2023)
5+
--------------------------
6+
7+
This is a patch release of the EESSI build-and-deploy bot.
8+
9+
Bug fixes:
10+
* omit header in output of `squeue` command run by the job manager (#220)
11+
* make bot compatible with more recent versions of PyGithub (#224)
12+
13+
Improvements:
14+
* added a script to help reducing disk usage by cleaning up tarballs stored by jobs (#217)
15+
* clarified documentation about setting permissions and event subscriptions for the bot (#221)
16+
17+
18+
v0.1.0 (29 September 2023)
519
--------------------------
620

721
This is the first release of the EESSI build-and-deploy bot, which consists of

connections/github.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
#
1212

1313
# Standard library imports
14-
import datetime
14+
from datetime import datetime, timezone
1515
import time
1616

1717
# Third party imports (anything installed into the local Python environment)
18-
from github import Github, GithubIntegration
18+
import github
1919

2020
# Local application imports (anything from EESSI/eessi-bot-software-layer)
2121
from tools import config, logging
@@ -57,7 +57,7 @@ def get_token():
5757
# If the config keys are not set, get_access_token will raise a NotImplementedError
5858
# Returning NoneType token will stop the connection in get_instance
5959
try:
60-
github_integration = GithubIntegration(app_id, private_key)
60+
github_integration = github.GithubIntegration(app_id, private_key)
6161
_token = github_integration.get_access_token(installation_id)
6262
break
6363
except NotImplementedError as err:
@@ -84,7 +84,7 @@ def connect():
8484
Returns:
8585
Instance of Github
8686
"""
87-
return Github(get_token().token)
87+
return github.Github(get_token().token)
8888

8989

9090
def get_instance():
@@ -101,7 +101,16 @@ def get_instance():
101101
global _gh, _token
102102
# TODO Possibly renew token already if expiry date is soon, not only
103103
# after it has expired.
104-
if not _gh or (_token and datetime.datetime.utcnow() > _token.expires_at):
104+
105+
# Check if PyGithub version is < 1.56
106+
if hasattr(github, 'GithubRetry'):
107+
# Pygithub 2.x
108+
time_now = datetime.now(timezone.utc)
109+
else:
110+
# Pygithub 1.x
111+
time_now = datetime.utcnow()
112+
113+
if not _gh or (_token and time_now > _token.expires_at):
105114
_gh = connect()
106115
return _gh
107116

eessi_bot_job_manager.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def get_current_jobs(self):
106106
if username is None:
107107
raise Exception("Unable to find username")
108108

109-
squeue_cmd = "%s --long --user=%s" % (self.poll_command, username)
109+
squeue_cmd = "%s --long --noheader --user=%s" % (self.poll_command, username)
110110
squeue_output, squeue_err, squeue_exitcode = run_cmd(
111111
squeue_cmd,
112112
"get_current_jobs(): squeue command",
@@ -125,10 +125,10 @@ def get_current_jobs(self):
125125
}
126126

127127
# get job info, logging any Slurm issues
128-
# Note, the first two lines of the output are skipped ("range(2,...)")
129-
# because they contain header information.
130-
for i in range(2, len(lines)):
131-
job = lines[i].rstrip().split()
128+
# Note, all output lines of squeue are processed because we run it with
129+
# --noheader.
130+
for line in lines:
131+
job = line.rstrip().split()
132132
if len(job) >= 9:
133133
job_id = job[0]
134134
state = job[4]

scripts/cleanup_pr.sh

Lines changed: 158 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,158 @@
1+
#!/bin/bash
2+
#
3+
# GitHub App for the EESSI project
4+
#
5+
# A bot to help with requests to add software installations to the EESSI software layer,
6+
# see https://github.com/EESSI/software-layer
7+
8+
# This script cleans up (deletes) all build artefacts and temporary storage tarballs of a given PR
9+
#
10+
# author: Thomas Roeblitz (@trz42)
11+
#
12+
# license: GPLv2
13+
#
14+
15+
SCRIPT_DIR=$(dirname $(realpath $BASH_SOURCE))
16+
17+
function display_help
18+
{
19+
echo "Usage: $0 [OPTIONS] <PR number>" >&2
20+
echo " -b | --jobs-base-dir DIRECTORY - jobs base directory [default: reads" >&2
21+
echo " value from bot config file app.cfg or .]" >&2
22+
echo " -D | --dry-run - only show commands that would be run" >&2
23+
echo " [default: false]" >&2
24+
echo " -h | --help - display this usage information" >&2
25+
}
26+
27+
function get_jobs_base_dir
28+
{
29+
app_cfg_path=${1}
30+
grep jobs_base_dir ${app_cfg_path} | grep -v '^[ ]*#' | sed -e 's/^[^=]*=[ ]*//'
31+
}
32+
33+
echo
34+
35+
if [[ $# -lt 1 ]]; then
36+
display_help
37+
exit 1
38+
fi
39+
40+
# process command line args
41+
POSITIONAL_ARGS=()
42+
43+
jobs_base_dir=
44+
dry_run=false
45+
46+
while [[ $# -gt 0 ]]; do
47+
case $1 in
48+
-b|--jobs-base-dir)
49+
if [[ $# -gt 1 ]]; then
50+
jobs_base_dir="$2"
51+
shift 2
52+
else
53+
echo "Error: missing argument (directory) for parameter '${1}'"
54+
exit 2
55+
fi
56+
;;
57+
-D|--dry-run)
58+
dry_run=true
59+
shift 1
60+
;;
61+
-h|--help)
62+
display_help
63+
exit 0
64+
;;
65+
-*|--*)
66+
echo "Error: Unknown option: $1" >&2
67+
exit 1
68+
;;
69+
*) # No more options
70+
POSITIONAL_ARGS+=("$1") # save positional arg
71+
shift
72+
;;
73+
esac
74+
done
75+
76+
# restore potentially parsed filename(s) into $*
77+
set -- "${POSITIONAL_ARGS[@]}"
78+
79+
if [[ $# -ne 1 ]]; then
80+
echo "Error: exactly one PR number should be provided as argument"
81+
display_help
82+
exit 3
83+
fi
84+
85+
pull_request=${1}
86+
87+
if ${dry_run} = true ; then
88+
echo "DRY_RUN: not removing any files"
89+
fi
90+
91+
# determine jobs base dir if not given explicitly
92+
# 1. check for file app.cfg in SCRIPT_DIR
93+
# 2. check for file app.cfg in current dir
94+
# if found try to obtain value of jobs_base_dir setting
95+
# if not file not found or jobs_base_dir setting not found (or empty) --> error & exit
96+
if [[ -z ${jobs_base_dir} ]]; then
97+
echo "jobs base directory not given explicitly, trying to determine it"
98+
if [[ -e ${SCRIPT_DIR}/app.cfg ]]; then
99+
echo "check for app.cfg in '${SCRIPT_DIR}'"
100+
jobs_base_dir=$(get_jobs_base_dir ${SCRIPT_DIR}/app.cfg)
101+
else
102+
if [[ -e ./app.cfg ]]; then
103+
echo "check for app.cfg in '${PWD}' (current directory)"
104+
jobs_base_dir=$(get_jobs_base_dir ./app.cfg)
105+
fi
106+
fi
107+
fi
108+
if [[ -z ${jobs_base_dir} ]]; then
109+
echo "Error: jobs base directory is empty, please specify it as argument"
110+
display_help
111+
exit 4
112+
fi
113+
114+
echo "processing all directories for PR ${pull_request}:"
115+
find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request} | sed -e 's/^/ /'
116+
117+
echo
118+
echo "disk usage of directories for PR ${pull_request} BEFORE removing build artefacts and tmp storage"
119+
for d in $(find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request}); do du -sh $d; done
120+
121+
echo
122+
echo "$([[ ${dry_run} = true ]] && echo "DRY_RUN: ")removing tmp storage tarballs for PR ${pull_request}"
123+
for d in $(find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request})
124+
do
125+
for f in $(find $d -type f -wholename "*[0-9].tgz")
126+
do
127+
if ${dry_run} = true ; then
128+
echo "DRY_RUN: rm '$f' ($(ls -lh $f | awk '{print $5}'))"
129+
else
130+
echo "Removing file '$f'"
131+
rm $f
132+
fi
133+
done
134+
done
135+
136+
echo
137+
echo "disk usage of directories for PR ${pull_request} AFTER removing tmp storage tarballs"
138+
for d in $(find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request}); do du -sh $d; done
139+
140+
echo
141+
echo "$([[ ${dry_run} = true ]] && echo "DRY_RUN: ")removing build artefacts for PR ${pull_request}"
142+
for d in $(find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request})
143+
do
144+
for f in $(find $d -type f -wholename "*tar.gz")
145+
do
146+
if ${dry_run} = true ; then
147+
echo "DRY_RUN: rm '$f' ($(ls -lh $f | awk '{print $5}'))"
148+
else
149+
echo "Removing file '$f'"
150+
rm $f
151+
fi
152+
done
153+
done
154+
155+
echo
156+
echo "disk usage of directories for PR ${pull_request} AFTER removing build artefacts and tmp storage"
157+
for d in $(find ${jobs_base_dir}/* -maxdepth 1 -type d -wholename */pr_${pull_request}); do du -sh $d; done
158+

0 commit comments

Comments
 (0)