Skip to content

Commit

Permalink
Add arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
deathaxe committed Nov 26, 2023
1 parent 35355e7 commit 6b4a6bc
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 18 deletions.
42 changes: 25 additions & 17 deletions action.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,18 @@
even though they are generated at load time.
Arguments:
--channel=channel.json
Channel filename to test
--repository=repository.json
Repository filename to test
--test-repositories
Also generates tests for all repositories in `channel.json` (the http
ones).
"""

import argparse
import os
import re
import json
Expand All @@ -25,18 +32,12 @@

generator_method_type = 'method'


if hasattr(sys, 'argv'):
arglist = ['--test-repositories']
# Extract used arguments from commandline an strip them for
# unittest.main
userargs = [arg for arg in sys.argv if arg in arglist]
for arg in userargs:
if arg in sys.argv:
sys.argv.remove(arg)
else:
userargs = []

parser = argparse.ArgumentParser()
parser.add_argument('--channel', default='channel.json')
parser.add_argument('--repository', default='repository.json')
parser.add_argument('--test-repositories', action='store_true')
userargs, unittesting_args = parser.parse_known_args()
sys.argv = sys.argv[:1] + unittesting_args

################################################################################
# Utilities
Expand Down Expand Up @@ -704,7 +705,10 @@ def _write(cls, stream, string):
stream.flush()


@unittest.skipIf(not os.path.isfile('channel.json'), "No channel.json found")
@unittest.skipIf(
not userargs.channel or not os.path.isfile(userargs.channel),
"No {} found".format(userargs.channel)
)
class DefaultChannelTests(TestContainer, unittest.TestCase):
maxDiff = None

Expand All @@ -716,8 +720,8 @@ def setUpClass(cls):
# We need cls.j this for generating tests
@classmethod
def pre_generate(cls):
if not hasattr(cls, 'j') and os.path.isfile('channel.json'):
with _open('channel.json') as f:
if not hasattr(cls, 'j') and os.path.isfile(userargs.channel):
with _open(userargs.channel) as f:
cls.source = f.read().decode('utf-8', 'strict')
cls.j = json.loads(cls.source)

Expand Down Expand Up @@ -749,7 +753,7 @@ def test_channel_keys(self):
self.assertIsInstance(repo, str)

def test_indentation(self):
return self._test_indentation('channel.json', self.source)
return self._test_indentation(userargs.channel, self.source)

def test_channel_repositories(self):
repos = self.j['repositories']
Expand All @@ -762,7 +766,7 @@ def test_channel_repositories(self):

@classmethod
def generate_repository_tests(cls, stream):
if "--test-repositories" not in userargs:
if not userargs.test_repositories:
# Only generate tests for all repositories (those hosted online)
# when run with "--test-repositories" parameter.
return
Expand All @@ -782,6 +786,10 @@ def generate_repository_tests(cls, stream):
stream.flush()


@unittest.skipIf(
not userargs.repository or not os.path.isfile(userargs.repository),
"No {} found".format(userargs.repository)
)
class DefaultRepositoryTests(TestContainer, unittest.TestCase):
maxDiff = None

Expand Down
25 changes: 24 additions & 1 deletion action.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,32 @@
name: Sublime Text Schema Reviewer
description: GitHub Action for reviewing package package control schema

inputs:
channel:
description: Channel file to check
required: false
default: channel.json
test_repositories:
description: Check channel's external https repositories
required: false
default: false
repository:
description: Repository file to check
required: false
default: repository.json

runs:
using: 'composite'
steps:
- name: Run repository tests
shell: bash
run: python3 ${{ github.action_path }}/tests/test.py
run: |-
if [[ ${{ inputs.test_repositories }} == true ]]; then
flags=--test-repositories;
else
flags=
fi;
python3 "${{ github.action_path }}/action.py" \
--channel=${{ inputs.channel }} \
--repository=${{ inputs.repository }} \
flags

0 comments on commit 6b4a6bc

Please sign in to comment.