-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(#7749) run yaml-lint and pylint as github action
* run yaml-lint as github action * add recipe_linter * add github action problem matchers * demo errors * libpq: Update Conan conventions Automatically created by bincrafters-conventions 0.30.5 * Update conandata.yml * Update conanfile.py * remove workflow_dispatch * fix path Co-authored-by: bincrafters-user <bincrafters@gmail.com> Co-authored-by: Uilian Ries <uilianries@gmail.com>
- Loading branch information
1 parent
1449b0a
commit cca3971
Showing
4 changed files
with
136 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
{ | ||
"problemMatcher": [ | ||
{ | ||
"owner": "recipe_linter_errors", | ||
"severity": "error", | ||
"pattern": [ | ||
{ | ||
"regexp": "(\\S+):(\\d+):(\\d+):\\s(E\\d+):\\s(.+)\\s\\((\\S+)\\)", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
"message": 5, | ||
"code": 4 | ||
} | ||
] | ||
}, | ||
{ | ||
"owner": "recipe_linter_warnings", | ||
"severity": "warning", | ||
"pattern": [ | ||
{ | ||
"regexp": "(\\S+):(\\d+):(\\d+):\\s(W\\d+):\\s(.+)\\s\\((\\S+)\\)", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
"message": 5, | ||
"code": 4 | ||
} | ||
] | ||
} | ||
] | ||
} |
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,53 @@ | ||
import os | ||
import yaml | ||
import requests | ||
import packaging.version | ||
import subprocess | ||
import platform | ||
import sys | ||
|
||
|
||
def main(pr): | ||
session = requests.session() | ||
session.headers = {} | ||
token = os.getenv("GH_TOKEN") | ||
if token: | ||
session.headers["Authorization"] = "token %s" % token | ||
|
||
session.headers["Accept"] = "application/vnd.github.v3+json" | ||
session.headers["User-Agent"] = "request" | ||
session.auth = None | ||
# if user and pw: | ||
# session.auth = requests.auth.HTTPBasicAuth(user, pw) | ||
|
||
github_server_url = os.getenv("GITHUB_SERVER_URL") | ||
github_repo = os.getenv("GITHUB_REPOSITORY") | ||
|
||
r = session.request("GET", f"{github_server_url}/{github_repo}/pull/{pr}.diff") | ||
r.raise_for_status() | ||
diff = r.text | ||
packages = set() | ||
for line in diff.split("\n"): | ||
if line.startswith("+++ b/recipes/") or line.startswith("--- a/recipes/"): | ||
packages.add(line.split("/")[2]) | ||
for package in packages: | ||
version = packaging.version.Version("0.0.0") | ||
folder = "" | ||
with open(os.path.join("recipes", package, "config.yml"), "r") as file: | ||
config = yaml.safe_load(file) | ||
for v in config["versions"]: | ||
try: | ||
tmpVer = packaging.version.Version(v) | ||
if tmpVer > version: | ||
version = tmpVer | ||
folder = config["versions"][v]["folder"] | ||
except packaging.version.InvalidVersion: | ||
print("Error parsing version %s for package %s in pr %s" % (v, package, pr)) | ||
|
||
shell = bool(platform.system() != "Windows") | ||
command = "conan export %s %s/%s@" % (os.path.join("recipes", package, folder), package, version) | ||
p = subprocess.run(command, shell=shell, check=True) | ||
|
||
if __name__ == "__main__": | ||
# execute only if run as a script | ||
main(sys.argv[1]) |
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,33 @@ | ||
name: run linters | ||
|
||
on: | ||
pull_request: | ||
|
||
jobs: | ||
lint: | ||
env: | ||
CONAN_YAMLLINT_WERR: 1 | ||
CONAN_PYLINT_WERR: 1 | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
hook: [".github/yaml_linter", ".github/recipe_linter"] | ||
runs-on: ubuntu-latest | ||
|
||
steps: | ||
- uses: actions/checkout@v2 | ||
- uses: actions/setup-python@v2.2.2 | ||
with: | ||
python-version: "3.8" | ||
|
||
- run: "pip3 install conan yamllint packaging pylint==2.10.2 astroid" | ||
|
||
- name: install hook | ||
run: | | ||
conan config install https://github.com/conan-io/hooks.git | ||
conan config set hooks.${{ matrix.hook }} | ||
- name: run lint | ||
run: | | ||
echo "::add-matcher::${{ matrix.hook }}.json" | ||
python3 .github/runlint.py ${{ github.event.pull_request.number }} |
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,18 @@ | ||
{ | ||
"problemMatcher": [ | ||
{ | ||
"owner": "yaml_linter", | ||
"pattern": [ | ||
{ | ||
"regexp": "^\\[HOOK\\s-\\syaml_linter\\.py\\]\\spre_export\\(\\):\\s(.+):(\\d+):(\\d+):\\s\\[(\\S+)\\]\\s(.+)\\s\\((.+)\\)$", | ||
"file": 1, | ||
"line": 2, | ||
"column": 3, | ||
"severity": 4, | ||
"message": 5, | ||
"code": 6 | ||
} | ||
] | ||
} | ||
] | ||
} |