Skip to content

Commit

Permalink
Update workflow and Makefile
Browse files Browse the repository at this point in the history
  • Loading branch information
bonddim committed Sep 6, 2024
1 parent e4d6db5 commit 399cff8
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 14 deletions.
29 changes: 21 additions & 8 deletions .github/workflows/mixins.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -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:
Expand Down

0 comments on commit 399cff8

Please sign in to comment.