From f738ab3352b86de27116b42f1273d5a89425ffa7 Mon Sep 17 00:00:00 2001 From: Evgeny Slutsky Date: Wed, 14 Jun 2023 11:51:12 +0300 Subject: [PATCH] trigger the run-osp-extended-tests action on specific comment Signed-off-by: Evgeny Slutsky --- .github/workflows/create-new-pr.yml | 39 +++++++++++ .github/workflows/run-osp-extended-tests.yml | 73 ++++++++++++++++++-- 2 files changed, 108 insertions(+), 4 deletions(-) create mode 100644 .github/workflows/create-new-pr.yml diff --git a/.github/workflows/create-new-pr.yml b/.github/workflows/create-new-pr.yml new file mode 100644 index 000000000..3eb8dcf11 --- /dev/null +++ b/.github/workflows/create-new-pr.yml @@ -0,0 +1,39 @@ +name: new PR greeter +on: + pull_request_target: + types: [opened,reopened] + +jobs: + new_pr_greeter: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Checkout forklift + uses: actions/checkout@v3 + + - id: codeowner + uses: SvanBoxel/codeowners-action@v1 + with: + path: './.github/CODEOWNERS' + + - name: fail if the commenter doesnt exists in codeowners + id: allowedaccess + run: | + echo allowed=$(echo '${{ steps.codeowner.outputs.codeowners }}' | \ + jq -r '."tests/" | index("@${{ github.actor }}")') >> $GITHUB_OUTPUT + + - name: Add comment to PR + uses: actions/github-script@v6 + if: ${{ steps.allowedaccess.outputs.allowed == '1' }} + with: + script: | + + const body = `Welcome ${{ github.actor }}, you can run extended openstack test with **/test-osp-extended** comment`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) diff --git a/.github/workflows/run-osp-extended-tests.yml b/.github/workflows/run-osp-extended-tests.yml index 0980d3f51..8d9e0111f 100644 --- a/.github/workflows/run-osp-extended-tests.yml +++ b/.github/workflows/run-osp-extended-tests.yml @@ -4,7 +4,6 @@ on: name: description: 'run e2e openstack extended tests on Self hosted runner' workflow_call: - issue_comment: types: [ created ] @@ -16,18 +15,54 @@ concurrency: # A workflow run is made up of one or more jobs that can run sequentially jobs: create_ovirt_runner: + if: github.event.issue.pull_request && contains(github.event.comment.body, '/test-osp-extended') runs-on: ubuntu-latest steps: + - name: Get PR branch + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + - name: Set latest commit status as pending + if: always() + uses: myrotvorets/set-commit-status-action@master + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: pending + + - name: Checkout forklift + uses: actions/checkout@v3 + + - id: codeowner + uses: SvanBoxel/codeowners-action@v1 + with: + path: './.github/CODEOWNERS' + + - name: fail if the commenter doesnt exists in codeowners + run: | + [[ $(echo '${{ steps.codeowner.outputs.codeowners }}' | \ + jq -r '."tests/" | index("@${{ github.event.comment.user.login }}")') -eq 1 ]] + - name: prepare the secrets - uses: kubev2v/forkliftci/ci/prepare-ansible-secrets@v4.0 + #uses: kubev2v/forkliftci/ci/prepare-ansible-secrets@v4.0 + uses: eslutsky/forkliftci/ci/prepare-ansible-secrets@gh-runner-fail-early with: OKD_ENGINE_SECRETS: ${{ secrets.OKD_ENGINE_SECRETS }} OKD_SSH_KEY: ${{ secrets.OKD_SSH_KEY }} - name: provision self hosted runner - uses: kubev2v/forkliftci/ci/create-self-runner@v4.0 + #uses: kubev2v/forkliftci/ci/create-self-runner@v4.0 + uses: eslutsky/forkliftci/ci/create-self-runner@gh-runner-fail-early + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: ${{ failure() || cancelled() }} + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} ci_setup: + if: github.event.issue.pull_request && contains(github.event.comment.body, '/test-osp-extended') runs-on: self-hosted #runs-on: ubuntu-latest needs: create_ovirt_runner @@ -52,7 +87,7 @@ jobs: - name: build and setup everything #uses: kubev2v/forkliftci/ci/build-and-setup@v4.0 - uses: eslutsky/forkliftci/ci/build-and-setup@add-ssl-to-action + uses: eslutsky/forkliftci/ci/build-and-setup@gh-runner-fail-early with: provider_name: openstack gh_access_token: ${{ secrets.GITHUB_TOKEN }} @@ -73,6 +108,36 @@ jobs: with: source_provider: openstack + - name: Get PR branch + if: always() + uses: xt0rted/pull-request-comment-branch@v1 + id: comment-branch + + - name: Set latest commit status as ${{ job.status }} + uses: myrotvorets/set-commit-status-action@master + if: always() + with: + sha: ${{ steps.comment-branch.outputs.head_sha }} + token: ${{ secrets.GITHUB_TOKEN }} + status: ${{ job.status }} + + - name: Add comment to PR + uses: actions/github-script@v6 + if: always() + with: + script: | + const name = '${{ github.workflow }}'; + const url = '${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}'; + const success = '${{ job.status }}' === 'success'; + const body = `${name}: ${success ? 'succeeded ✅' : 'failed ❌'}\n${url}`; + + await github.rest.issues.createComment({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + body: body + }) + remove_ovirt_runner: runs-on: ubuntu-latest if: ${{ success() || failure() || cancelled() }}