Skip to content
This repository has been archived by the owner on Oct 25, 2021. It is now read-only.

Commit

Permalink
Adding linter to make sure all the versions are the same (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
pjreiniger authored Oct 2, 2021
1 parent a2f4654 commit 12a4713
Show file tree
Hide file tree
Showing 14 changed files with 570 additions and 308 deletions.
30 changes: 30 additions & 0 deletions .github/workflows/lint.yml
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() }}
8 changes: 4 additions & 4 deletions codelabs/basic_simulator/vendordeps/SnobotSim.json
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": []
}
}
6 changes: 3 additions & 3 deletions codelabs/pid/vendordeps/SnobotSim.json
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
{
"fileName": "SnobotSim.json",
"name": "SnobotSim",
"version": "2021.0.2.0",
"uuid": "f70acdbb-3f33-4dd5-a1f5-00a3bc109bcd",
"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.2.0"
"version": "2021.0.3.0"
}
],
"jniDependencies": [],
Expand Down
122 changes: 122 additions & 0 deletions libraries/linters/gradlerio_versions/lint_gradlerio_versions.py
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()
2 changes: 1 addition & 1 deletion y2020/Testboard/build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
plugins {
id "java"
id "edu.wpi.first.GradleRIO" version "2020.2.2"
id "edu.wpi.first.GradleRIO" version "2021.3.1"
}

sourceCompatibility = JavaVersion.VERSION_11
Expand Down
Loading

0 comments on commit 12a4713

Please sign in to comment.