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

Add CI/CD support using GitHub Actions #30

Merged
merged 15 commits into from
Oct 13, 2023
Merged
Show file tree
Hide file tree
Changes from 11 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
49 changes: 49 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
name: pagure-exporter
on: [push, pull_request, workflow_dispatch]
jobs:
ci-basic:
strategy:
fail-fast: false
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v4

- name: Install the base dependencies
run: |
python3 -m pip install --upgrade poetry tox

- name: Check the correctness of the project config
run: |
poetry check

- name: Check the quality of the code
run: |
tox -e black
tox -e isort
tox -e lint
gridhead marked this conversation as resolved.
Show resolved Hide resolved
tox -e bandit

ci-tests:
strategy:
fail-fast: false
matrix:
tox-env: ["py311"]
runs-on: ubuntu-latest
container: fedorapython/fedora-python-tox:latest
steps:
- uses: actions/checkout@v4

- name: Install the base dependencies
run: |
python3 -m pip install --upgrade tox

- name: Set up user for running the testcases
run: |
useradd testrunner
chown -R testrunner .

- name: Execute tox
run: |
su testrunner -c "tox -e ${{ matrix.tox-env }}"
84 changes: 16 additions & 68 deletions poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 19 additions & 1 deletion protop2g/conf/standard.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,25 @@

movestat = False

tempdrct = "/var/tmp"
# While the location for creating temporary directories is definitive, the temporary directories
# are created with a random name constituting of a definitive prefix in runtime with only the user
# that created the file having READ and WRITE access to them. Basically, while the location
# `/var/tmp` is known from the beginning, the locations `/var/tmp/protop2g-tempsrce-$RANDOM` and
# `/var/tmp/protop2g-tempdest-$RANDOM` are not and hence - that should not be a security concern.
# For more information, please read
# https://bandit.readthedocs.io/en/latest/plugins/b108_hardcoded_tmp_directory.html
# https://security.openstack.org/guidelines/dg_using-temporary-files-securely.html
tempdrct = "/var/tmp" # noqa: S108

# If a definitive timeout is not specified for every usage of `requests`, there is likeliness that
# a failure in probing a URL might lead to the program trying so indefinitely - thus causing the
# program to freeze. Remember, `requests` is a synchronous HTTP library and if you are looking for
# some of that nice asynchronicity, you are much better off using the likes of `httpx`.
# For more information, please read
# https://bandit.readthedocs.io/en/latest/plugins/b113_request_without_timeout.html
# https://datagy.io/python-requests-timeouts/
rqsttime = 30

dfremote = "origin"
prfxsrce = "protop2g-tempsrce-"
prfxdest = "protop2g-tempdest-"
Expand Down
4 changes: 2 additions & 2 deletions protop2g/work/stat.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def __init__(self):

