ci: testing #9
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Trigger Buildkite update screenshots build | |
| on: | |
| issue_comment: | |
| types: [created] | |
| permissions: | |
| issues: write | |
| pull-requests: write | |
| contents: read | |
| jobs: | |
| check-and-trigger: | |
| if: | | |
| github.event.issue.pull_request && | |
| ( | |
| contains(github.event.comment.body, 'buildkite update screenshots') || | |
| contains(github.event.comment.body, 'buildkite update vrt') | |
| ) | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Dump github.event | |
| run: echo '${{ toJSON(github.event) }}' | jq | |
| - name: Debug environment before Buildkite trigger | |
| run: | | |
| echo "Current working directory: $(pwd)" | |
| echo "" | |
| echo "Key variables:" | |
| echo " GITHUB_SHA = ${GITHUB_SHA:-not-set}" | |
| echo " COMMIT_SHA = ${COMMIT_SHA:-not-set}" | |
| echo " BRANCH = ${BRANCH:-not-set}" | |
| echo " PR_NUMBER = ${PR_NUMBER:-not-set}" | |
| echo " TRIGGERED_BY = ${TRIGGERED_BY:-not-set}" | |
| echo " UPDATE_MODE = ${UPDATE_MODE:-not-set}" | |
| echo "" | |
| echo "Full env dump (sorted):" | |
| echo "────────────────────────────────────────" | |
| env | sort | |
| echo "────────────────────────────────────────" | |
| - name: Check elastic org membership | |
| id: check-membership | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.ADMIN_TOKEN_GH }} | |
| script: | | |
| const org = 'elastic'; | |
| const username = '${{ github.event.comment.user.login }}'; | |
| try { | |
| await github.request('GET /orgs/{org}/members/{username}', { | |
| org, | |
| username, | |
| headers: { Accept: 'application/vnd.github.v3+json' } | |
| }); | |
| core.setOutput('is_member', 'true'); | |
| core.info(`${username} is a member of ${org}`); | |
| } catch (err) { | |
| if (err.status === 404) { | |
| core.setOutput('is_member', 'false'); | |
| core.info(`${username} is NOT a member of ${org}`); | |
| } else { | |
| core.setFailed(`Failed to check membership: ${err}`); | |
| } | |
| } | |
| - name: Add 👍 reaction to comment | |
| if: steps.check-membership.outputs.is_member == 'true' | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| comment-id: ${{ github.event.comment.id }} | |
| reaction-type: +1 | |
| - name: Trigger Buildkite pipeline | |
| if: steps.check-membership.outputs.is_member == 'true' | |
| env: | |
| BUILDKITE_API_TOKEN: ${{ secrets.BUILDKITE_API_TOKEN }} | |
| PR_NUMBER: ${{ github.event.issue.number }} | |
| COMMIT_SHA: ${{ github.event.issue.pull_request.head.sha }} | |
| BRANCH: ${{ github.event.issue.pull_request.head.ref }} | |
| TRIGGERED_BY: ${{ github.event.comment.user.login }} | |
| run: | | |
| curl -s -X POST "https://api.buildkite.com/v2/organizations/elastic/pipelines/kibana-elastic-charts-build/builds" \ | |
| -H "Authorization: Bearer $BUILDKITE_API_TOKEN" \ | |
| -H "Content-Type: application/json" \ | |
| -d '{ | |
| "commit": "'"$COMMIT_SHA"'", | |
| "branch": "'"$BRANCH"'", | |
| "message": "Update screenshots from PR #'${PR_NUMBER}' (triggered by @'"${TRIGGERED_BY}"')", | |
| "author": { | |
| "name": "'"$TRIGGERED_BY"'", | |
| "email": "'"$TRIGGERED_BY"'@users.noreply.github.com" | |
| }, | |
| "env": { | |
| "ECH_STEP_PLAYWRIGHT_UPDATE_SCREENSHOTS": "true" | |
| }, | |
| "meta_data": { | |
| "github_pr_number": "'"$PR_NUMBER"'", | |
| "triggered_via": "github-comment", | |
| "triggered_by": "'"$TRIGGERED_BY"'" | |
| } | |
| }' | jq . | |
| - name: Add 😕 reaction to comment | |
| if: steps.check-membership.outputs.is_member == 'false' | |
| uses: peter-evans/create-or-update-comment@v4 | |
| with: | |
| comment-id: ${{ github.event.comment.id }} | |
| reaction-type: confused | |
| - name: Fail if not Elastic org member | |
| if: steps.check-membership.outputs.is_member == 'false' | |
| run: | | |
| echo "User ${{ github.event.comment.user.login }} is not a member of elastic organization" | |
| echo "Aborting Buildkite trigger" |