Add save PR test

This commit is contained in:
Daniel Lindmark 2024-05-15 11:21:01 -05:00
parent 789d826ab1
commit 30f1108c6e
2 changed files with 147 additions and 0 deletions

View File

@ -0,0 +1,95 @@
# save_design_review.py
# Uses py-allspice + AllSpice API to save all design review comments to a markdown file
from allspice import AllSpice, DesignReview
import argparse
import sys
print("Starting Test")
parser = argparse.ArgumentParser(
prog="Allspice_API_BIST", description="Test connection and execution of API actions"
)
parser.add_argument(
"--allspice_hub_url",
help="The URL of your AllSpice Hub instance. Defaults to https://hub.allspice.io.",
)
parser.add_argument(
"--allspice_token",
help="Your AllSpice application token. Generate a token: https://hub.allspice.io/user/settings/applications",
)
parser.add_argument(
"--repo_owner",
help="The owner of the repository",
)
parser.add_argument(
"--repo_name",
help="The name of the repository",
)
parser.add_argument(
"--dr",
help="The Design Review ID",
)
print("Parsing args")
args = parser.parse_args()
auth_token = args.allspice_token
if auth_token is None:
print("Please supply a token with --allspice_token <your_token> Generate a token: https://hub.allspice.io/user/settings/applications")
sys.exit(1)
print(f"Auth token {auth_token}")
if args.allspice_hub_url is None:
allspice = AllSpice(token_text="https://hub.allspice.io")
else:
try:
allspice = AllSpice(
token_text=auth_token, allspice_hub_url=args.allspice_hub_url
)
except Exception as e:
print("Error")
sys.exit(1)
if args.repo_owner is None:
print("Please supply a repo owner with --repo_owner <repo_owner>")
sys.exit(1)
if args.repo_name is None:
print("Please supply a repo name with --repo_name <repo_name>")
sys.exit(1)
## Testing connection and authentication
print("Finish making connection")
# Test connection and key
print("AllSpice Version: " + allspice.get_version())
# Test private API call
print("API-Token belongs to user: " + allspice.get_user().username)
design_review = DesignReview.request(allspice, args.repo_owner, args.repo_name, args.dr)
# Open file for writing
file_name = "design_review_comments.md"
comments = design_review.get_comments()
for comment in comments:
# write to file
with open(file_name, 'a') as f:
f.write(f"Author: {comment.author.username}\n")
f.write(f"Date: {comment.created_at}\n")
f.write(f"Comment: {comment.text}\n")
f.write("\n")
# Close file
f.close()
print("End test")

View File

@ -0,0 +1,52 @@
# Python-py-allspice demo repository
# This workflow demonstrates how to use Python and py-allspice to interact with the AllSpice API
# AllSpice Actions documentation: https://learn.allspice.io/docs/actions-cicd
name: Python-py-allspice
on:
push:
issues:
types: [opened, closed, reopened]
jobs:
py-allspice test:
runs-on: ubuntu-latest
steps:
- name: Get repository owner
id: get_owner
run: echo "::set-output name=owner::$(echo ${{ github.repository }} | cut -d'/' -f1)"
- name: Get repository name
id: get_repo
run: echo "::set-output name=repo::$(echo ${{ github.repository }} | cut -d'/' -f2)"
# Check out repository code
- name: "[📚->🖥️] Check out repository code"
uses: actions/checkout@v3
- name: "[🔎->📂] List files in repo 🔎"
run: |
ls -la ${{ github.workspace }}
# Installs python requirements from the requirements.txt file
- name: "[🤼->🖥️] Install python requirements"
run: pip install -r .allspice/utils/requirements.txt
# Run the py-allspice self-test script, this will ping the server and verify the API is working
# Parameters: ${github.server_url} and ${github.token} are automatic Workflow variables and are used to authenticate the AllSpice API
- name: "[🔑->🕸️] Test AllSpice API with py-allspice 🔎"
run: python .allspice/utils/save_design_review.py --allspice_hub_url ${{ github.server_url }} --allspice_token ${{ github.token }} --repo_owner ${{ steps.get_owner.outputs.owner }} --repo_name ${{ steps.get_repo.outputs.repo }} --dr 22
# Print the netlist file to the terminal
- name: Show Netlist 🔎
run: cat design_review_comments.md
# Archive the netlist file as an artifact file
- name: Archive code coverage results
uses: actions/upload-artifact@v3
with:
name: design_review_comments.md
path: design_review_comments.md