Skip to content

start adding linter #8

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 70 commits into from
Feb 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
70 commits
Select commit Hold shift + click to select a range
5194209
start adding linter
Oddant1 Jan 17, 2025
c542cfc
Merge pull request #2 from Oddant1/linting-action
Oddant1 Jan 21, 2025
e7eb7d6
Whitespace error?
Oddant1 Jan 21, 2025
f3763cf
Simplify condition
Oddant1 Jan 21, 2025
125ca72
Different way to get diff
Oddant1 Jan 21, 2025
52a4fb4
HEAD not main
Oddant1 Jan 21, 2025
2f1155d
need fetch depth 2?
Oddant1 Jan 21, 2025
bb5d79b
No leading /
Oddant1 Jan 21, 2025
979daf7
abspath
Oddant1 Jan 21, 2025
90406c8
put on one line
Oddant1 Jan 21, 2025
a5495d3
find
Oddant1 Jan 21, 2025
1cc258c
Make find narrower
Oddant1 Jan 21, 2025
9d971be
no sparse checkout
Oddant1 Jan 21, 2025
6e050ff
View output
Oddant1 Jan 21, 2025
1e446e9
Different syntax to store outputs
Oddant1 Jan 21, 2025
7c6f398
change get outputs syntax
Oddant1 Jan 21, 2025
394510f
change get outputs syntax
Oddant1 Jan 21, 2025
2916197
Close quote
Oddant1 Jan 21, 2025
97fb4f1
cleanup
Oddant1 Jan 21, 2025
fc7d6ee
Get all files in diff
Oddant1 Jan 21, 2025
da85e97
Add back requirements to run
Oddant1 Jan 21, 2025
37d0cd2
No leading /
Oddant1 Jan 21, 2025
a7d634b
Update comments
Oddant1 Jan 21, 2025
474b798
Only lint files in plugins and assert their names match pattern
Oddant1 Jan 21, 2025
d098632
Refactor vars
Oddant1 Jan 21, 2025
cfe7d1f
view diff
Oddant1 Jan 21, 2025
9c4d07d
multi line
Oddant1 Jan 21, 2025
f69b6ac
Make \n a string
Oddant1 Jan 21, 2025
ddad529
typo
Oddant1 Jan 21, 2025
cc5f3be
Get rid of end delimeter
Oddant1 Jan 21, 2025
b62a452
EOF
Oddant1 Jan 21, 2025
67d8af9
cleanup
Oddant1 Jan 21, 2025
c881cd1
github token
Oddant1 Jan 21, 2025
ad1154b
Get environment-files
Oddant1 Jan 22, 2025
1205469
Merge
Oddant1 Feb 12, 2025
b5366df
play with getting env files
Oddant1 Feb 12, 2025
f0e4c2c
Different debug
Oddant1 Feb 19, 2025
d7ce8c8
Maybe the button will work
Oddant1 Feb 19, 2025
d12cf16
Merge branch 'linting-action'
Oddant1 Feb 19, 2025
2f0943f
more info
Oddant1 Feb 19, 2025
5980b10
Move that
Oddant1 Feb 19, 2025
6be59c3
Save ENV_FILES
Oddant1 Feb 19, 2025
c5c1619
Try to set up matrix over env files
Oddant1 Feb 19, 2025
acb206a
Parse output
Oddant1 Feb 19, 2025
8919aa5
Get step?
Oddant1 Feb 19, 2025
c6c1d8c
Maybe the step name at end
Oddant1 Feb 19, 2025
0668149
WHY
Oddant1 Feb 19, 2025
94ea4fe
Clean up names
Oddant1 Feb 19, 2025
ef73ada
Test
Oddant1 Feb 19, 2025
c56904f
Just outputs
Oddant1 Feb 19, 2025
58c74a1
toJSON
Oddant1 Feb 19, 2025
c0f20cf
AAAAAAAAAHHHHHHHHHHHHHHHH
Oddant1 Feb 19, 2025
817d5a9
Maybe like this
Oddant1 Feb 19, 2025
ddf022c
Back to matrix
Oddant1 Feb 19, 2025
110980e
Different var name/access
Oddant1 Feb 19, 2025
47e6438
Try making env
Oddant1 Feb 19, 2025
9a01a9b
Need -f
Oddant1 Feb 19, 2025
ff172b0
Job name caps
Oddant1 Feb 19, 2025
2073af4
env create
Oddant1 Feb 19, 2025
80d4a82
Conda init
Oddant1 Feb 19, 2025
37eb9cf
Steal from ALP
Oddant1 Feb 19, 2025
31f3271
step names
Oddant1 Feb 19, 2025
09af28e
Source file
Oddant1 Feb 19, 2025
8b1f357
./test as prefix
Oddant1 Feb 19, 2025
99eb7ca
Use env var
Oddant1 Feb 19, 2025
cf6b439
matrix the os as well
Oddant1 Feb 20, 2025
ce87b0d
Setup run conditions
Oddant1 Feb 20, 2025
4ad0d16
Comments in yml
Oddant1 Feb 20, 2025
7b5bb95
Let people have their own stuff in there
Oddant1 Feb 20, 2025
c0cab9f
Formatting and comments in lint.py
Oddant1 Feb 20, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions .github/scripts/lint.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
import os
import re
import sys
import yaml
import requests


