Skip to content

Commit

Permalink
Merge branch 'add_snippets'
Browse files Browse the repository at this point in the history
  • Loading branch information
Josverl committed Nov 18, 2023
2 parents 49cb42d + 1c6dc41 commit b3b7f70
Show file tree
Hide file tree
Showing 167 changed files with 6,628 additions and 6,339 deletions.
4 changes: 3 additions & 1 deletion .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"powershell": "latest"
"powershell": "latest",
"ghcr.io/devcontainers/features/docker-outside-of-docker:1": {},
"ghcr.io/itsmechlark/features/act:1": {}
}
}
77 changes: 77 additions & 0 deletions .github/workflows/compare_score.py
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)
16 changes: 16 additions & 0 deletions .github/workflows/list_versions.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,19 @@
"""
This module retrieves the versions of Micropython from the Micropython repository on GitHub.
It is used to generate a matrix of versions to create stubs for using Github Actions.
It provides a function `micropython_versions` that returns a list of versions starting from a specified version.
The module also includes a main block that generates a matrix of versions based on command-line arguments and environment variables.
The matrix is printed as JSON and can be optionally written to a file if running in a GitHub Actions workflow.
"""
import json
import os
import sys

from github import Github
from packaging.version import parse

...
import json
import os
import sys
Expand Down
58 changes: 58 additions & 0 deletions .github/workflows/test_stub_quality.yml
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,5 @@ typings
# no node modules
node_modules
package*.json

coverage/snippet_score.json
25 changes: 1 addition & 24 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,26 +1,6 @@
{
"workbench.colorCustomizations": {
"titleBar.activeBackground": "#215732",
"titleBar.activeForeground": "#e7e7e7",
"titleBar.inactiveBackground": "#21573299",
"titleBar.inactiveForeground": "#e7e7e799",
"activityBar.activeBackground": "#2f7c47",
"activityBar.activeBorder": "#422c74",
"activityBar.background": "#2f7c47",
"activityBar.foreground": "#e7e7e7",
"activityBar.inactiveForeground": "#e7e7e799",
"panel.border": "#2f7c47",
"editorGroup.border": "#2f7c47",
"tab.activeBorder": "#2f7c47",
"activityBarBadge.background": "#422c74",
"activityBarBadge.foreground": "#e7e7e7",
"statusBar.background": "#215732",
"statusBar.foreground": "#e7e7e7",
"statusBarItem.hoverBackground": "#2f7c47",
"statusBarItem.remoteBackground": "#215732",
"statusBarItem.remoteForeground": "#e7e7e7",
"sash.hoverBorder": "#2f7c47",
"commandCenter.border": "#e7e7e799"
"activityBar.activeBorder": "#422c74"
},
"peacock.color": "#215732",
"cSpell.words": [
Expand All @@ -29,9 +9,6 @@
"peacock.affectEditorGroupBorder": true,
"peacock.affectPanelBorder": true,
"peacock.affectTabActiveBorder": true,
"python.testing.pytestArgs": [
"tests"
],
"python.testing.unittestEnabled": false,
"python.testing.pytestEnabled": true,
"python.analysis.useLibraryCodeForTypes": false,
Expand Down
28 changes: 0 additions & 28 deletions lgtm.yml

This file was deleted.

Loading

0 comments on commit b3b7f70

Please sign in to comment.