From c2334228f48454947d03c8eed5ec73affa461921 Mon Sep 17 00:00:00 2001 From: Hector Castejon Diaz Date: Fri, 19 Jul 2024 11:23:03 +0200 Subject: [PATCH] test --- .github/workflows/integration-pr.yml | 43 +++++++++++++++++++ .github/workflows/integration-tests.yml | 33 ++++++--------- .github/workflows/test-check.yml | 55 ------------------------- 3 files changed, 55 insertions(+), 76 deletions(-) create mode 100644 .github/workflows/integration-pr.yml delete mode 100644 .github/workflows/test-check.yml diff --git a/.github/workflows/integration-pr.yml b/.github/workflows/integration-pr.yml new file mode 100644 index 00000000..79b1b4eb --- /dev/null +++ b/.github/workflows/integration-pr.yml @@ -0,0 +1,43 @@ +name: Integration Tests Check + +on: + pull_request: + branches: [ "main" ] + +jobs: + start-check: + runs-on: ubuntu-latest + permissions: + checks: write # Permission to create a Check Run + actions: write # Permission to run another workflow + steps: + - name: Create Check + id: checkrun + env: + GH_TOKEN: ${{ github.token }} # Expose the token for GH CLI + run: | + + CHECKID=$(gh api -X POST -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -f name='Integration Tests' \ + -f head_sha='${{ github.event.pull_request.head.sha }}' \ + -f status='queued' \ + -f 'output[title]=Run Integration Tests' \ + -f 'output[summary]=Running Integration Tests for Java SDK' \ + --jq '.id' \ + /repos/${{ github.repository }}/check-runs) + + # Put the ID into a step variable + echo "checkId=$CHECKID" >> $GITHUB_OUTPUT + + - name: Trigger Workflow + env: + GH_TOKEN: ${{ github.token }} + run: | + # By default, this will run the workflow in the main branch. + # To test changes the ref to the current branch. + gh api -X POST -H "Accept: application/vnd.github+json" \ + -H "X-GitHub-Api-Version: 2022-11-28" \ + -f 'inputs[checkRunId]=${{ steps.checkrun.outputs.checkId }}' \ + -f "ref=run-tests" \ + /repos/${{ github.repository }}/actions/workflows/integration-tests.yml/dispatches \ No newline at end of file diff --git a/.github/workflows/integration-tests.yml b/.github/workflows/integration-tests.yml index 1adf468f..a2575b70 100644 --- a/.github/workflows/integration-tests.yml +++ b/.github/workflows/integration-tests.yml @@ -1,15 +1,15 @@ name: Integration Tests on: - repository_dispatch: - types: [integration-check] + workflow_dispatch: + inputs: + checkRunId: + description: "ID for the Check Run in a PR" + type: string + jobs: myEvent: runs-on: ubuntu-latest steps: - #################################################### - # Update the status to show that the queued message - # was received and is being processed - #################################################### - name: Acknowledge Request env: GH_TOKEN: ${{ github.token }} @@ -17,9 +17,9 @@ jobs: gh api -X PATCH -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ -f 'status=in_progress' \ - -f 'output[title]=Integration Tests' \ - -f 'output[summary]=Running Integration Tests for Py SDK' \ - /repos/${{ github.repository }}/check-runs/${{ github.event.client_payload.checkRunId }} + -f 'output[title]=Run Integration Tests' \ + -f 'output[summary]=Running Integration Tests for Java SDK' \ + /repos/${{ github.repository }}/check-runs/${{ github.event.inputs.checkRunId }} #################################################### # Actually, we'll just sleep to simulate some work @@ -27,28 +27,19 @@ jobs: - name: Processing run: sleep 10 - ##################################################### - # Send a final message to complete the run and - # provide any final updates. Doing this one in JSON - # to make it more readable. This approach can also - # be used to get total control over the serialized - # data types (for example, integers). - ##################################################### - name: Complete Check env: GH_TOKEN: ${{ github.token }} run: | gh api -X PATCH -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ - /repos/${{ github.repository }}/check-runs/${{ github.event.client_payload.checkRunId }} \ + /repos/${{ github.repository }}/check-runs/${{ github.event.inputs.checkRunId }} \ --input - <<- EOF { "conclusion": "success", - "details_url": "TODO", "output": { - "title": "Integration Tests", - "summary": "**Summary**: The run completed.", - "text": "Everything worked as expected." + "title": "Run Integration Tests", + "summary": "Successful execution of Integration Tests for Java SDK" } } EOF \ No newline at end of file diff --git a/.github/workflows/test-check.yml b/.github/workflows/test-check.yml deleted file mode 100644 index c25cdec6..00000000 --- a/.github/workflows/test-check.yml +++ /dev/null @@ -1,55 +0,0 @@ -name: Integration Tests Validation - -# To trigger the check -on: - pull_request: - branches: [ "main" ] - -jobs: - start-check: - runs-on: ubuntu-latest - permissions: - checks: write # Permission to create a Check Run - contents: write # Permission to write a repository_dispatch requests - steps: - - name: Integration Tests Check - id: testcheck # An ID to allow the step to be referenced - env: - GH_TOKEN: ${{ github.token }} # Expose the token for GH CLI - run: | - ########################################################## - # Create a Check Run and indicate that it is being queued - # Use --jq to return the ID - ########################################################## - - CHECKID=$(gh api -X POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -f name='Integration Tests Check' \ - -f head_sha='${{ github.event.pull_request.head.sha }}' \ - -f status='queued' \ - -f 'output[title]=Integration Tests' \ - -f 'output[summary]=Pending Integration Tests for Py SDK' \ - --jq '.id' \ - /repos/${{ github.repository }}/check-runs) - - #################################################### - # Put the ID into a step variable - #################################################### - - echo "checkId=$CHECKID" >> $GITHUB_OUTPUT - - - name: Trigger Integration Tests - env: - GH_TOKEN: ${{ github.token }} - run: | - ########################################################## - # Create a repository_dispatch event of type my-check - # Send the SHA and the Check Run ID in the client_payload - ########################################################## - - gh api -X POST -H "Accept: application/vnd.github+json" \ - -H "X-GitHub-Api-Version: 2022-11-28" \ - -f 'event_type=integration-check' \ - -f 'client_payload[checkRunId]=${{ steps.testcheck.outputs.checkId }}' \ - -f 'client_payload[sha]=${{ github.sha }}' \ - /repos/${{ github.repository }}/dispatches \ No newline at end of file