From 0035df328ec0b16c08d7531ddb383c7fd0d0b1f2 Mon Sep 17 00:00:00 2001 From: Lukas K Date: Thu, 3 Sep 2020 00:31:42 +0200 Subject: [PATCH] add PR comment workflow --- .github/workflows/comment.yml | 34 ++++++++++++++++++++++++++++++++++ scripts/ci/add_pool.py | 2 +- scripts/ci/diff_to_base.py | 9 +++++---- scripts/ci/update_pool.py | 10 ++++++---- 4 files changed, 46 insertions(+), 9 deletions(-) create mode 100644 .github/workflows/comment.yml diff --git a/.github/workflows/comment.yml b/.github/workflows/comment.yml new file mode 100644 index 000000000..2fbb3195a --- /dev/null +++ b/.github/workflows/comment.yml @@ -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 + diff --git a/scripts/ci/add_pool.py b/scripts/ci/add_pool.py index 423bc1920..6d928b741 100644 --- a/scripts/ci/add_pool.py +++ b/scripts/ci/add_pool.py @@ -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) diff --git a/scripts/ci/diff_to_base.py b/scripts/ci/diff_to_base.py index 3e733e65b..c7135a68a 100644 --- a/scripts/ci/diff_to_base.py +++ b/scripts/ci/diff_to_base.py @@ -3,10 +3,11 @@ 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 : @@ -14,6 +15,6 @@ 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) diff --git a/scripts/ci/update_pool.py b/scripts/ci/update_pool.py index b25011af7..dd4d9d7f3 100644 --- a/scripts/ci/update_pool.py +++ b/scripts/ci/update_pool.py @@ -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))