|
| 1 | +name: LogQL Analyzer |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + release: |
| 6 | + types: |
| 7 | + - released |
| 8 | + |
| 9 | +permissions: |
| 10 | + contents: read |
| 11 | + id-token: write |
| 12 | + |
| 13 | +jobs: |
| 14 | + analyze: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + |
| 17 | + env: |
| 18 | + BUILD_TIMEOUT: 60 |
| 19 | + IMAGE_PREFIX: "grafana" |
| 20 | + RELEASE_VERSION: "${{ github.event.release.tag_name || 'test' }}" |
| 21 | + steps: |
| 22 | + - uses: actions/checkout@v4 |
| 23 | + with: |
| 24 | + fetch-tags: true |
| 25 | + path: loki |
| 26 | + |
| 27 | + - name: prepare |
| 28 | + id: prepare |
| 29 | + env: |
| 30 | + MAJOR_MINOR_VERSION_REGEXP: '([0-9]+\\.[0-9]+)' |
| 31 | + RELEASE_TAG_REGEXP: '^([0-9]+\\.[0-9]+\\.[0-9]+)$' |
| 32 | + working-directory: loki |
| 33 | + run: | |
| 34 | + echo "$(./tools/image-tag)" > .tag |
| 35 | + if [[ "$RELEASE_VERSION" == "test" ]]; then |
| 36 | + echo "RELEASE_VERSION is not set, using image tag" |
| 37 | + RELEASE_VERSION="$(cat .tag)" |
| 38 | + fi |
| 39 | + echo "RELEASE_VERSION: $RELEASE_VERSION" |
| 40 | +
|
| 41 | + # if the tag matches the pattern `D.D.D` then RELEASE_NAME="D-D-x", otherwise RELEASE_NAME="next" |
| 42 | + RELEASE_NAME=$([[ $RELEASE_VERSION =~ $RELEASE_TAG_REGEXP ]] && echo $RELEASE_TAG | grep -oE $MAJOR_MINOR_VERSION_REGEXP | sed "s/\\./-/g" | sed "s/$/-x/" || echo "next") |
| 43 | + echo "RELEASE_NAME: $RELEASE_NAME" |
| 44 | +
|
| 45 | + echo "release_version=${RELEASE_VERSION}" >> "$GITHUB_OUTPUT" |
| 46 | + echo "release_name=${RELEASE_NAME}" >> "$GITHUB_OUTPUT" |
| 47 | +
|
| 48 | + - id: "get-github-app-token" |
| 49 | + name: "get github app token" |
| 50 | + uses: "actions/create-github-app-token@v1" |
| 51 | + with: |
| 52 | + app-id: "${{ secrets.APP_ID }}" |
| 53 | + owner: "${{ github.repository_owner }}" |
| 54 | + private-key: "${{ secrets.APP_PRIVATE_KEY }}" |
| 55 | + |
| 56 | + - name: "Set up QEMU" |
| 57 | + uses: "docker/setup-qemu-action@v3" |
| 58 | + - name: "set up docker buildx" |
| 59 | + uses: "docker/setup-buildx-action@v3" |
| 60 | + - name: "Login to DockerHub (from vault)" |
| 61 | + uses: "grafana/shared-workflows/actions/dockerhub-login@main" |
| 62 | + |
| 63 | + - name: "Build and push" |
| 64 | + timeout-minutes: "${{ fromJSON(env.BUILD_TIMEOUT) }}" |
| 65 | + uses: "docker/build-push-action@v6" |
| 66 | + with: |
| 67 | + build-args: "IMAGE_TAG=${{ steps.prepare.outputs.release_version }}" |
| 68 | + context: loki |
| 69 | + file: "loki/cmd/logql-analyzer/Dockerfile" |
| 70 | + platforms: "linux/amd64" |
| 71 | + push: true |
| 72 | + tags: "grafana/logql-analyzer:${{ steps.prepare.outputs.release_version }}" |
| 73 | + |
| 74 | + - name: Log in to Google Artifact Registry |
| 75 | + uses: grafana/shared-workflows/actions/login-to-gar@main |
| 76 | + with: |
| 77 | + registry: "us-docker.pkg.dev" |
| 78 | + environment: "prod" |
| 79 | + |
| 80 | + - name: Update to latest image |
| 81 | + env: |
| 82 | + GITHUB_TOKEN: ${{ steps.get-github-app-token.outputs.token }} |
| 83 | + RELEASE_NAME: ${{ steps.prepare.outputs.release_name }} |
| 84 | + RELEASE_VERSION: ${{ steps.prepare.outputs.release_version }} |
| 85 | + run: | |
| 86 | + set -e -o pipefail |
| 87 | +
|
| 88 | + cat << EOF > config.json |
| 89 | + { |
| 90 | + "repo_name": "deployment_tools", |
| 91 | + "destination_branch": "master", |
| 92 | + "git_author_email": "119986603+updater-for-ci[bot]@users.noreply.github.com", |
| 93 | + "git_author_name": "version_bumper[bot]", |
| 94 | + "git_committer_email": "119986603+updater-for-ci[bot]@users.noreply.github.com", |
| 95 | + "git_committer_name": "version_bumper[bot]", |
| 96 | + "pull_request_branch_prefix": "logql-analyzer/updater", |
| 97 | + "pull_request_enabled": true, |
| 98 | + "pull_request_existing_strategy": "replace", |
| 99 | + "pull_request_title_prefix": "[logql-analyzer updater] ", |
| 100 | + "pull_request_message": "Add logql-analyzer version to ${RELEASE_VERSION} to supported versions", |
| 101 | + "update_jsonnet_attribute_configs": [ |
| 102 | + { |
| 103 | + "file_path": "ksonnet/environments/logql-analyzer/supported-versions.libsonnet", |
| 104 | + "jsonnet_key": "${RELEASE_NAME}", |
| 105 | + "jsonnet_value": "grafana/logql-analyzer:${RELEASE_VERSION}-amd64", |
| 106 | + "upsert": true |
| 107 | + } |
| 108 | + ] |
| 109 | + } |
| 110 | + EOF |
| 111 | +
|
| 112 | + docker run --rm \ |
| 113 | + -e GITHUB_TOKEN="$GITHUB_TOKEN" \ |
| 114 | + -e CONFIG_JSON="$(cat config.json)" us-docker.pkg.dev/grafanalabs-global/docker-deployment-tools-prod/updater |& tee updater-output.log |
0 commit comments