Skip to content

Commit

Permalink
Add files via upload
Browse files Browse the repository at this point in the history
actionlint scripts (README, download from csv, parsing results)
  • Loading branch information
Chloe2330 authored Apr 25, 2024
1 parent 8fbda42 commit f277cce
Show file tree
Hide file tree
Showing 4 changed files with 11,711 additions and 0 deletions.
43 changes: 43 additions & 0 deletions actionlint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
# Actionlint Script
## Run actionlint on every repository in the script's directory.

### **Quick Start**
Clone this repository.
```bash
git clone https://github.com/Chloe2330/repo-runner.git
```

Install `actionlint` [here](https://github.com/rhysd/actionlint) in the same directory.

Clone the repositories to run actionlint on.

The following reposities were used to produce the output files in the sample results folder and the sample `output.json` file:
```bash
git clone https://github.com/abrt/abrt.git
git clone https://github.com/argoproj/argo-cd.git
git clone https://github.com/vmware/govmomi.git
git clone https://github.com/AcademySoftwareFoundation/openexr.git
git clone https://github.com/aliasrobotics/RVD.git
git clone https://github.com/appneta/tcpreplay.git
git clone https://github.com/YetiForceCompany/YetiForceCRM.git
```

If actionlint does not detect any issues with the workflow configuration file, the ouput text file will be empty.

### **Usage**
`./script.py actionlint` runs actionlint on every repository\
`./script.py --json` consolidates all text files in the results directory in an `output.json ` file\
`./script.py --help` prints script usage\
`./script.py --clear` deletes all folders and output files in the results directory

### **Other Features**
`./read_csv.py [csv file name]` reads and downloads repositories from a csv file\
`./read_csv.py --help` prints script usage

### **Work in Progress**
- Fix issues with multiple arguments

### **Additional Notes**
- `script.py` will run any command on every repository in its directory (i.e. `./script.py "git ls-remote --heads"`).
- `actionlint` is not compatible with workflows that do not use GitHub Actions (error: no project was found in any parent directories of ".").
- `read_csv.py` is only compatible with the csv format shown in `sample.csv`, modify the script based on the csv format that is being used
75 changes: 75 additions & 0 deletions actionlint/read_csv.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#!/usr/bin/env python3
import os
import sys
import subprocess
import csv

if (__name__ != "__main__"):
exit(1)

if len(sys.argv) != 2:
print("Please enter a valid input.")
exit(1)

if sys.argv[1] == "--help":
print("This script will download all the repositories in a csv file.")
print("Usage: read_csv.py [csv file name]")
print("Example: ./read_csv.py sample.csv")
exit(0)

if sys.argv[1] == "--sparse-checkout":
# Access the script's directory and get all of its repositories
os.chdir(os.path.dirname(__file__))
repos = []
for item in os.listdir('.'):
if os.path.exists(item + "/.git/config"):
repos.append(item)

# Execute the command on every repository in the folder
for repo in repos:
os.chdir(repo)
commandOne = ['git', 'sparse-checkout', 'init', '--cone']
commandTwo = ['git', 'sparse-checkout', 'set', '.github/workflows']
commandThree = ['git', 'checkout', '@']
try:
# Set up sparse-checkout
subprocess.run(commandOne, check=True)
print(f"Sparse-checkout setup successfully: {repo}")
except subprocess.CalledProcessError as e:
print(f"Error setting up sparse-checkout repository {repo}: {e}")
try:
# Checkout the workflows folder
subprocess.run(commandTwo, check=True)
print(f"Successfully checked out workflows folder: {repo}")
except subprocess.CalledProcessError as e:
print(f"Error checking out workflows folder {repo}: {e}")
try:
# Switch to @
subprocess.run(commandThree, check=True)
print(f"Switched to @: {repo}")
except subprocess.CalledProcessError as e:
print(f"Could not switch to @ {repo}: {e}")
os.chdir(os.path.dirname(__file__))
exit(0)

repos = []

os.chdir(os.path.dirname(__file__))
file_name = sys.argv[1]
file_path = os.path.join(os.getcwd(), file_name)

# Open the csv file and read its contents
with open(file_path, 'r') as file:
csv_reader = csv.DictReader(file, delimiter=',')
for row in csv_reader:
# Each 'row' variable represents a dictionary where keys are column names
repos.append(row["URL"])

for url in repos:
command = ['git', 'clone', '--no-checkout', url]
try:
# Clone each repository
subprocess.run(command, check=True)
print(f"Repository cloned successfully: {url}")
except subprocess.CalledProcessError as e:
print(f"Error cloning repository {url}: {e}")
Loading

0 comments on commit f277cce

Please sign in to comment.