def obtninfo(self):
rqstloca = "{}/{}".format(self.loca, self.repo)
response = requests.get(rqstloca, headers=self.head)
response = requests.get(rqstloca, headers=self.head, timeout=standard.rqsttime)
if response.status_code == 200:
jsondict = response.json()
standard.srcedict = {
Expand Down Expand Up @@ -70,7 +70,7 @@ def __init__(self):

def obtninfo(self):
rqstloca = "{}/{}".format(self.loca, self.repo)
response = requests.get(rqstloca, headers=self.head)
response = requests.get(rqstloca, headers=self.head, timeout=standard.rqsttime)
if response.status_code == 200:
jsondict = response.json()
standard.destdict = {
Expand Down
34 changes: 28 additions & 6 deletions protop2g/work/tkts.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,12 @@ def getcount(self):
initdata = {"per_page": standard.pagesize, "page": "1"}
if standard.tktstate == "closed" or standard.tktstate == "all":
initdata["status"] = standard.tktstate
initresp = requests.get(url=f"{self.purl}/issues", params=initdata, headers=self.phed)
initresp = requests.get(
url=f"{self.purl}/issues",
params=initdata,
headers=self.phed,
timeout=standard.rqsttime,
)
respcode, respresn = initresp.status_code, initresp.reason
if respcode == 200:
initdict = initresp.json()
Expand All @@ -55,7 +60,10 @@ def getcount(self):
if standard.tktstate == "closed" or standard.tktstate == "all":
lastdata["status"] = standard.tktstate
lastresp = requests.get(
url=f"{self.purl}/issues", params=lastdata, headers=self.phed
url=f"{self.purl}/issues",
params=lastdata,
headers=self.phed,
timeout=standard.rqsttime,
)
respcode, respresn = lastresp.status_code, lastresp.reason
if lastresp.status_code == 200:
Expand All @@ -74,7 +82,12 @@ def iterpage(self, indx):
rqstdata = {"per_page": standard.pagesize, "page": f"{indx}"}
if standard.tktstate == "closed" or standard.tktstate == "all":
rqstdata["status"] = standard.tktstate
response = requests.get(url=f"{self.purl}/issues", params=rqstdata, headers=self.phed)
response = requests.get(
url=f"{self.purl}/issues",
params=rqstdata,
headers=self.phed,
timeout=standard.rqsttime,
)
respcode, respresn = response.status_code, response.reason
if respcode == 200:
standard.pagerslt = response.json()["issues"]
Expand All @@ -87,7 +100,9 @@ def iterpage(self, indx):
def iteriden(self, tkid):
try:
strttime = time.time()
response = requests.get(url=f"{self.purl}/issue/{tkid}", headers=self.phed)
response = requests.get(
url=f"{self.purl}/issue/{tkid}", headers=self.phed, timeout=standard.rqsttime
)
respcode, issuskip = response.status_code, True
if respcode == 200:
standard.issurslt = response.json()
Expand Down Expand Up @@ -120,7 +135,7 @@ def itertkts(self, dictobjc):
standard.issubody = dictobjc["content"]
standard.timedata = int(dictobjc["date_created"])
headdata = standard.headtemp_ticket.format(
issuiden=standard.issuiden, issuname=standard.issuname
issuiden=standard.issuiden, issuname=standard.issuname, timeout=standard.rqsttime
)
bodydata = standard.bodytemp_ticket.format(
issubody=standard.issubody,
Expand All @@ -145,7 +160,12 @@ def itertkts(self, dictobjc):
rqstdata = {"title": headdata, "description": bodydata.replace("@", "&")}
if standard.movetags:
rqstdata["labels"] = ",".join(standard.issutags)
response = requests.post(url=f"{self.gurl}/issues", data=rqstdata, headers=self.ghed)
response = requests.post(
url=f"{self.gurl}/issues",
data=rqstdata,
headers=self.ghed,
timeout=standard.rqsttime,
)
respcode, respresn = response.status_code, response.reason
if respcode == 201:
respresn = response.json()["web_url"]
Expand Down Expand Up @@ -192,6 +212,7 @@ def itercmts(self, dictobjc):
url=f"{self.gurl}/issues/{standard.gtlbtkid}/notes",
data=rqstdata,
headers=self.ghed,
timeout=standard.rqsttime,
)
respcode, respresn = response.status_code, response.reason
if respcode == 201:
Expand All @@ -212,6 +233,7 @@ def iterstat(self):
url=f"{self.gurl}/issues/{standard.gtlbtkid}",
data=rqstdata,
headers=self.ghed,
timeout=standard.rqsttime,
)
respcode, respresn = response.status_code, response.reason
else:
Expand Down
2 changes: 0 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,8 @@ GitPython = "^3.1.37"
[tool.poetry.group.dev.dependencies]
pre-commit = "^3.4.0"
black = "^22.8.0"
isort = "^5.10.1"
flake8 = "<5.0.0"
gridhead marked this conversation as resolved.
Show resolved Hide resolved
tox = "^4.0.0"
bandit = "^1.7.4"
pytest = "^7.1.3"
pytest-black = "^0.3.12"
gridhead marked this conversation as resolved.
Show resolved Hide resolved
pytest-flake8 = "^1.0.7"
Expand Down
4 changes: 2 additions & 2 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,6 @@
def test_main_help(cmdl, code, text):
runner = CliRunner()
result = runner.invoke(main, cmdl)
assert result.exit_code == code
assert result.exit_code == code # noqa: S101
for indx in text:
assert indx in result.output
assert indx in result.output # noqa: S101
39 changes: 39 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[tox]
minversion = 3.11.0
envlist = py311,black,lint,isort,bandit
isolated_build = true
skip_missing_interpreters = true

[testenv]
passenv = HOME
skip_install = true
sitepackages = false
deps =
poetry>=1.2.0
commands_pre =
poetry install --all-extras
commands =
poetry run pytest -o 'addopts=--cov-config .coveragerc --cov=protop2g --cov-report term-missing --cov-report xml --cov-report html' test/ {posargs}

[testenv:black]
commands =
poetry run black --diff --check protop2g/ test/

[testenv:lint]
commands =
poetry run ruff check protop2g/ test/

[testenv:isort]
gridhead marked this conversation as resolved.
Show resolved Hide resolved
commands =
poetry run ruff check --select I protop2g/ test/

[testenv:bandit]
gridhead marked this conversation as resolved.
Show resolved Hide resolved
commands =
poetry run ruff check --select S protop2g/ test/

[flake8]
max-line-length = 100
extend-ignore = E203

[isort]
gridhead marked this conversation as resolved.
Show resolved Hide resolved
profile = black