Skip to content

Commit

Permalink
add PR comment workflow
Browse files Browse the repository at this point in the history
  • Loading branch information
carrotIndustries committed Sep 2, 2020
1 parent 174657e commit 0035df3
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 9 deletions.
34 changes: 34 additions & 0 deletions .github/workflows/comment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name: Comment on PR

on:
pull_request_target:
branches: [ master ]

jobs:
check:
runs-on: ubuntu-latest
container: horizoneda/horizon:latest
steps:
- uses: actions/checkout@v2
with:
path: pool
- name: fetch master
if: github.event_name == 'pull_request'
run: git fetch --no-tags --prune --progress --no-recurse-submodules --depth=1 origin ${{ github.base_ref }}:${{ github.base_ref }}
working-directory: pool
- name: add pool
run: python3 scripts/ci/add_pool.py
- name: update pool
run: python3 scripts/ci/update_pool.py >> comment.md
- name: print diff to base
if: github.event_name == 'pull_request'
run: python3 scripts/ci/diff_to_base.py ${{ github.base_ref }} >> comment.md
- name: print comment
if: ${{ always() }}
run: cat comment.md
- uses: harupy/comment-on-pr@master
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
filename: comment.md

2 changes: 1 addition & 1 deletion scripts/ci/add_pool.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import horizon
horizon.PoolManager.add_pool(".")
horizon.PoolManager.add_pool("pool")
print("added pools")
for k,v in horizon.PoolManager.get_pools().items() :
print(k,v)
9 changes: 5 additions & 4 deletions scripts/ci/diff_to_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,18 @@
import sys
base = sys.argv[1]

repo = pygit2.Repository(".")
conn = sqlite3.connect("pool.db")
repo = pygit2.Repository("pool")
conn = sqlite3.connect("pool/pool.db")
cur = conn.cursor()

print("# Diff to base")

diff = repo.diff("HEAD", base)
for delta in diff.deltas :
filename = delta.new_file.path
cur.execute("SELECT type, name FROM all_items_view WHERE filename=?", (filename,))
r = cur.fetchone()
if r is not None :
print("New %s '%s': %s"%(r[0], r[1], filename))
print(" - New %s '%s': %s"%(r[0], r[1], filename))
else:
print("%s not found in pool"%filename)
print(" - %s not found in pool"%filename)
10 changes: 6 additions & 4 deletions scripts/ci/update_pool.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,19 @@
files = set()
error = False

print("# Pool Update")

def cb(st, filename, msg) :
global error
if st in (horizon.Pool.UPDATE_STATUS_ERROR, horizon.Pool.UPDATE_STATUS_FILE_ERROR) :
print("ERROR", st, filename, msg)
print(" - ERROR", st, filename, msg)
error = True
if st == horizon.Pool.UPDATE_STATUS_FILE :
files.add(filename)

print("updating pool...")
horizon.Pool.update(".", cb)
print("%d files "% len(files))
horizon.Pool.update("pool", cb)

if error :
exit(1)
else :
print("okay, %d files "% len(files))

0 comments on commit 0035df3

Please sign in to comment.