GHA: make element-web and cypress workflows reusable (#10969)

* GHA: make `element-web` workflow reusable

... so that we can call it from the js-sdk repo

* GHA: make `cypress.yaml` a reusable workflow

... so that we can call it from js-sdk

* GHA: give cypress.yaml a `rust-crypto` parameter

* Update .github/workflows/cypress.yaml

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>

* remove workflow_dispatch

---------

Co-authored-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Richard van der Hoff 2023-05-26 16:04:29 +01:00 committed by GitHub
parent 67313743fc
commit 3bba816b10
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 56 additions and 4 deletions

View file

@ -1,13 +1,33 @@
# Triggers after the layered build has finished, taking the artifact and running cypress on it # Triggers after the layered build has finished, taking the artifact and running cypress on it
#
# Also called by a workflow in matrix-js-sdk.
#
name: Cypress End to End Tests name: Cypress End to End Tests
on: on:
workflow_run: workflow_run:
workflows: ["Element Web - Build"] workflows: ["Element Web - Build"]
types: types:
- completed - completed
# support calls from other workflows
workflow_call:
inputs:
react-sdk-repository:
type: string
required: true
description: "The name of the github repository to check out and build."
rust-crypto:
type: boolean
required: false
description: "Enable Rust cryptography for the cypress run."
secrets:
CYPRESS_RECORD_KEY:
required: true
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch || github.run_id }} group: ${{ github.workflow }}-${{ github.event.workflow_run.head_branch || github.run_id }}
cancel-in-progress: ${{ github.event.workflow_run.event == 'pull_request' }} cancel-in-progress: ${{ github.event.workflow_run.event == 'pull_request' }}
jobs: jobs:
prepare: prepare:
name: Prepare name: Prepare
@ -129,11 +149,20 @@ jobs:
# XXX: We're checking out untrusted code in a secure context # XXX: We're checking out untrusted code in a secure context
# We need to be careful to not trust anything this code outputs/may do # We need to be careful to not trust anything this code outputs/may do
# #
# Note that we check out from the default repository, which is (for this workflow) the # Note that (in the absence of a `react-sdk-repository` input),
# we check out from the default repository, which is (for this workflow) the
# *target* repository for the pull request. # *target* repository for the pull request.
#
ref: ${{ steps.sha.outputs.sha }} ref: ${{ steps.sha.outputs.sha }}
persist-credentials: false persist-credentials: false
path: matrix-react-sdk path: matrix-react-sdk
repository: ${{ inputs.react-sdk-repository || github.repository }}
# Enable rust crypto if the calling workflow requests it
- name: Enable rust crypto
if: inputs.rust-crypto
run: |
echo "CYPRESS_RUST_CRYPTO=1" >> "$GITHUB_ENV"
- name: Run Cypress tests - name: Run Cypress tests
uses: cypress-io/github-action@40a1a26c08d0e549e8516612ecebbd1ab5eeec8f uses: cypress-io/github-action@40a1a26c08d0e549e8516612ecebbd1ab5eeec8f

View file

@ -12,6 +12,20 @@ on:
branches: [develop, master] branches: [develop, master]
repository_dispatch: repository_dispatch:
types: [upstream-sdk-notify] types: [upstream-sdk-notify]
# support triggering from other workflows
workflow_call:
inputs:
react-sdk-repository:
type: string
required: true
description: "The name of the github repository to check out and build."
matrix-js-sdk-sha:
type: string
required: false
description: "The Git SHA of matrix-js-sdk to build against. By default, will use a matching branch name if it exists, or develop."
concurrency: concurrency:
group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }} group: ${{ github.workflow }}-${{ github.ref }}-${{ github.event_name }}
cancel-in-progress: true cancel-in-progress: true
@ -25,7 +39,10 @@ jobs:
name: "Build Element-Web" name: "Build Element-Web"
runs-on: ubuntu-latest runs-on: ubuntu-latest
steps: steps:
- uses: actions/checkout@v3 - name: Checkout code
uses: actions/checkout@v3
with:
repository: ${{ inputs.react-sdk-repository || github.repository }}
- uses: actions/setup-node@v3 - uses: actions/setup-node@v3
with: with:
@ -33,6 +50,9 @@ jobs:
- name: Fetch layered build - name: Fetch layered build
id: layered_build id: layered_build
env:
# tell layered.sh to check out the right sha of the JS-SDK, if we were given one
JS_SDK_GITHUB_BASE_REF: ${{ inputs.matrix-js-sdk-sha }}
run: | run: |
scripts/ci/layered.sh scripts/ci/layered.sh
JSSDK_SHA=$(git -C matrix-js-sdk rev-parse --short=12 HEAD) JSSDK_SHA=$(git -C matrix-js-sdk rev-parse --short=12 HEAD)
@ -44,7 +64,6 @@ jobs:
run: cp element.io/develop/config.json config.json run: cp element.io/develop/config.json config.json
working-directory: ./element-web working-directory: ./element-web
# After building we write the version file and the react-sdk sha so our cypress tests are from the same sha
- name: Build - name: Build
env: env:
CI_PACKAGE: true CI_PACKAGE: true
@ -52,9 +71,13 @@ jobs:
run: | run: |
yarn build yarn build
echo $VERSION > webapp/version echo $VERSION > webapp/version
echo $GITHUB_SHA > webapp/sha
working-directory: ./element-web working-directory: ./element-web
# Record the react-sdk sha so our cypress tests are from the same sha
- name: Record react-sdk SHA
run: |
git rev-parse HEAD > element-web/webapp/sha
- name: Upload Artifact - name: Upload Artifact
uses: actions/upload-artifact@v3 uses: actions/upload-artifact@v3
with: with: