Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[CI] allow for manual triggered jobs to accept inputs #58

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
163 changes: 159 additions & 4 deletions .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,104 @@ on:
branches: [ '**' ]
paths-ignore:
- '**/*.md'
workflow_dispatch:
inputs:
test_repo:
description: 'Test repo'
default: 'opensearch-project/opensearch-dashboards-functional-test'
required: true
type: string
test_branch:
description: 'Test branch (default: source branch)'
required: false
type: string
pr_number:
description: 'PR Number'
required: false
type: number
specs:
description: 'Additional tests to run'
required: false
type: string

env:
SOURCE_REPO: ${{ github.repository }}
SOURCE_BRANCH: ${{ github.base_ref }}
TEST_REPO: ${{ inputs.test_repo != '' && inputs.test_repo || 'opensearch-project/opensearch-dashboards-functional-test' }}
TEST_BRANCH: ${{ inputs.test_branch != '' && inputs.test_branch || github.base_ref }}
FTR_PATH: 'ftr'
START_CMD: 'node ../scripts/opensearch_dashboards --dev --no-base-path --no-watch'
OPENSEARCH_SNAPSHOT_CMD: 'node ../scripts/opensearch snapshot'
SPEC: 'cypress/integration/core-opensearch-dashboards/opensearch-dashboards/**/*.js,'
ADDITIONAL_SPEC: "${{ inputs.specs != '' && inputs.specs || '' }}"
CYPRESS_BROWSER: 'chromium'
CYPRESS_VISBUILDER_ENABLED: true
CYPRESS_DATASOURCE_MANAGEMENT_ENABLED: false
OSD_SNAPSHOT_SKIP_VERIFY_CHECKSUM: true
COMMENT_TAG: '[MANUAL CYPRESS TEST RUN RESULTS]'
COMMENT_SUCCESS_MSG: ':white_check_mark: Cypress test run succeeded.'
COMMENT_FAILURE_MSG: ':x: Cypress test run failed.'

jobs:
test-add-comment:
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Get source information from PR number
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
id: get_pr_info
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: "${{ inputs.pr_number }}"
});

const sourceRepo = pr.head.repo.full_name;
const sourceBranch = pr.head.ref;
const sourceJSON = `{ 'source': { 'repo': '${sourceRepo}', 'branch': '${sourceBranch}' } }`;
return sourceJSON;

- name: Set source branch from PR number
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
run: |
echo "SOURCE_REPO=${{ fromJSON(steps.get_pr_info.outputs.result.source.repo) }}" >> $GITHUB_ENV
echo "SOURCE_BRANCH=${{ fromJSON(steps.get_pr_info.outputs.result.source.branch) }}" >> $GITHUB_ENV

- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ inputs.pr_number }}
comment-author: 'github-actions[bot]'
body-includes: "${{ env.COMMENT_TAG }}"

- name: Add comment on the PR
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ inputs.pr_number }}
body: |
### ${{ env.COMMENT_TAG }}

#### ${{ env.CYPRESS_VISBUILDER_ENABLED && env.COMMENT_SUCCESS_MSG || env.COMMENT_FAILURE_MSG }}

#### Inputs:
Source repo: `${{ env.SOURCE_REPO }}`
Source branch: `${{ env.SOURCE_BRANCH }}`
Test repo: `${{ env.TEST_REPO }}`
Test branch: `${{ env.TEST_BRANCH }}`
Spec: `${{ env.SPEC }}${{ env.ADDITIONAL_SPEC }}`

Link to results:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace

cypress-tests:
runs-on: ubuntu-latest
container:
Expand All @@ -30,8 +116,42 @@ jobs:
TERM: xterm
name: Run cypress tests
steps:
- name: Get source information from PR number
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
id: get_pr_info
uses: actions/github-script@v6
with:
result-encoding: string
script: |
const { data: pr } = await github.rest.pulls.get({
owner: context.repo.owner,
repo: context.repo.repo,
pull_number: "${{ inputs.pr_number }}"
});

