Skip to content

Commit

Permalink
accept input and read pr
Browse files Browse the repository at this point in the history
Signed-off-by: Kawika Avilla <[email protected]>
  • Loading branch information
kavilla committed Sep 27, 2023
1 parent fa67faa commit 98079ab
Showing 1 changed file with 74 additions and 19 deletions.
93 changes: 74 additions & 19 deletions .github/workflows/cypress_workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,30 @@ on:
paths-ignore:
- '**/*.md'
workflow_dispatch:
inputs:
repository:
description: 'Repo of the tests'
inputs:
test_repo:
description: 'Test repo'
default: 'opensearch-project/opensearch-dashboards-functional-test'
required: true
type: string
branch:
description: 'Branch of the tests (default: target branch)'
default: ''
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'
default: ''
required: false
type: string
pr_number:
description: 'Pull request number to link results'
default: ''
required: false
type: number

env:
REPO: ${{ inputs.repository != '' && inputs.repository || 'opensearch-project/opensearch-dashboards-functional-test' }}
TEST_BRANCH: ${{ inputs.branch != '' && inputs.branch || github.base_ref }}
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'
Expand All @@ -52,6 +51,30 @@ jobs:
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
Expand All @@ -71,7 +94,9 @@ jobs:
#### ${{ env.CYPRESS_VISBUILDER_ENABLED && env.COMMENT_SUCCESS_MSG || env.COMMENT_FAILURE_MSG }}
#### Inputs:
Test repo: `${{ env.REPO }}`
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 }}`
Expand All @@ -91,13 +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 "Repo: ${{ env.REPO }}"
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 @@ -120,7 +174,7 @@ jobs:
uses: actions/checkout@v2
with:
path: ${{ env.FTR_PATH }}
repository: ${{ env.REPO }}
repository: ${{ env.TEST_REPO }}
ref: '${{ env.TEST_BRANCH }}'

- name: Get Cypress version
Expand Down Expand Up @@ -195,9 +249,10 @@ jobs:
#### ${{ needs.cypress-tests.result == 'success' && env.COMMENT_SUCCESS_MSG || env.COMMENT_FAILURE_MSG }}
#### Inputs:
Test repo: `${{ env.REPO }}`
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 }}
Expand Down

0 comments on commit 98079ab

Please sign in to comment.