From 10510d5138a8033dcbf3f5bb3a639a6e153f5a9e Mon Sep 17 00:00:00 2001 From: Bruno Date: Mon, 17 Jul 2023 16:08:53 -0300 Subject: [PATCH] ci: split ephemeral instances action and run only the grafana build workflow in a larger runner (#71785) --- .github/CODEOWNERS | 3 +- ...yml => ephemeral-instances-pr-comment.yml} | 10 ++-- .../ephemeral-instances-pr-opened-closed.yml | 47 +++++++++++++++++++ 3 files changed, 54 insertions(+), 6 deletions(-) rename .github/workflows/{ephemeral-instances.yml => ephemeral-instances-pr-comment.yml} (87%) create mode 100644 .github/workflows/ephemeral-instances-pr-opened-closed.yml diff --git a/.github/CODEOWNERS b/.github/CODEOWNERS index 69551b1c75c..fddfe32e3c3 100644 --- a/.github/CODEOWNERS +++ b/.github/CODEOWNERS @@ -633,7 +633,8 @@ 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 +/.github/workflows/ephemeral-instances-pr-comment.yml @grafana/grafana-operator-experience-squad +/.github/workflows/ephemeral-instances-pr-opened-closed.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-pr-comment.yml similarity index 87% rename from .github/workflows/ephemeral-instances.yml rename to .github/workflows/ephemeral-instances-pr-comment.yml index 69645529881..d7b7952b35b 100644 --- a/.github/workflows/ephemeral-instances.yml +++ b/.github/workflows/ephemeral-instances-pr-comment.yml @@ -1,12 +1,12 @@ -name: 'Ephemeral instances action' +name: 'Ephemeral instances: PR comment' on: issue_comment: types: [created] - pull_request: - types: [opened, reopened, closed] jobs: handle-pull-request-event: - if: github.event.sender.type == 'User' + if: github.event.sender.type == 'User' && + github.event.issue.pull_request && + startsWith(github.event.comment.body, '/deploy-to-hg') runs-on: labels: ubuntu-latest-8-cores continue-on-error: true @@ -44,7 +44,7 @@ jobs: -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 }}" \ + -HOSTED_GRAFANA_IMAGE_TAG="$GRAFANA_VERSION-ephemeral-${{ github.triggering_actor }}-$(uuidgen)" \ -REGISTRY="${{ secrets.EI_EPHEMERAL_INSTANCES_REGISTRY }}" \ -GRAFANA_VERSION="$GRAFANA_VERSION" \ -GCP_SERVICE_ACCOUNT_KEY_BASE64="${{ secrets.EI_GCP_SERVICE_ACCOUNT_KEY_BASE64 }}" \ diff --git a/.github/workflows/ephemeral-instances-pr-opened-closed.yml b/.github/workflows/ephemeral-instances-pr-opened-closed.yml new file mode 100644 index 00000000000..595cc43c953 --- /dev/null +++ b/.github/workflows/ephemeral-instances-pr-opened-closed.yml @@ -0,0 +1,47 @@ +name: 'Ephemeral instances: PR opened/closed' +on: + pull_request: + types: [opened, reopened, closed] +jobs: + handle-pull-request-event: + runs-on: ubuntu-latest + continue-on-error: true + steps: + - name: Setup Go + uses: actions/setup-go@v4 + with: + go-version: '>=1.20' + + - name: Generate a GitHub app installation token + 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 + 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-${{ github.triggering_actor }}-$(uuidgen)" \ + -REGISTRY="${{ secrets.EI_EPHEMERAL_INSTANCES_REGISTRY }}" \ + -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