From 6cf785ce547eca641023801022fdd5f73348b188 Mon Sep 17 00:00:00 2001
From: Anna Shaleva <shaleva.ann@nspcc.ru>
Date: Thu, 25 Apr 2024 16:25:13 +0300
Subject: [PATCH] workflows: ensure autogenerated code is up-to-date

In case if source of stringers or any other autogenerated code is
updated we need to regenerate the target files. It's easy to forget
about it.

Ref. 8995f11d39cc6b5f5b0081039bbe616dd7aaf38e.

Signed-off-by: Anna Shaleva <shaleva.ann@nspcc.ru>
---
 .github/workflows/tests.yml | 26 ++++++++++++++++++++++++++
 1 file changed, 26 insertions(+)

diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml
index 295566833..5fd544564 100644
--- a/.github/workflows/tests.yml
+++ b/.github/workflows/tests.yml
@@ -39,6 +39,32 @@ jobs:
         run: |
           ./scripts/check_deps.sh
 
+  codegencheck:
+    name: Check code generated with 'go generate' is up-to-date
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v4
+        with:
+          fetch-depth: 0
+      - uses: actions/setup-go@v5
+        with:
+          go-version-file: 'go.mod'
+
+      - name: Install stringer
+        run: go install golang.org/x/tools/cmd/stringer@latest
+
+      - name: Run go generate
+        run: go generate ./...
+
+      - name: Check that autogenerated code is up-to-date
+        run: |
+          if [[ $(git diff --name-only | grep '' -c) != 0 ]]; then
+          echo "Fresh version of autogenerated code should be committed for the following files:";
+          git diff --name-only;
+          exit 1;
+          fi
+
   codeql:
     name: CodeQL
     runs-on: ubuntu-latest