This repository has been archived by the owner on Oct 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adding linter to make sure all the versions are the same (#6)
- Loading branch information
1 parent
a2f4654
commit 12a4713
Showing
14 changed files
with
570 additions
and
308 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,30 @@ | ||
name: Lint | ||
|
||
on: [push] | ||
|
||
jobs: | ||
lint_versions: | ||
strategy: | ||
fail-fast: false | ||
matrix: | ||
platform: [ubuntu-latest, macos-latest, windows-latest] | ||
runs-on: ${{ matrix.platform }} | ||
|
||
steps: | ||
- uses: actions/checkout@v1 | ||
- uses: actions/setup-python@v2 | ||
with: | ||
python-version: '3.7.6' | ||
|
||
- name: Run Linter | ||
run: python libraries/linters/gradlerio_versions/lint_gradlerio_versions.py | ||
|
||
- name: Generate diff | ||
run: git diff HEAD > lint-version-fixes.patch | ||
if: ${{ failure() }} | ||
|
||
- uses: actions/upload-artifact@v2 | ||
with: | ||
name: lint-version-fixes | ||
path: lint-version-fixes.patch | ||
if: ${{ failure() }} |
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 |
---|---|---|
@@ -1,17 +1,17 @@ | ||
{ | ||
"fileName": "SnobotSim.json", | ||
"name": "SnobotSim", | ||
"version": "2021.0.2.0", | ||
"uuid": "2aa1aeaf-c5e7-4b89-848e-07c2895c43aa", | ||
"version": "2021.0.3.0", | ||
"uuid": "46c80e86-a08b-4978-a56c-f23f7505b1cb", | ||
"mavenUrls": ["http://raw.githubusercontent.com/snobotsim/maven_repo/master/development"], | ||
"jsonUrl": "http://raw.githubusercontent.com/snobotsim/maven_repo/master/release/SnobotSim.json", | ||
"javaDependencies": [ | ||
{ | ||
"groupId": "org.snobotv2", | ||
"artifactId": "snobot_sim_java", | ||
"version": "2021.0.1.0" | ||
"version": "2021.0.3.0" | ||
} | ||
], | ||
"jniDependencies": [], | ||
"cppDependencies": [] | ||
} | ||
} |
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
122 changes: 122 additions & 0 deletions
122
libraries/linters/gradlerio_versions/lint_gradlerio_versions.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 |
---|---|---|
@@ -0,0 +1,122 @@ | ||
import sys | ||
import os | ||
import re | ||
import collections | ||
import json | ||
import shutil | ||
|
||
|
||
def get_build_file_versions(build_files): | ||
versions = collections.defaultdict(list) | ||
|
||
for build_file in build_files: | ||
with open(build_file, 'r') as f: | ||
for line in f.readlines(): | ||
matches = re.search(r'edu\.wpi\.first\.GradleRIO.* version "(.*)"', line) | ||
if matches: | ||
version = matches.group(1) | ||
versions[version].append(build_file) | ||
|
||
return versions | ||
|
||
|
||
def get_vendor_deps_versions(vendor_deps): | ||
vendor_versions = {} | ||
for vendor_name, vendor_files in vendor_deps.items(): | ||
versions = collections.defaultdict(list) | ||
|
||
for vendor_file in vendor_files: | ||
with open(vendor_file, 'r') as f: | ||
vendor_dep = json.load(f) | ||
version = vendor_dep['version'] | ||
versions[version].append(vendor_file) | ||
|
||
vendor_versions[vendor_name] = versions | ||
|
||
return vendor_versions | ||
|
||
|
||
def get_versions(base_directory): | ||
build_files = [] | ||
vendor_deps = collections.defaultdict(list) | ||
|
||
for root, _, files in os.walk(base_directory): | ||
for f in files: | ||
full_file = os.path.join(root, f) | ||
if f == "build.gradle": | ||
build_files.append(full_file) | ||
elif "vendordeps" in os.path.dirname(full_file): | ||
vendor_deps[f].append(full_file) | ||
|
||
gradlerio_versions = get_build_file_versions(build_files) | ||
vendor_deps_versions = get_vendor_deps_versions(vendor_deps) | ||
|
||
return gradlerio_versions, vendor_deps_versions | ||
|
||
|
||
def fix_vendordep_version(versions): | ||
sorted_versions = sorted(list(versions.keys()), reverse=True) | ||
newest_version = sorted_versions[0] | ||
newest_file = versions[newest_version][0] | ||
|
||
print(f"Using {newest_file}, version {newest_version}") | ||
|
||
for version, files in versions.items(): | ||
if version == newest_version: | ||
continue | ||
|
||
for f in files: | ||
print(f" Fixing {f}") | ||
shutil.copy(newest_file, f) | ||
|
||
|
||
def fix_gradlerio_build_file(versions): | ||
sorted_versions = sorted(list(versions.keys()), reverse=True) | ||
newest_version = sorted_versions[0] | ||
newest_file = versions[newest_version][0] | ||
print(f"Using {newest_file}, version {newest_version}") | ||
|
||
for version, files in versions.items(): | ||
if version == newest_version: | ||
continue | ||
|
||
for bad_file in files: | ||
print(f" Fixing {bad_file}") | ||
new_content = "" | ||
with open(bad_file, 'r') as f: | ||
for line in f.readlines(): | ||
matches = re.search(r'edu\.wpi\.first\.GradleRIO.* version "(.*)"', line) | ||
if matches: | ||
new_content += f' id "edu.wpi.first.GradleRIO" version "{newest_version}"\n' | ||
else: | ||
new_content += line | ||
|
||
with open(bad_file, 'w') as f: | ||
f.write(new_content) | ||
|
||
|
||
def main(): | ||
|
||
this_dir = os.path.dirname(os.path.realpath(__file__)) | ||
base_directory = os.path.join(this_dir, "..", "..", "..") | ||
|
||
gradlerio_versions, vendor_deps_versions = get_versions(base_directory) | ||
|
||
passed = True | ||
|
||
|
||
if len(gradlerio_versions) != 1: | ||
fix_gradlerio_build_file(gradlerio_versions) | ||
passed = False | ||
|
||
for vendor_name, vendor_versions in vendor_deps_versions.items(): | ||
if len(vendor_versions) != 1: | ||
passed = False | ||
fix_vendordep_version(vendor_versions) | ||
|
||
if not passed: | ||
sys.exit(-1) | ||
|
||
|
||
if __name__ == "__main__": | ||
main() |
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.