-
Notifications
You must be signed in to change notification settings - Fork 122
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
349941b
commit 604b153
Showing
7 changed files
with
136 additions
and
172 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 }} | ||
|
||
|
This file was deleted.
Oops, something went wrong.