From 1b56a9ccd8e9d42d76b3b33e5f28f01a41d5b239 Mon Sep 17 00:00:00 2001 From: Bruno Date: Thu, 13 Jul 2023 18:02:35 -0300 Subject: [PATCH] ci: add ephemeral instances action (#71604) * ci: add ephemeral instances action * add operator experience squad to CODEOWNERS * only run action steps for a specific user --- .github/CODEOWNERS | 1 + .github/workflows/ephemeral-instances.yml | 81 +++++++++++++++++++++++ 2 files changed, 82 insertions(+) create mode 100644 .github/workflows/ephemeral-instances.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 709097af7a4..b24e352f1da 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -629,6 +629,7 @@ embed.go @grafana/grafana-as-code /.github/workflows/publish-kinds-release.yml @grafana/grafana-as-code /.github/workflows/verify-kinds.yml @grafana/grafana-as-code /.github/workflows/dashboards-issue-add-label.yml @grafana/dashboards-squad +/.github/workflows/ephemeral-instances.yml @grafana/grafana-operator-experience-squad # Generated files not requiring owner approval diff --git a/.github/workflows/ephemeral-instances.yml b/.github/workflows/ephemeral-instances.yml new file mode 100644 index 00000000000..2e2dcb04775 --- /dev/null +++ b/.github/workflows/ephemeral-instances.yml @@ -0,0 +1,81 @@ +name: 'Ephemeral instances action' +on: + issue_comment: + types: [created] + pull_request: + types: [opened, reopened, closed] +jobs: + handle-pull-request-event: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Get pull request repo + if: github.triggering_actor == 'PoorlyDefinedBehaviour' + uses: actions/github-script@v6 + id: get-pull-request-repo + with: + result-encoding: string + script: | + if(context.payload.pull_request?.head.ref) { + return context.payload.pull_request.head.ref + } + + const response = await github.rest.pulls.get({ + owner: "grafana", + repo: "grafana", + pull_number: context.payload.issue.number, + }); + + return response.data.head.ref + + - name: Checkout Grafana + if: github.triggering_actor == 'PoorlyDefinedBehaviour' + uses: actions/checkout@v3 + with: + repository: grafana/grafana + ref: ${{ steps.get-pull-request-repo.outputs.result }} + path: grafana + + - name: Setup Go + if: github.triggering_actor == 'PoorlyDefinedBehaviour' + uses: actions/setup-go@v4 + with: + go-version: '>=1.20' + + - name: Generate a GitHub app installation token + if: github.triggering_actor == 'PoorlyDefinedBehaviour' + id: generate_token + uses: tibdex/github-app-token@b62528385c34dbc9f38e5f4225ac829252d1ea92 + with: + app_id: ${{ secrets.EI_APP_ID }} + private_key: ${{ secrets.EI_APP_PRIVATE_KEY }} + + - name: Checkout ephemeral instances repository + uses: actions/checkout@v3 + with: + repository: grafana/ephemeral-grafana-instances-github-action + token: ${{ steps.generate_token.outputs.token }} + ref: main + path: ephemeral + + - name: Run action + if: github.triggering_actor == 'PoorlyDefinedBehaviour' + env: + GITHUB_EVENT: ${{ toJson(github.event)}} + run: | + GRAFANA_VERSION=10.1.0 + + cd $GITHUB_WORKSPACE/ephemeral/src + go run . \ + -GITHUB_TOKEN="${{ steps.generate_token.outputs.token }}" \ + -GITHUB_EVENT="$GITHUB_EVENT" \ + -GITHUB_TRIGGERING_ACTOR="${{ github.triggering_actor }}" \ + -GCOM_HOST="${{ secrets.EI_GCOM_HOST }}" \ + -GCOM_TOKEN="${{ secrets.EI_GCOM_TOKEN }}" \ + -HOSTED_GRAFANA_IMAGE_TAG="$GRAFANA_VERSION-ephemeral-grafana-${{ github.triggering_actor }}-${{ github.run_number }}-${{ github.run_attempt }}" \ + -REGISTRY="${{ secrets.EI_EPHEMERAL_INSTANCES_REGISTRY }}" \ + -GRAFANA_DIR="$GITHUB_WORKSPACE/grafana" \ + -ENTERPRISE_REF="main" \ + -GRAFANA_VERSION="$GRAFANA_VERSION" \ + -GCP_SERVICE_ACCOUNT_KEY_BASE64="${{ secrets.EI_GCP_SERVICE_ACCOUNT_KEY_BASE64 }}" \ + -EPHEMERAL_ORG_ID="${{ secrets.EI_EPHEMERAL_ORG_ID }}" || true \ No newline at end of file