From 713b37b54553503527386efdd8df1efffca66ae9 Mon Sep 17 00:00:00 2001 From: "api-clients-generation-pipeline[bot]" <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Date: Thu, 3 Jun 2021 14:33:16 +0200 Subject: [PATCH] Get integration test status check from client repos (#973) * Add step to get token * Send status checks back to spec PR * Remove comments, details * Regenerate client from commit 379360f of spec repo Co-authored-by: Hippolyte HENRY Co-authored-by: api-clients-generation-pipeline[bot] <54105614+api-clients-generation-pipeline[bot]@users.noreply.github.com> Co-authored-by: ci.datadog-api-spec --- .apigentools-info | 8 ++--- .github/workflows/scripts/test_integration.js | 24 +++++++++++++ .github/workflows/test_integration.yml | 36 +++++++++++++++++-- 3 files changed, 62 insertions(+), 6 deletions(-) create mode 100644 .github/workflows/scripts/test_integration.js diff --git a/.apigentools-info b/.apigentools-info index 9f1df561c84..f7f0fa9d666 100644 --- a/.apigentools-info +++ b/.apigentools-info @@ -4,13 +4,13 @@ "spec_versions": { "v1": { "apigentools_version": "1.4.1.dev8", - "regenerated": "2021-06-03 07:59:24.677012", - "spec_repo_commit": "6c05087" + "regenerated": "2021-06-03 12:21:12.869496", + "spec_repo_commit": "379360f" }, "v2": { "apigentools_version": "1.4.1.dev8", - "regenerated": "2021-06-03 07:59:57.715981", - "spec_repo_commit": "6c05087" + "regenerated": "2021-06-03 12:21:46.073810", + "spec_repo_commit": "379360f" } } } \ No newline at end of file diff --git a/.github/workflows/scripts/test_integration.js b/.github/workflows/scripts/test_integration.js new file mode 100644 index 00000000000..8b6542bb4d3 --- /dev/null +++ b/.github/workflows/scripts/test_integration.js @@ -0,0 +1,24 @@ +const SPEC_REPO = "datadog-api-spec" + +module.exports.post_status_check = async (github, context, status) => { + const pr_num = context.payload.pull_request.head.ref.split("/")[2] + const {data: pr} = await github.pulls.get({ + owner: context.repo.owner, + repo: SPEC_REPO, + pull_number: pr_num, + }); + const { data: jobs } = await github.actions.listJobsForWorkflowRun({ + owner: context.repo.owner, + repo: context.repo.repo, + run_id: context.runId + }); + await github.repos.createCommitStatus({ + owner: context.repo.owner, + repo: SPEC_REPO, + sha: pr.head.sha, + state: status, + target_url: `https://github.com/${context.repo.owner}/${context.repo.repo}/pull/${context.payload.pull_request.number}/checks?check_run_id=${jobs.jobs[0].id}`, + description: `${context.repo.repo} integration tests`, + context: `${context.repo.repo}_integration_tests` + }); +} diff --git a/.github/workflows/test_integration.yml b/.github/workflows/test_integration.yml index 4012299304b..ade1795dc7d 100644 --- a/.github/workflows/test_integration.yml +++ b/.github/workflows/test_integration.yml @@ -32,12 +32,28 @@ jobs: DD_HOSTNAME: "none" DD_INSIDE_CI: "true" steps: + - name: Get GitHub App token + if: github.event_name == 'pull_request' + id: get_token + uses: tibdex/github-app-token@v1.3.0 + with: + app_id: ${{ secrets.PIPELINE_GITHUB_APP_ID }} + private_key: ${{ secrets.PIPELINE_GITHUB_APP_PRIVATE_KEY }} + repository: DataDog/datadog-api-spec + - name: Checkout code + uses: actions/checkout@v2 + - name: Post pending status check + if: github.event_name == 'pull_request' + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "pending") - name: Install Go uses: actions/setup-go@v2 with: go-version: 1.16.x - - name: Checkout code - uses: actions/checkout@v2 - name: Run integration tests shell: bash run: ./run-tests.sh @@ -50,3 +66,19 @@ jobs: DD_TEST_CLIENT_API_KEY: ${{ secrets.DD_CLIENT_API_KEY }} DD_TEST_CLIENT_APP_KEY: ${{ secrets.DD_CLIENT_APP_KEY }} RECORD: "none" + - name: Post failure status check + if: failure() && github.event_name == 'pull_request' + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('./.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "failure") + - name: Post success status check + if: "!failure() && github.event_name == 'pull_request'" + uses: actions/github-script@v4.0.2 + with: + github-token: ${{ steps.get_token.outputs.token }} + script: | + const script = require('./.github/workflows/scripts/test_integration.js') + await script.post_status_check(github, context, "success")