-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
167 changed files
with
6,628 additions
and
6,339 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import json | ||
import os | ||
|
||
import requests | ||
from dotenv import load_dotenv | ||
|
||
try: | ||
|
||
load_dotenv() # load variables | ||
load_dotenv(".secrets") # load variables from the ".secrets" file | ||
except: | ||
pass | ||
|
||
# has been propagated from repo vars to env vars | ||
try: | ||
current_scores = json.loads(os.getenv("SNIPPET_SCORE", '{"snippet_score": 0}')) | ||
except json.decoder.JSONDecodeError: | ||
current_scores = {"snippet_score": 0} | ||
|
||
# set by pytest in custom conftest reporting | ||
new_scores = {} | ||
with open("results/snippet_score.json", "r") as f: | ||
new_scores = json.load(f) | ||
|
||
|
||
# Compare the scores and update the repository variable if necessary | ||
def add_summary(msg, current_scores: dict, new_scores: dict): | ||
if os.getenv("GITHUB_STEP_SUMMARY") is None: | ||
print(f"The environment variable GITHUB_STEP_SUMMARY does not exist.") | ||
return | ||
with open(os.getenv("GITHUB_STEP_SUMMARY", 0), "a") as f: | ||
f.write("# Snippets\n") | ||
f.write(msg) | ||
f.write("\n```json\n") | ||
json.dump({"current": new_scores}, f) | ||
f.write("\n") | ||
json.dump({"previous": current_scores}, f) | ||
f.write("\n```\n") | ||
|
||
|
||
|
||
def update_var(var_name: str, value: str): | ||
repo = os.getenv("GITHUB_REPOSITORY", "Josverl/micropython-stubs") | ||
gh_token_vars = os.getenv("GH_TOKEN_VARS", os.getenv("GH_TOKEN", "-")) | ||
if gh_token_vars == "-": | ||
print("No token available to update the repository variable") | ||
return | ||
# update the repository variable | ||
url = f"https://api.github.com/repos/{repo}/actions/variables/{var_name}" | ||
headers = { | ||
"Authorization": f"token {gh_token_vars}", | ||
"Content-Type": "application/json", | ||
"User-Agent": "josverl", | ||
} | ||
data = {"name": str(var_name), "value": str(value)} | ||
response = requests.patch(url, headers=headers, json=data) | ||
response.raise_for_status() | ||
|
||
|
||
if new_scores["snippet_score"] < current_scores["snippet_score"]: | ||
msg = f"The snippet_score has decreased from {current_scores['snippet_score']} to {new_scores['snippet_score']}" | ||
print(msg) | ||
add_summary(msg, current_scores, new_scores) | ||
exit(1) # Fail the test | ||
elif new_scores["snippet_score"] == current_scores["snippet_score"]: | ||
msg = f"The snippet_score has not changed from {current_scores['snippet_score']}" | ||
print(msg) | ||
add_summary(msg, current_scores, new_scores) | ||
elif new_scores["snippet_score"] > current_scores["snippet_score"]: | ||
msg = f"The snippet_score has improved to {new_scores['snippet_score']}" | ||
print(msg) | ||
add_summary(msg, current_scores, new_scores) | ||
if os.getenv("GITHUB_REF_NAME", "main") == "main": | ||
update_var(var_name="SNIPPET_SCORE", value=json.dumps(new_scores, skipkeys=True, indent=4)) | ||
|
||
print("Done") | ||
exit(0) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
name: test_stub_quality | ||
on: [push, pull_request, workflow_dispatch] | ||
|
||
env: | ||
# Setting an environment variable with the value of a configuration variable | ||
SNIPPET_SCORE: ${{ vars.SNIPPET_SCORE }} | ||
GH_TOKEN_VARS: ${{ secrets.GH_TOKEN_VARS }} | ||
|
||
jobs: | ||
test_snippets: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v4 | ||
#---------------------------------------------- | ||
|
||
- name: Install poetry # poetry is not in the default image | ||
run: pipx install poetry | ||
|
||
- name: Set up Python | ||
uses: actions/setup-python@v4 | ||
with: | ||
python-version: "3.11" # Replace with the Python version you're using | ||
|
||
- name: Testspace client install & config | ||
uses: testspace-com/setup-testspace@v1 | ||
with: | ||
domain: josverl | ||
#---------------------------------------------- | ||
# install project | ||
#---------------------------------------------- | ||
- name: Install dependencies for group test | ||
run: | | ||
pip install -r requirements-test.txt | ||
#---------------------------------------------- | ||
# stubber clone | ||
# repos needed for tests | ||
#---------------------------------------------- | ||
- name: stubber clone | ||
run: stubber clone | ||
|
||
|
||
- name: update the stubs and test the snippets (not pushed) | ||
continue-on-error: true | ||
run: | | ||
pwsh -file ./update-stubs.ps1 | ||
pytest -m 'snippets' --cache-clear --junitxml=./results/results.xml | ||
env: | ||
JUPYTER_PLATFORM_DIRS: "1" | ||
# fix: DeprecationWarning: Jupyter is migrating its paths to use standard platformdirs | ||
|
||
- name: Testspace push test content | ||
run: | | ||
testspace ./results/results.xml | ||
- name: compare and update | ||
run: | | ||
python .github/workflows/compare_score.py |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -50,3 +50,5 @@ typings | |
# no node modules | ||
node_modules | ||
package*.json | ||
|
||
coverage/snippet_score.json |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.