From 80339ab8ba2e1c4f69f36bc9dd074f3a82ef8b8b Mon Sep 17 00:00:00 2001 From: Trevor Whitney Date: Tue, 15 Oct 2024 14:43:44 -0600 Subject: [PATCH] ci: add logql-analyzer CI --- .github/workflows/logql-analyzer.yml | 102 +++++++++++++++++++++++++++ 1 file changed, 102 insertions(+) create mode 100644 .github/workflows/logql-analyzer.yml diff --git a/.github/workflows/logql-analyzer.yml b/.github/workflows/logql-analyzer.yml new file mode 100644 index 0000000000000..f3618ce5eba0d --- /dev/null +++ b/.github/workflows/logql-analyzer.yml @@ -0,0 +1,102 @@ +name: LogQL Analyzer + +on: + pull_request: + branches: + - logql-analyzer-ci + release: + types: + - released + +permissions: + contents: read + id-token: write + +jobs: + analyze: + runs-on: ubuntu-latest + + env: + BUILD_TIMEOUT: 60 + IMAGE_PREFIX: "grafana" + RELEASE_VERSION: "${{ github.event.release.tag_name || 'test' }}" + steps: + - uses: actions/checkout@v4 + with: + fetch-tags: true + + - id: "get-github-app-token" + name: "get github app token" + uses: "actions/create-github-app-token@v1" + with: + app-id: "${{ secrets.APP_ID }}" + owner: "${{ github.repository_owner }}" + private-key: "${{ secrets.APP_PRIVATE_KEY }}" + + - name: "Set up QEMU" + uses: "docker/setup-qemu-action@v3" + - name: "set up docker buildx" + uses: "docker/setup-buildx-action@v3" + - name: "Login to DockerHub (from vault)" + uses: "grafana/shared-workflows/actions/dockerhub-login@main" + + - name: "Build and push" + timeout-minutes: "${{ fromJSON(env.BUILD_TIMEOUT) }}" + uses: "docker/build-push-action@v6" + with: + build-args: "IMAGE_TAG=${RELEASE_VERSION}" + file: "cmd/logql-analyzer/Dockerfile" + platforms: "linux/amd64,linux/arm64,linux/arm" + push: true + tags: "${{ env.IMAGE_PREFIX }}/logql-analyzer:${RELEASE_VERSION}" + + - name: Log in to Google Artifact Registry + uses: grafana/shared-workflows/actions/login-to-gar@main + with: + environment: "prod" + + - name: Run shell command + run: | + echo $("${WORKSPACE_ROOT}/loki/tools/image-tag") > .tag + export RELEASE_TAG=$(cat .tag) + # if the tag matches the pattern `D.D.D` then RELEASE_NAME="D-D-x", otherwise RELEASE_NAME="next" + export RELEASE_NAME=$([[ $RELEASE_TAG =~ $RELEASE_TAG_REGEXP ]] && echo $RELEASE_TAG | grep -oE $MAJOR_MINOR_VERSION_REGEXP | sed "s/\\./-/g" | sed "s/$/-x/" || echo "next") + echo $RELEASE_NAME + echo $PLUGIN_CONFIG_TEMPLATE > updater-config.yaml + # replace placeholders with RELEASE_NAME and RELEASE TAG + sed -i "s/\\"{{release}}\\"/\\"$RELEASE_NAME\\"/g" %s % configFileName + sed -i "s/{{version}}/$RELEASE_TAG/g" %s % configFileName + + - name: Update to latest image + env: + GITHUB_TOKEN: ${{ steps.get-github-app-token.outputs.token }} + run: | + set -e -o pipefail + + cat << EOF > config.json + { + "repo_name": "deployment_tools", + "destination_branch": "master", + "git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com", + "git_author_name": "version_bumper[bot]", + "git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com", + "git_committer_name": "version_bumper[bot]", + "pull_request_branch_prefix": "logql-analyzer/updater", + "pull_request_enabled": true, + "pull_request_existing_strategy": "replace", + "pull_request_title_prefix": "[logql-analyzer updater] ", + "pull_request_message": "Add logql-analyzer version to ${RELEASE_VERSION} to supported versions", + "update_jsonnet_attribute_configs": [ + { + "file_path": "ksonnet/environments/logql-analyzer/supported-versions.libsonnet", + "jsonnet_key": "${RELEASE_NAME}", + "jsonnet_value": "grafana/logql-analyzer:${RELEASE_VERSION}-amd64", + "upsert": true + } + ] + } + EOF + + docker run --rm \ + -e GITHUB_TOKEN="$GITHUB_TOKEN" \ + -e CONFIG_JSON="$(cat config.json)" us-docker.pkg.dev/grafanalabs-global/docker-deployment-tools-prod/updater |& tee updater-output.log