DIR = 'plugins'

KEY_SET = set(['owner', 'name', 'branch', 'docs'])
ENV_FILE_REGEX = '.*-qiime2-.*-20[0-9][0-9]\.([1-9]|1[0-2])\.yml'
GITHUB_BASE_URL = "https://api.github.com"

env_urls = []

GITHUB_TOKEN = sys.argv[1]
GITHUB_BASE_URL = 'https://api.github.com'


def lint(yml):
# Assert corrrect keys
assert set(yml.keys()) == KEY_SET

# Get the docs URL assert 200
response = requests.get(yml['docs'])
assert response.status_code == 200

# Put together the owner/name:branch
url = f'{GITHUB_BASE_URL}/repos/{yml['owner']}/{yml['name']}/contents/environment-files'
headers = {
'Authorization': f'token: {GITHUB_TOKEN}',
'X-GitHub-Api-Version': '2022-11-28'
}
query_params = {
'owner': yml['owner'],
'repo': yml['name'],
'ref': yml['branch'],
'path': '/environment-files/'
}

# Get all files in the /environment-files/ folder
response = requests.get(url, headers=headers, params=query_params)
envs = response.json()

# If the file matches the regex to be a QIIME 2 environment-file then keep
# track of its download URL
for env in envs:
if re.search(ENV_FILE_REGEX, env['name']) is not None:
env_urls.append(env['download_url'])


if __name__ == "__main__":
GITHUB_TOKEN = sys.argv[1]
files = sys.argv[2:]

for file in files:
head, tail = os.path.split(file)
file_name, file_ext = os.path.splitext(tail)

# We only care about files added to the plugins dir
if head == DIR:
with open(file, 'r') as fh:
yml = yaml.safe_load(fh)
lint(yml)

with open(os.environ['GITHUB_OUTPUT'], 'a') as fh:
fh.write(f'ENV_FILES={env_urls}\n')
84 changes: 84 additions & 0 deletions .github/workflows/lint-pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
name: lint-pr

# Run on PR changing files in plugins dir against main
on:
pull_request:
branches:
- 'main'
paths:
- '/plugins/**'

jobs:
lint-yml:
runs-on: ubuntu-latest
outputs:
ENV_FILES: ${{ steps.lint.outputs.ENV_FILES }}

steps:
# Checkout new commit and prior HEAD
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 2

# Get diff
# This feels odd to me got it from
# https://docs.github.com/en/actions/writing-workflows/choosing-what-your-workflow-does/workflow-commands-for-github-actions#multiline-strings
- name: Get Diff
run: |
{
echo 'DIFF<<EOF'
git diff --name-only HEAD~ HEAD
echo EOF
} >> "$GITHUB_ENV"

# Lint all plugins/** files in diff (filtering of diff occurs in Python)
# Also gets all env files in added plugins for env testing
- name: Lint Yml and Get Env Files
id: lint
run: python .github/scripts/lint.py ${{ secrets.GITHUB_TOKEN }} $DIFF

# Install all envs found and at least make sure `qiime info` runs
# TODO: Make this attempt to run pytest?
test-envs:
needs: lint-yml
strategy:
matrix:
os: [ubuntu-latest, macos-13]
url: ${{ fromJSON(needs.lint-yml.outputs.ENV_FILES) }}
runs-on: ${{ matrix.os }}
env:
prefix: ./test

steps:
- name: Set up Miniconda
uses: conda-incubator/setup-miniconda@v3
with:
activate-environment: ''
architecture: 'x64'
auto-activate-base: true
miniconda-version: 'latest'

# Hacky stff to make it so I can activate the conda env for testing
- name: Set up Test Environment
env:
url: ${{ matrix.url }}
run: |
conda env create -y -p ${{ env.prefix }} -f $url
mkdir -p ${{ env.prefix }}/etc
cat <<EOF > '${{ env.prefix }}/etc/activate.sh'
. "$CONDA/etc/profile.d/conda.sh"
conda activate '${{ env.prefix }}'
EOF
chmod +x 'test/etc/activate.sh'

- name: Test
run: |
source ${{ env.prefix }}/etc/activate.sh
conda activate ${{ env.prefix }}
qiime info

# Grab the target repo and validate it?
# Description?
# README?
# Env files?