Skip to content

Commit

Permalink
Add GitHub Action.
Browse files Browse the repository at this point in the history
  • Loading branch information
mrstegeman committed Sep 16, 2019
1 parent 1443c13 commit 37f177c
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 35 deletions.
23 changes: 23 additions & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check changes

on:
pull_request:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jsonschema
- name: Check changes
run: |
./test-pr.py
23 changes: 23 additions & 0 deletions .github/workflows/push.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Check full list

on:
push:
branches:
- master

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up Python 3.7
uses: actions/setup-python@v1
with:
python-version: 3.7
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install jsonschema
- name: Check full list
run: |
./tools/check-list.py
8 changes: 0 additions & 8 deletions .travis.yml

This file was deleted.

52 changes: 52 additions & 0 deletions test-pr.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
#!/usr/bin/env python3

import json
import os
import re
import shlex
import sys
import urllib.request


def main():
with open(os.environ['GITHUB_EVENT_PATH']) as f:
event = json.load(f)

url = 'https://api.github.com/repos/{}/pulls/{}/files'.format(
os.environ['GITHUB_REPOSITORY'],
event['pull_request']['number'],
)

r = urllib.request.Request(url, headers={'Accept': 'application/json'})
f = urllib.request.urlopen(r)
files = json.load(f)
files = [x['filename'] for x in files]

addons_changed = []
schema_changed = False
checker_changed = False
for fname in files:
match = re.match(r'^addons/([^/]+)\.json$', fname)
if match:
addons_changed.append(match.group(1))
elif re.match(r'^schema/.+$', fname):
schema_changed = True
elif fname == 'tools/check-list.py':
checker_changed = True

if schema_changed or checker_changed:
return os.system('./tools/check-list.py')

if len(addons_changed) > 0:
return os.system('./tools/check-list.py {}'.format(
' '.join([shlex.quote(a) for a in addons_changed]))
)

return 0


if __name__ == '__main__':
# Sometimes, check-list.py returns 256. Apparently, sys.exit() will only
# accept 0-255, so we have to adjust. Weird.
if main() > 0:
sys.exit(1)
27 changes: 0 additions & 27 deletions travis.sh

This file was deleted.

0 comments on commit 37f177c

Please sign in to comment.