-
Notifications
You must be signed in to change notification settings - Fork 40
Adding CI validation for manifest.json #447
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
Merged
Merged
Changes from 7 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
6eff988
Adding CI validation for manifest.json
MSAdministrator d3f0a31
Updating action to install deps
MSAdministrator 09f0752
Adding robust error output for github
MSAdministrator 14decde
Updating yaml
MSAdministrator d908c47
Updating condition on step
MSAdministrator 30e5742
Trying a different approach using bash
MSAdministrator 17a18c1
Udating error message
MSAdministrator 2c90475
Updating logging message based on feedback
MSAdministrator 452fb76
Removing old script
MSAdministrator File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,37 @@ | ||
| name: Validate manifest.json | ||
|
|
||
| on: push | ||
|
|
||
| jobs: | ||
| validate: | ||
| runs-on: ubuntu-latest | ||
|
|
||
| steps: | ||
| - name: Checkout repository | ||
| uses: actions/checkout@v4 | ||
| with: | ||
| fetch-depth: 1 | ||
|
|
||
| - name: Validate manifest.json | ||
| id: validate_manifest | ||
| run: | | ||
| echo "Validating manifest files" | ||
| for item in $(jq -c -r '.lists.[].file | select( . != null )' manifest.json); do | ||
| if test -f $item; then | ||
| echo "$item exists" | ||
| else | ||
| echo "::error file=manifest.json,title=Invalid-Manifest::$item does not exist" | ||
MSAdministrator marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| echo "Validating manifest urls" | ||
| for item in $(jq -c -r '.lists.[].url | select( . != null )' manifest.json); do | ||
| urlstatus=$(curl -H 'Cache-Control: no-cache' -o /dev/null --silent --head --write-out "$URL %{http_code}" "$item") | ||
| if [ $urlstatus -ne 200 ]; then | ||
| echo "::error file=manifest.json,title=Invalid-Manifest::$item has HTTP status of $urlstatus" | ||
| exit 1 | ||
| fi | ||
| done | ||
|
|
||
| echo "Validation complete" | ||
This file contains hidden or 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,39 @@ | ||
| import os | ||
| import json | ||
|
|
||
| import requests | ||
|
|
||
|
|
||
| class Validate: | ||
|
|
||
| def __init__(self, manifest: str = "manifest.json") -> None: | ||
| if not os.path.exists(manifest): | ||
| err = f"manifest.json '{manifest}' doesn't exist." | ||
| self.set_output("error", err) | ||
| raise ValueError(err) | ||
| self.manifest = manifest | ||
|
|
||
| def set_output(self, name, value): | ||
| with open(os.environ['GITHUB_OUTPUT'], 'a') as fh: | ||
| print(f'{name}={value}', file=fh) | ||
|
|
||
| def run(self) -> bool: | ||
| data: dict = {} | ||
| with open(self.manifest) as f: | ||
| data = json.load(f) | ||
| for item in data.get("lists"): | ||
| if item.get("file") and not os.path.exists(item["file"]): | ||
| err = f"referenced static file does not exist: '{item}'" | ||
| self.set_output("error", err) | ||
| raise ValueError(err) | ||
| elif item.get("url"): | ||
| resp = requests.request("GET", item["url"]) | ||
| resp.raise_for_status() | ||
| if not resp.ok: | ||
| err = f"unable to retrieve file from URL: '{item['url']}'" | ||
| self.set_output("error", err) | ||
| raise requests.exceptions.HTTPError(err) | ||
|
|
||
|
|
||
| if __name__ == "__main__": | ||
| Validate().run() |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.