Skip to content

Commit

Permalink
ci: add pr update checker
Browse files Browse the repository at this point in the history
  • Loading branch information
nickofthyme committed Sep 13, 2021
1 parent 349941b commit 604b153
Show file tree
Hide file tree
Showing 7 changed files with 136 additions and 172 deletions.
28 changes: 0 additions & 28 deletions .github/workflows/api_extractor_check.yaml

This file was deleted.

40 changes: 0 additions & 40 deletions .github/workflows/auto_release.yaml

This file was deleted.

21 changes: 0 additions & 21 deletions .github/workflows/cleanup.yaml

This file was deleted.

32 changes: 0 additions & 32 deletions .github/workflows/deploy_docs.yaml

This file was deleted.

24 changes: 0 additions & 24 deletions .github/workflows/lint.yaml

This file was deleted.

136 changes: 136 additions & 0 deletions .github/workflows/pr_checker.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
name: 'PR Update Check'

on:
workflow_dispatch: # Trigger manually until pr push check is done
push:
branches:
- master # whenever master changes
schedule:
- cron: '0 0 * * *' # once a day

env:
ECH_NODE_VERSION: '14.x'
BASE_COMMIT_LIMIT: 10
CONTEXT: 'PR Update Check'

jobs:
fetch:
runs-on: ubuntu-latest
outputs:
matrix: ${{ steps.save.outputs.json }}
steps:
- name: Fetch GH pulls
id: fetch
uses: octokit/[email protected]
with:
route: GET /repos/{repo}/pulls?state=open
repo: ${{ github.repository }}
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Store matrix
id: save
uses: nickofthyme/object-remap@v1
with:
include.*.number: ${{ toJSON(fromJSON(steps.fetch.outputs.data).*.number) }}
include.*.title: ${{ toJSON(fromJSON(steps.fetch.outputs.data).*.title) }}
include.*.head_sha: ${{ toJSON(fromJSON(steps.fetch.outputs.data).*.head.sha) }}
include.*.base_ref: ${{ toJSON(fromJSON(steps.fetch.outputs.data).*.base.ref) }}
include.*.base_sha: ${{ toJSON(fromJSON(steps.fetch.outputs.data).*.base.sha) }}

base-status-check:
name: "PR #${{ matrix.number }} - ${{ matrix.title }}"
runs-on: ubuntu-latest
needs: fetch
strategy:
matrix: ${{ fromJSON(needs.fetch.outputs.matrix) }}
fail-fast: false
steps:
- name: Set pending status
uses: hkusu/status-create-action@v1
with:
sha: ${{ matrix.headSha }}
state: pending
target-url: "https://github.com/elastic/elastic-charts/actions/runs/${{ github.run_id }}"
description: "Checking if PR is up-to-date"
context: ${{ env.CONTEXT }}
- name: Git base compare
id: base-compare
uses: octokit/[email protected]
with:
route: GET /repos/{repo}/compare/{basehead}
repo: ${{ github.repository }}
basehead: "${{ matrix.baseRef }}...${{ matrix.baseSha }}"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- run: echo "${{ fromJSON(steps.base-compare.outputs.data).behind_by }}"
- run: echo "This pr is behind by ${{ fromJSON(steps.base-compare.outputs.data).behind_by }} commits"
- name: Set success status - in sync
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by == 0 }}
uses: hkusu/status-create-action@v1
with:
sha: ${{ matrix.headSha }}
state: success
target-url: "https://github.com/elastic/elastic-charts/actions/runs/${{ github.run_id }}"
description: PR is in up-to-date with upstream base
context: ${{ env.CONTEXT }}
- name: Git head compare
id: head-compare
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by > 0 }}
uses: octokit/[email protected]
with:
route: GET /repos/{repo}/compare/{basehead}
repo: ${{ github.repository }}
basehead: "${{ matrix.baseSha }}...${{ matrix.headSha }}"
env:
GITHUB_TOKEN: "${{ secrets.GITHUB_TOKEN }}"
- name: Check files changes
id: files-check
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by > 0 && fromJSON(steps.base-compare.outputs.data).behind_by <= env.BASE_COMMIT_LIMIT }}
shell: python
# TODO: find a better way to do this, possiblly custom action
run: |
import json
baseFiles = json.loads("""${{ toJSON(fromJSON(steps.base-compare.outputs.data).files.*.filename) }}""")
headFiles = json.loads("""${{ toJSON(fromJSON(steps.head-compare.outputs.data).files.*.filename) }}""")
# file intersection
files = list(filter(lambda x:x in baseFiles, headFiles))
hasStaleScreenshot = False
for file in files:
if file.startswith('integration/tests/__image_snapshots__/') and '/__diff_output__/' not in file:
hasStaleScreenshot = True;
print(f"::set-output name=hasStaleScreenshot::{str(hasStaleScreenshot).lower()}")
- name: Print output
run: echo ${{ steps.files-check.outputs.hasStaleScreenshot == 'true' }}
- name: Set failed status - out of sync with stale vrt
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by > 0 && fromJSON(steps.base-compare.outputs.data).behind_by <= env.BASE_COMMIT_LIMIT && steps.files-check.outputs.hasStaleScreenshot == 'true' }}
uses: hkusu/status-create-action@v1
with:
sha: ${{ matrix.headSha }}
state: failure
target-url: "https://github.com/elastic/elastic-charts/actions/runs/${{ github.run_id }}"
description: "PR has stale VRT screenshots. Please merge with ${{ matrix.baseRef }}."
context: ${{ env.CONTEXT }}
- name: Set success status - not in sync but no stale vrt
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by > 0 && fromJSON(steps.base-compare.outputs.data).behind_by <= env.BASE_COMMIT_LIMIT && steps.files-check.outputs.hasStaleScreenshot != 'true' }}
uses: hkusu/status-create-action@v1
with:
sha: ${{ matrix.headSha }}
state: success
target-url: "https://github.com/elastic/elastic-charts/actions/runs/${{ github.run_id }}"
description: "PR is ${{ fromJSON(steps.base-compare.outputs.data).behind_by }} commits behind with no stale VRT screenshots."
context: ${{ env.CONTEXT }}
- name: Set failed status - exceeds synced limit
if: ${{ fromJSON(steps.base-compare.outputs.data).behind_by > env.BASE_COMMIT_LIMIT }}
uses: hkusu/status-create-action@v1
with:
sha: ${{ matrix.headSha }}
state: failure
target-url: "https://github.com/elastic/elastic-charts/actions/runs/${{ github.run_id }}"
description: "PR is ${{ fromJSON(steps.base-compare.outputs.data).behind_by }} commits behind. Please merge with ${{ matrix.baseRef }}."
context: ${{ env.CONTEXT }}


27 changes: 0 additions & 27 deletions .github/workflows/unit_test.yaml

This file was deleted.

0 comments on commit 604b153

Please sign in to comment.