Skip to content

Commit

Permalink
Merge pull request #1539 from concord-consortium/188397633-run-regres…
Browse files Browse the repository at this point in the history
…sion

setup github actions for run regression label
  • Loading branch information
scytacki authored Oct 9, 2024
2 parents 360d8aa + fb6d8dd commit a9b2e3f
Show file tree
Hide file tree
Showing 4 changed files with 151 additions and 5 deletions.
4 changes: 4 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@ on:
- 'v3/**' # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#example-excluding-paths
- '.github/workflows/v3.yml'
- '.github/workflows/build-num-increment.yml'
- '.github/workflows/run-regression-label.yml'
- '.github/workflows/v3-regression.yml'
- '.github/workflows/release-v3-production.yml'
- '.github/workflows/release-v3-staging.yml'
tags-ignore:
- '3.*'
branches-ignore:
Expand Down
44 changes: 44 additions & 0 deletions .github/workflows/run-regression-label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
name: Regression Label

on:
pull_request:
types: [ labeled ]
jobs:
re_run:
# only continue if a push or PR labeled with 'run regression'
if: github.event.label.name == 'run regression'
runs-on: ubuntu-latest
permissions:
actions: write
steps:
- name: Re Run last push
# get the last regression run triggered by a pull, and get this run's id
# then rerun the run
# if the run id can't be found the rerun command will fail which should
# fail the job
# When the run hasn't finished yet, we try to cancel the run
# and wait 30s for it to finish canceling before trying to re-run it.
# If the run isn't complete the rerun command prints this message:
# returned: run 6410886572 cannot be rerun; its workflow file may be broken
run: |
run_id=$(gh run list -e push -b ${{github.head_ref}} -w 'CI v3 Regression' -L 1 --json databaseId -q '.[0].databaseId')
run_status=$(gh run view $run_id --json status -q '.status')
if [[ "$run_status" != "completed" ]]
then
echo "run $run_id is $run_status, trying to cancel"
gh run cancel $run_id
count=0
until [[ "$run_status" == "completed" || $count -gt 15 ]]
do
sleep 2
count=$((count+1))
run_status=$(gh run view $run_id --json status -q '.status')
echo "run: $run_id, status: $run_status, try: $count"
done
fi
echo "rerunning $run_id"
gh run rerun $run_id
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# set repository so we don't have to check out all of the code
GH_REPO: ${{github.repository}}
99 changes: 99 additions & 0 deletions .github/workflows/v3-regression.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,99 @@
# If this name is changed we also need to change it in run-regression-label.yml
name: CI v3 Regression

on:
push:
paths: # only run this workflow if it contains v3 files
- 'v3/**' # https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#example-including-paths
- '.github/workflows/v3-regression.yml'
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
prepare:
runs-on: ubuntu-latest
outputs:
pr_labels: ${{ steps.pr.outputs.labels }}
# If there is no label then steps.run_regression.outputs.value will be "false" which
# being a string is actually considered true, so fromJSON is needed to turn `"false"` into `false`.
# If we are on the 'main' branch then run the regression tests regardless of the PR label
run_regression: ${{ fromJSON(steps.run_regression.outputs.value) || github.ref_name == 'main' }}
permissions:
pull-requests: read
steps:
- name: Get PR labels
id: pr
# the github.event.pull_request.labels is not available when a build
# is triggered by a push. So we use the `gh` CLI to get info about the PR for the
# current branch.
# - If the branch doesn't have a PR yet, then the `gh pr view` command fails with
# the message: no pull requests found for branch "pr-label-test"
# - If the same branch is part of multiple PRs, it isn't clear what will
# happen, but that should be very unusual.
run: echo "labels=$(gh pr view ${{ github.ref_name }} --json labels -q '.labels' || echo "[]")" >> $GITHUB_OUTPUT
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# set repository so we don't have to check out all of the code
GH_REPO: ${{github.repository}}
- name: Print PR labels
run: echo "PR labels ${{ steps.pr.outputs.labels }}"
- name: Get run_regression
id: run_regression
run: echo "value=${{ contains(fromJSON(steps.pr.outputs.labels).*.name, 'run regression') }}" >> $GITHUB_OUTPUT
cypress:
needs: ['prepare']
# only run the regression tests if the PR is labeled.
if: fromJSON(needs.prepare.outputs.run_regression)
runs-on: ubuntu-latest
strategy:
# when one test fails, DO NOT cancel the other
# containers, because this will kill Cypress processes
# leaving the Dashboard hanging ...
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
# run multiple copies of the current job in parallel [1, ..., n]
containers: [1, 2, 3, 4, 5]
steps:
- name: Checkout
uses: actions/checkout@v4
- uses: actions/cache@v4
with:
path: v3/node_modules/.cache/webpack/
key: ${{ github.head_ref || github.ref_name }}-webpack-build
restore-keys: |
main-webpack-build
- uses: cypress-io/github-action@v6
with:
working-directory: v3
start: npm start
wait-on: 'http://localhost:8080'
# add timeout of 5 minutes to start
wait-on-timeout: 300
# only record the results to dashboard.cypress.io if CYPRESS_RECORD_KEY is set
record: ${{ !!secrets.CYPRESS_RECORD_KEY }}
# only do parallel if we have a record key
parallel: ${{ !!secrets.CYPRESS_RECORD_KEY }}
browser: chrome
# TODO: this currently will re-run the smoke test, once we have a dedicated smoke
# test that should be excluded
# spec: cypress/e2e/**
group: 'Regression Tests'
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
# pass GitHub token to allow accurately detecting a build vs a re-run build
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
# turn on code coverage when running npm start
# so far we've been using a webpack coverage-istanbul-loader for this
# but there has been work on using the code coverage support in the browser directly,
# which should be much faster
CODE_COVERAGE: true
# Also turn on the code coverage tasks in cypress itself, these are disabled
# by default.
CYPRESS_coverage: true
- name: Upload coverage to Codecov
uses: codecov/codecov-action@v4
with:
token: ${{ secrets.CODECOV_TOKEN }}
flags: cypress
9 changes: 4 additions & 5 deletions .github/workflows/v3.yml
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,6 @@ jobs:
# leaving the Dashboard hanging ...
# https://github.com/cypress-io/github-action/issues/48
fail-fast: false
matrix:
# run multiple copies of the current job in parallel [1, ..., n]
containers: [1, 2, 3, 4, 5]
steps:
- name: Checkout
uses: actions/checkout@v4
Expand All @@ -66,9 +63,11 @@ jobs:
wait-on-timeout: 300
# only record the results to dashboard.cypress.io if CYPRESS_RECORD_KEY is set
record: ${{ !!secrets.CYPRESS_RECORD_KEY }}
# only do parallel if we have a record key
parallel: ${{ !!secrets.CYPRESS_RECORD_KEY }}
browser: chrome
# only run a single test
# TODO: setup a special test for this purpose
spec: cypress/e2e/import-v2.spec.ts
group: 'Smoke Tests'
env:
# pass the Dashboard record key as an environment variable
CYPRESS_RECORD_KEY: ${{ secrets.CYPRESS_RECORD_KEY }}
Expand Down

0 comments on commit a9b2e3f

Please sign in to comment.