From 6aabef96e6fafe199971d2369ca42ca8b07da3d3 Mon Sep 17 00:00:00 2001 From: Horst Gutmann Date: Wed, 3 Jul 2024 14:17:25 +0200 Subject: [PATCH] Add workflow for detecting a drift in the generated Dagger files --- .github/workflows/acceptance-tests.yml | 1 + .github/workflows/check-dagger-drift.yml | 47 ++++++++++++++++++++++++ Makefile | 7 +++- 3 files changed, 54 insertions(+), 1 deletion(-) create mode 100644 .github/workflows/check-dagger-drift.yml diff --git a/.github/workflows/acceptance-tests.yml b/.github/workflows/acceptance-tests.yml index 65f069da7..701a98b34 100644 --- a/.github/workflows/acceptance-tests.yml +++ b/.github/workflows/acceptance-tests.yml @@ -15,6 +15,7 @@ jobs: - name: Checkout uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 - name: Call Dagger Function + id: dagger uses: dagger/dagger-for-github@11048419d80c283890d0dd68187d44541f63dd89 # v5.11.0 with: version: "0.11.9" diff --git a/.github/workflows/check-dagger-drift.yml b/.github/workflows/check-dagger-drift.yml new file mode 100644 index 000000000..02cb891f8 --- /dev/null +++ b/.github/workflows/check-dagger-drift.yml @@ -0,0 +1,47 @@ +name: "Check for drift in Dagger files" + +on: + pull_request: + branches: + - main + +jobs: + check-dagger-drift: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@a5ac7e51b41094c92402da3b24376905380afc29 # v4.1.6 + + - name: Determine Dagger version + id: dagger_version + run: | + sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq + sudo chmod +x /usr/bin/yq + cat .github/workflows/acceptance-tests.yml| yq -r '.jobs.build.steps[] | select(.id == "dagger") | .with.version' > .version + echo "version=$(<.version)" > $GITHUB_OUTPUT + rm -rf .version + + - uses: actions/cache@v4 + id: cache_daggercli + with: + path: bin + key: daggercli-download-${{ steps.dagger_version.outputs.version }} + + - name: Install Dagger CLI + if: steps.cache_daggercli.outputs.cache-hit != 'true' + shell: bash + run: | + curl -L https://dl.dagger.io/dagger/install.sh | DAGGER_VERSION=${{ steps.dagger_version.outputs.version }} sh + + - name: Check drift + run: | + set -e + export PATH=$PATH:$PWD/bin + make dagger-develop + if [[ -z "$(git status --porcelain ./dagger)" ]]; then + echo "No drift detected" + else + echo "Drift detected. Run 'make dagger-develop' and commit the changed files." + git diff + exit 1 + fi diff --git a/Makefile b/Makefile index 6f308ce72..a04fd8d61 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -.PHONY: lint test static install uninstall cross acceptance-tests +.PHONY: lint test static install uninstall cross acceptance-tests dagger-develop GOPATH := $(shell go env GOPATH) VERSION := $(shell git describe --tags --dirty --always) BIN_DIR := $(GOPATH)/bin @@ -41,3 +41,8 @@ cross: $(GOX) # Docker container container: static docker build -t grafana/tanka . + +dagger-develop: + @cp dagger/.gitignore dagger/.gitignore.bak + @dagger develop --silent + @mv dagger/.gitignore.bak dagger/.gitignore