const sourceRepo = pr.head.repo.full_name;
const sourceBranch = pr.head.ref;
const sourceJSON = `{ 'source': { 'repo': '${sourceRepo}', 'branch': '${sourceBranch}' } }`;
return sourceJSON;

- name: Set source branch from PR number
if: ${{ github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
run: |
echo "SOURCE_REPO=${{ fromJSON(steps.get_pr_info.outputs.result.source.repo) }}" >> $GITHUB_ENV
echo "SOURCE_BRANCH=${{ fromJSON(steps.get_pr_info.outputs.result.source.branch) }}" >> $GITHUB_ENV

- run: |
echo "Source repo: ${{ env.SOURCE_REPO }}"
echo "Source branch: ${{ env.SOURCE_BRANCH }}"
echo "Test repo: ${{ env.TEST_REPO }}"
echo "Test branch: ${{ env.TEST_BRANCH }}"
echo "Extra spec: ${{ env.ADDITIONAL_SPEC }}"

- name: Checkout code
uses: actions/checkout@v2
with:
repository: ${{ env.SOURCE_REPO }}
ref: '${{ env.SOURCE_BRANCH }}'

- name: Setup Node
uses: actions/setup-node@v2
Expand All @@ -54,8 +174,8 @@ jobs:
uses: actions/checkout@v2
with:
path: ${{ env.FTR_PATH }}
repository: opensearch-project/opensearch-dashboards-functional-test
ref: '${{ github.base_ref }}'
repository: ${{ env.TEST_REPO }}
ref: '${{ env.TEST_BRANCH }}'

- name: Get Cypress version
id: cypress_version
Expand All @@ -79,7 +199,7 @@ jobs:
working-directory: ${{ env.FTR_PATH }}
start: ${{ env.OPENSEARCH_SNAPSHOT_CMD }}, ${{ env.START_CMD }}
wait-on: 'http://localhost:9200, http://localhost:5601'
command: yarn cypress:run-without-security --browser ${{ env.CYPRESS_BROWSER }} --spec ${{ env.SPEC }}
command: yarn cypress:run-without-security --browser ${{ env.CYPRESS_BROWSER }} --spec ${{ env.SPEC }}${{ env.ADDITIONAL_SPEC }}

# Screenshots are only captured on failure, will change this once we do visual regression tests
- uses: actions/upload-artifact@v3
Expand All @@ -101,4 +221,39 @@ jobs:
with:
name: ftr-cypress-results
path: ${{ env.FTR_PATH }}/cypress/results
retention-days: 1
retention-days: 1

add-comment:
needs: [cypress-tests]
if: ${{ always() && github.event_name == 'workflow_dispatch' && inputs.pr_number != '' }}
permissions:
pull-requests: write
runs-on: ubuntu-latest
steps:
- name: Find Comment
uses: peter-evans/find-comment@v2
id: fc
with:
issue-number: ${{ inputs.pr_number }}
comment-author: 'github-actions[bot]'
body-includes: "${{ env.COMMENT_TAG }}"

- name: Add comment on the PR
uses: peter-evans/create-or-update-comment@v3
with:
comment-id: ${{ steps.fc.outputs.comment-id }}
issue-number: ${{ inputs.pr_number }}
body: |
### ${{ env.COMMENT_TAG }}

#### ${{ needs.cypress-tests.result == 'success' && env.COMMENT_SUCCESS_MSG || env.COMMENT_FAILURE_MSG }}

#### Inputs:
Source repo: `${{ env.SOURCE_REPO }}`
Source branch: `${{ env.SOURCE_BRANCH }}`
Test repo: `${{ env.TEST_REPO }}`
Test branch: `${{ env.TEST_BRANCH }}`

Link to results:
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
edit-mode: replace
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ trash
target
/build
/bwc_tmp
/scripts/random/data
/scripts/random/stdout.txt
/scripts/random/data.tar.gz
/scripts/random.tar.gz
.jruby
.idea
*.iml
Expand Down
Loading