From 399cff85fa59dd42c56900dd3f24d1893d06dce7 Mon Sep 17 00:00:00 2001 From: Dmytro Bondar Date: Fri, 6 Sep 2024 11:22:48 +0200 Subject: [PATCH] Update workflow and Makefile --- .github/workflows/mixins.yaml | 29 +++++++++++++++++++++-------- Makefile | 14 ++++++++------ 2 files changed, 29 insertions(+), 14 deletions(-) diff --git a/.github/workflows/mixins.yaml b/.github/workflows/mixins.yaml index 083934c..3a18794 100644 --- a/.github/workflows/mixins.yaml +++ b/.github/workflows/mixins.yaml @@ -14,18 +14,31 @@ jobs: ref: ${{ github.event.pull_request.head.sha }} persist-credentials: true + - name: Update Jsonnet dependencies + if: ${{ github.actor == 'renovate[bot]' }} + run: make vendor + env: + JB_ARGS: update + - name: Render mixins run: make + - name: Get status + run: echo "changed=$(git status --short | grep -c -E "docs|jsonnetfile.lock.json")" >> "$GITHUB_OUTPUT" + id: status + - name: Push changes + if: ${{ github.actor == 'renovate[bot]' && steps.status.outputs.changed !=0 }} run: | + git add docs jsonnetfile.lock.json git config --global user.name "github-actions[bot]" - git config --global user.email "github-actions[bot]@noreply.github.com" - git add . + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + git commit -m "Update files after Renovate update" + git push origin HEAD:refs/heads/${{ github.event.pull_request.head.ref }} - if git diff --staged --quiet; then - echo "No changes detected. Skipping ..." - else - git commit -m "Update rendered mixins" - git push - fi + - name: Detected changes + if: ${{ github.actor != 'renovate[bot]' && steps.status.outputs.changed !=0 }} + run: | + echo "::error::Detected changes in the rendered docs files. Please run 'make' locally and commit the changes." + git status --short docs + exit 1 diff --git a/Makefile b/Makefile index dbb8d68..4d7cd92 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,8 @@ #!/usr/bin/make -f OUT_DIR ?= docs +JB_ARGS ?= install +export GOFLAGS := -mod=mod export GOBIN := $(shell pwd)/bin JB_BIN := $(GOBIN)/jb JSONNET_BIN := $(GOBIN)/jsonnet @@ -14,15 +16,15 @@ alerts: $(addprefix prometheusAlerts-, $(mixins)) rules: $(addprefix prometheusRules-, $(mixins)) .DEFAULT_GOAL := all -all: deps dashboards prom +all: vendor dashboards prom prom: alerts rules -dashboards-%: deps $(tools) +dashboards-%: vendor $(tools) @echo "Rendering dashboards for $* ..." @$(JSONNET_BIN) -J vendor -cm $(OUT_DIR)/$*/dashboards -e '(import "mixins/$*.libsonnet").grafanaDashboards' @find $(OUT_DIR)/$*/dashboards -type f -name '*.json' -exec $(YQ_BIN) --inplace --indent 2 --prettyPrint -o json {} \; -prometheus%: deps $(tools) +prometheus%: vendor $(tools) $(eval TYPE := $(word 1,$(subst -, ,$@))) $(eval MIXIN := $(word 2,$(subst -, ,$@))) $(eval TARGET_FILE := $(OUT_DIR)/$(MIXIN)/$(TYPE)) @@ -38,9 +40,9 @@ $(tools): go install github.com/jsonnet-bundler/jsonnet-bundler/cmd/jb@latest go install github.com/mikefarah/yq/v4@latest -.PHONY: deps -deps: $(tools) - @$(JB_BIN) install +.PHONY: vendor +vendor: $(tools) + @$(JB_BIN) $(JB_ARGS) .PHONY: clean clean: