From afd23657c0ff7219981288fc5744a9753f0e4ed4 Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:15:14 +0200 Subject: [PATCH 01/15] feat: help, version menu --- Makefile | 5 +++-- include/version.h | 9 +++++++++ src/main.c | 21 +++++++++++++++++++-- 3 files changed, 31 insertions(+), 4 deletions(-) create mode 100644 include/version.h diff --git a/Makefile b/Makefile index 5929207..80de16a 100644 --- a/Makefile +++ b/Makefile @@ -8,11 +8,12 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall _CFLAGS=-I$(DIR) -ALLFLAGS=$(CFLAGS) -I$(IDIR) +BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" +ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) LIBS=-lpam -_DEPS = log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h +_DEPS = version.h log.h util.h ui.h ui_state.h config.h desktop.h auth.h ofield.h efield.h keys.h users.h sessions.h chvt.h macros.h launch_state.h DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o diff --git a/include/version.h b/include/version.h new file mode 100644 index 0000000..df9d7f2 --- /dev/null +++ b/include/version.h @@ -0,0 +1,9 @@ +#ifndef LIDM_VERSION +#define LIDM_VERSION "v1.1.1" +#endif +#ifndef LIDM_GIT_DESCRIPTION +#define LIDM_GIT_DESCRIPTION "?" +#endif +#ifndef LIDM_BUILD_DATE +#define LIDM_BUILD_DATE "?" +#endif diff --git a/src/main.c b/src/main.c index 3ec6f92..186a85d 100644 --- a/src/main.c +++ b/src/main.c @@ -1,6 +1,7 @@ #include #include #include +#include #include #include #include @@ -12,6 +13,7 @@ #include "ui.h" #include "users.h" #include "util.h" +#include "version.h" int main(int argc, char* argv[]) { // Logger @@ -27,8 +29,23 @@ int main(int argc, char* argv[]) { log_init(log_fd); } - // Chvt - if (argc == 2) chvt_str(argv[1]); + if (argc == 2) { + if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { + printf("lidm version %s (git %s, build date %s)\n", LIDM_VERSION, + LIDM_GIT_DESCRIPTION, LIDM_BUILD_DATE); + return 0; + } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { + printf( + "Usage: lidm [vt number]\n" + "Options:\n" + " -h, --help Display help menu\n" + " -v, --version Display version information\n"); + return 0; + } else { + // Chvt + chvt_str(argv[1]); + } + } struct config config = DEFAULT_CONFIG; char* conf_override = getenv("LIDM_CONF"); From 9245d38ecfd10f0564aaab0bd1ff43ce2c9db917 Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:28:47 +0200 Subject: [PATCH 02/15] ci: fix: install git before checkout action --- .github/workflows/check-and-build.yml | 28 +++++++++++++++++++-------- 1 file changed, 20 insertions(+), 8 deletions(-) diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index 36d1ed0..450cff8 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -54,6 +54,10 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev" + version: 1.0 - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses @@ -62,10 +66,6 @@ jobs: status: pending description: ${{ steps.build.outputs.DESCR }} context: Build for amd64 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "libpam0g-dev" - version: 1.0 - id: build run: | make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) @@ -98,6 +98,10 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev gcc-multilib" + version: 1.0 - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses @@ -106,10 +110,6 @@ jobs: status: pending description: ${{ steps.build.outputs.DESCR }} context: Build for i386 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "libpam0g-dev gcc-multilib" - version: 1.0 - run: | sudo dpkg --add-architecture i386 sudo apt-get update -y @@ -146,6 +146,10 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev" + version: 1.0 - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses @@ -196,6 +200,10 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev" + version: 1.0 - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses @@ -246,6 +254,10 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev" + version: 1.0 - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses From 3ec1eec56f33827279d782bea18233abaaf3549b Mon Sep 17 00:00:00 2001 From: grialion <48643945+grialion@users.noreply.github.com> Date: Fri, 4 Jul 2025 00:40:10 +0200 Subject: [PATCH 03/15] fix: git describe always (even in CI build) use --always to make it work on shallow cloned repos (ie. CI build job) --- Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Makefile b/Makefile index 80de16a..668abe0 100644 --- a/Makefile +++ b/Makefile @@ -8,7 +8,7 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall _CFLAGS=-I$(DIR) -BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" +BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags --always || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) LIBS=-lpam From 19a1355b06a4c3efa89b1db05c5f09ceb8bb32b9 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 15:19:25 +0200 Subject: [PATCH 04/15] dev: automatic version.h generation also added compiler information as a feature --- .gitignore | 2 ++ Makefile | 27 +++++++++++++++++++++++++-- include/macros.h | 10 ++++++++++ include/version.h | 9 --------- src/main.c | 35 +++++++++++++++++++++++++++++------ 5 files changed, 66 insertions(+), 17 deletions(-) delete mode 100644 include/version.h diff --git a/.gitignore b/.gitignore index 097f96e..34588b2 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ valgrind-out.txt # nix build result result + +include/version.h diff --git a/Makefile b/Makefile index 668abe0..f7955de 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,6 @@ +VERSION = 1.1.1 +.DEFAULT_GOAL := lidm + CDIR=src LDIR=lib IDIR=include @@ -8,7 +11,7 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall _CFLAGS=-I$(DIR) -BUILD_FLAGS=-DLIDM_GIT_DESCRIPTION="\"$(shell git describe --long --tags --always || echo ?)\"" -DLIDM_BUILD_DATE="\"$(shell date -u +"%Y-%m-%dT%H:%M:%SZ" || echo ?)\"" +BUILD_FLAGS= ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) LIBS=-lpam @@ -19,6 +22,17 @@ DEPS = $(patsubst %,$(IDIR)/%,$(_DEPS)) _OBJ = main.o log.o util.o ui.o ui_state.o config.o desktop.o auth.o ofield.o efield.o users.o sessions.o chvt.o launch_state.o OBJ = $(patsubst %,$(ODIR)/%,$(_OBJ)) +$(IDIR)/version.h: Makefile .git/HEAD + @tmp=$$(mktemp); \ + printf '' > $$tmp; \ + echo '#define LIDM_VERSION "'$(VERSION)'"' >> $$tmp; \ + echo '#define LIDM_GIT_REV "'$$(git describe --long --tags --always)'"' >> $$tmp; \ + echo '#define LIDM_BUILD_TS '$$(date +%s) >> $$tmp; \ + if ! cmp -s $$tmp $@; then \ + mv $$tmp $@; \ + fi; \ + rm -f $$tmp; + $(ODIR)/%.o: $(CDIR)/%.c $(DEPS) @mkdir -p $(ODIR) $(CC) -c -o $@ $< $(ALLFLAGS) @@ -26,7 +40,6 @@ $(ODIR)/%.o: $(CDIR)/%.c $(DEPS) lidm: $(OBJ) $(CC) -o $@ $^ $(ALLFLAGS) $(LIBS) -.PHONY: clean clean: rm -f $(ODIR)/*.o lidm @@ -79,3 +92,13 @@ pre-commit: find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck clang-format -i $$(git ls-files "*.c" "*.h") clang-tidy -p . $$(git ls-files "*.c" "*.h") + +.PHONY: clean \ + install uninstall \ + install-service \ + install-service-s6 \ + install-service-dinit \ + install-service-runit \ + install-service-openrc \ + install-service-systemd \ + pre-commit diff --git a/include/macros.h b/include/macros.h index c549cf1..ad0f718 100644 --- a/include/macros.h +++ b/include/macros.h @@ -20,6 +20,16 @@ #define UNULLABLE #endif +#if defined(__clang__) +#define COMPILER_VERSION __VERSION__ +#elif defined(__GNUC__) +#define xstr(s) str(s) +#define str(s) #s + +#define COMPILER_VERSION \ +"GCC " xstr(__GNUC__) "." xstr(__GNUC_MINOR__) "." xstr(__GNUC_PATCHLEVEL__) +#endif + #define LEN(X) (sizeof(X) / sizeof((X)[0])) #endif diff --git a/include/version.h b/include/version.h deleted file mode 100644 index df9d7f2..0000000 --- a/include/version.h +++ /dev/null @@ -1,9 +0,0 @@ -#ifndef LIDM_VERSION -#define LIDM_VERSION "v1.1.1" -#endif -#ifndef LIDM_GIT_DESCRIPTION -#define LIDM_GIT_DESCRIPTION "?" -#endif -#ifndef LIDM_BUILD_DATE -#define LIDM_BUILD_DATE "?" -#endif diff --git a/src/main.c b/src/main.c index 186a85d..41bdd53 100644 --- a/src/main.c +++ b/src/main.c @@ -4,17 +4,20 @@ #include #include #include +#include #include #include "chvt.h" #include "config.h" #include "log.h" +#include "macros.h" #include "sessions.h" #include "ui.h" #include "users.h" #include "util.h" #include "version.h" +#define DATESTR_MAXBUFSIZE 0x20 int main(int argc, char* argv[]) { // Logger char* log_output = getenv("LIDM_LOG"); @@ -31,20 +34,40 @@ int main(int argc, char* argv[]) { if (argc == 2) { if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { - printf("lidm version %s (git %s, build date %s)\n", LIDM_VERSION, - LIDM_GIT_DESCRIPTION, LIDM_BUILD_DATE); + char* version = "?"; + char* revision = "?"; + char* builddate = "?"; + char* compilever = "?"; +#ifdef LIDM_VERSION + version = LIDM_VERSION; +#endif +#ifdef LIDM_GIT_REV + revision = LIDM_GIT_REV; +#endif +#ifdef LIDM_BUILD_TS + time_t ts = LIDM_BUILD_TS; + char date_buf[DATESTR_MAXBUFSIZE]; + builddate = date_buf; + if (strftime(date_buf, 0xff, "%Y-%m-%dT%H:%M:%SZ", localtime(&ts)) > 0) + builddate = date_buf; +#endif +#ifdef COMPILER_VERSION + compilever = COMPILER_VERSION; +#endif + printf("lidm version %s (git %s, build date %s, compiler %s)\n", version, + revision, builddate, compilever); return 0; - } else if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { + } + if (strcmp(argv[1], "-h") == 0 || strcmp(argv[1], "--help") == 0) { printf( "Usage: lidm [vt number]\n" "Options:\n" " -h, --help Display help menu\n" " -v, --version Display version information\n"); return 0; - } else { - // Chvt - chvt_str(argv[1]); } + // Chvt + chvt_str(argv[1]); } struct config config = DEFAULT_CONFIG; From 3fb74ece4496e0ff212413e8c900fb2adab858e9 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 15:23:22 +0200 Subject: [PATCH 05/15] style: indent preprocessor directives --- .clang-format | 3 +++ include/macros.h | 22 +++++++++++----------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/.clang-format b/.clang-format index 19acc21..bc877c6 100644 --- a/.clang-format +++ b/.clang-format @@ -6,3 +6,6 @@ AllowShortIfStatementsOnASingleLine: WithoutElse AlignAfterOpenBracket: Align BinPackParameters: true AllowAllParametersOfDeclarationOnNextLine: true + +IndentPPDirectives: BeforeHash +IndentGotoLabels: true diff --git a/include/macros.h b/include/macros.h index ad0f718..56f3fb3 100644 --- a/include/macros.h +++ b/include/macros.h @@ -3,31 +3,31 @@ // Do we just replace the compiler with clang?? #if defined(__clang__) -#define NULLABLE _Nullable + #define NULLABLE _Nullable #else -#define NULLABLE + #define NULLABLE #endif #if defined(__clang__) -#define NNULLABLE _Nonnull + #define NNULLABLE _Nonnull #else -#define NNULLABLE + #define NNULLABLE #endif #if defined(__clang__) -#define UNULLABLE _Null_unspecified + #define UNULLABLE _Null_unspecified #else -#define UNULLABLE + #define UNULLABLE #endif #if defined(__clang__) -#define COMPILER_VERSION __VERSION__ + #define COMPILER_VERSION __VERSION__ #elif defined(__GNUC__) -#define xstr(s) str(s) -#define str(s) #s + #define xstr(s) str(s) + #define str(s) #s -#define COMPILER_VERSION \ -"GCC " xstr(__GNUC__) "." xstr(__GNUC_MINOR__) "." xstr(__GNUC_PATCHLEVEL__) + #define COMPILER_VERSION \ + "GCC " xstr(__GNUC__) "." xstr(__GNUC_MINOR__) "." xstr(__GNUC_PATCHLEVEL__) #endif #define LEN(X) (sizeof(X) / sizeof((X)[0])) From 736e816509a8f5be382b8bdef3c27be4a5af73a2 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 15:50:18 +0200 Subject: [PATCH 06/15] style: satisfy clang-tidy --- src/main.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/main.c b/src/main.c index 41bdd53..c67072c 100644 --- a/src/main.c +++ b/src/main.c @@ -34,10 +34,12 @@ int main(int argc, char* argv[]) { if (argc == 2) { if (strcmp(argv[1], "-v") == 0 || strcmp(argv[1], "--version") == 0) { + // NOLINTBEGIN(clang-analyzer-deadcode.DeadStores) char* version = "?"; char* revision = "?"; char* builddate = "?"; char* compilever = "?"; + // NOLINTEND(clang-analyzer-deadcode.DeadStores) #ifdef LIDM_VERSION version = LIDM_VERSION; #endif From e4b11f9a30f59186981e046ebbe4fa4d98b417c9 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 15:50:37 +0200 Subject: [PATCH 07/15] ci: add clang-tidy to CI --- .github/workflows/check-and-build.yml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index 450cff8..326951e 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -44,8 +44,7 @@ jobs: packages: "clang-format clang-tidy" version: 1.0 - run: clang-format -ni src/*.c include/*.h - # TODO: include when the errors/warnings are bearable - #- run: clang-tidy src/*.c include/*.h + - run: clang-tidy -p . src/*.c include/*.h build-linux-amd64: name: Build for amd64 From 240bdbede6dfd64625828684b57b54bae9ac3170 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 15:56:31 +0200 Subject: [PATCH 08/15] ci(9245d38): set-status first of all and no need to cache libpam for vm build architectures --- .github/workflows/check-and-build.yml | 50 +++++++++++++-------------- 1 file changed, 25 insertions(+), 25 deletions(-) diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index 326951e..ff7aed6 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -53,11 +53,6 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "git libpam0g-dev" - version: 1.0 - - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses with: @@ -65,6 +60,11 @@ jobs: status: pending description: ${{ steps.build.outputs.DESCR }} context: Build for amd64 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev" + version: 1.0 + - uses: actions/checkout@v4 - id: build run: | make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) @@ -97,11 +97,6 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "git libpam0g-dev gcc-multilib" - version: 1.0 - - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses with: @@ -109,6 +104,11 @@ jobs: status: pending description: ${{ steps.build.outputs.DESCR }} context: Build for i386 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git libpam0g-dev gcc-multilib" + version: 1.0 + - uses: actions/checkout@v4 - run: | sudo dpkg --add-architecture i386 sudo apt-get update -y @@ -145,11 +145,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "git libpam0g-dev" - version: 1.0 - - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses with: @@ -157,6 +152,11 @@ jobs: status: pending description: ${{ steps.status.outputs.DESCR }} context: Build for aarch64 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git" + version: 1.0 + - uses: actions/checkout@v4 - uses: uraimo/run-on-arch-action@v2 with: arch: aarch64 @@ -199,11 +199,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "git libpam0g-dev" - version: 1.0 - - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses with: @@ -211,6 +206,11 @@ jobs: status: pending description: ${{ steps.status.outputs.DESCR }} context: Build for armv7 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git" + version: 1.0 + - uses: actions/checkout@v4 - uses: uraimo/run-on-arch-action@v2 with: arch: armv7 @@ -253,11 +253,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "git libpam0g-dev" - version: 1.0 - - uses: actions/checkout@v4 - uses: myrotvorets/set-commit-status-action@master if: inputs.set-statuses with: @@ -265,6 +260,11 @@ jobs: status: pending description: ${{ steps.status.outputs.DESCR }} context: Build for riscv64 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git" + version: 1.0 + - uses: actions/checkout@v4 - uses: uraimo/run-on-arch-action@v2 with: arch: riscv64 From 7cd976f916b8fa12a0f6b169b3602248ebf07ab7 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 16:03:42 +0200 Subject: [PATCH 09/15] ci: fix clang-tidy --- .github/workflows/check-and-build.yml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index ff7aed6..69c6ba4 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -41,8 +41,9 @@ jobs: - uses: actions/checkout@v4 - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: "clang-format clang-tidy" + packages: "clang-format clang-tidy bear" version: 1.0 + - run: bear -- make - run: clang-format -ni src/*.c include/*.h - run: clang-tidy -p . src/*.c include/*.h From d1b993c32ab864ecec6cd5a4c08a7c027886d1c9 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 16:05:14 +0200 Subject: [PATCH 10/15] ci: fix bear --- .github/workflows/check-and-build.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index 69c6ba4..3571501 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -41,7 +41,7 @@ jobs: - uses: actions/checkout@v4 - uses: awalsh128/cache-apt-pkgs-action@latest with: - packages: "clang-format clang-tidy bear" + packages: "clang-format clang-tidy bear libpam0g-dev" version: 1.0 - run: bear -- make - run: clang-format -ni src/*.c include/*.h From 521a7c295ec2066024d746ed0058ac8084b61aed Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 16:39:29 +0200 Subject: [PATCH 11/15] rm: unused Makefile flags --- Makefile | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Makefile b/Makefile index f7955de..f2f1a5a 100644 --- a/Makefile +++ b/Makefile @@ -10,9 +10,7 @@ PREFIX=/usr CC?=gcc CFLAGS?=-O3 -Wall -_CFLAGS=-I$(DIR) -BUILD_FLAGS= -ALLFLAGS=$(CFLAGS) -I$(IDIR) $(BUILD_FLAGS) +ALLFLAGS=$(CFLAGS) -I$(IDIR) LIBS=-lpam From f3ae85bb94ea5d9aa300c996d019c191709e67ba Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 17:55:49 +0200 Subject: [PATCH 12/15] feat|fix: improve all ci behavior --- .github/workflows/check-and-build.yml | 145 ++------------------------ .github/workflows/make-release.yml | 2 - assets/github_scripts/build.sh | 47 +++++++++ 3 files changed, 55 insertions(+), 139 deletions(-) create mode 100755 assets/github_scripts/build.sh diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/check-and-build.yml index 3571501..2461cd1 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/check-and-build.yml @@ -2,11 +2,6 @@ name: Check and Build on: workflow_call: - inputs: - set-statuses: - required: false - default: true - type: boolean jobs: spellcheck: @@ -54,36 +49,13 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - description: ${{ steps.build.outputs.DESCR }} - context: Build for amd64 - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: "git libpam0g-dev" version: 1.0 - uses: actions/checkout@v4 - id: build - run: | - make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) - cat /tmp/stderr >&2 - - HSIZE="$(stat --printf="%s" lidm | numfmt --to=iec-i)B" - WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)" - mv lidm lidm-amd64 - - echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT" - - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - description: ${{ steps.build.outputs.DESCR }} - context: Build for amd64 + run: ARCH=amd64 assets/github_scripts/build.sh - uses: actions/upload-artifact@v4 with: @@ -98,13 +70,6 @@ jobs: needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - description: ${{ steps.build.outputs.DESCR }} - context: Build for i386 - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: "git libpam0g-dev gcc-multilib" @@ -116,23 +81,7 @@ jobs: sudo apt-get install -y libpam0g-dev:i386 - id: build - run: | - make -j$(nproc) CFLAGS="-O3 -Wall -m32" 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) - cat /tmp/stderr >&2 - - HSIZE="$(stat --printf="%s" lidm | numfmt --to=iec-i)B" - WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)" - mv lidm lidm-i386 - - echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT" - - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - description: ${{ steps.build.outputs.DESCR }} - context: Build for i386 + run: ARCH=i386 assets/github_scripts/build.sh CFLAGS="-O3 -Wall -m32" - uses: actions/upload-artifact@v4 with: @@ -146,13 +95,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - description: ${{ steps.status.outputs.DESCR }} - context: Build for aarch64 - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: "git" @@ -166,27 +108,8 @@ jobs: install: | apt-get update && \ apt-get install -y make gcc libpam0g-dev - run: | - make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) - - cat /tmp/stderr >&2 - mv lidm lidm-aarch64 - - - if: inputs.set-statuses - id: status - run: | - HSIZE="$(stat --printf="%s" lidm-aarch64 | numfmt --to=iec-i)B" - WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)" - - echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT" - - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - description: ${{ steps.status.outputs.DESCR }} - context: Build for aarch64 + run: ARCH=aarch64 GITHUB_STEP_SUMMARY=gss.out GITHUB_OUTPUT=go.out assets/github_scripts/build.sh + - run: set +e; cat gss.out >>"$GITHUB_STEP_SUMMARY"; cat go.out >>"$GITHUB_OUTPUT" - uses: actions/upload-artifact@v4 with: @@ -200,13 +123,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - description: ${{ steps.status.outputs.DESCR }} - context: Build for armv7 - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: "git" @@ -220,27 +136,8 @@ jobs: install: | apt-get update && \ apt-get install -y make gcc libpam0g-dev - run: | - make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) - - cat /tmp/stderr >&2 - mv lidm lidm-armv7 - - - if: inputs.set-statuses - id: status - run: | - HSIZE="$(stat --printf="%s" lidm-armv7 | numfmt --to=iec-i)B" - WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)" - - echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT" - - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - description: ${{ steps.status.outputs.DESCR }} - context: Build for armv7 + run: ARCH=armv7 GITHUB_STEP_SUMMARY=gss.out GITHUB_OUTPUT=go.out assets/github_scripts/build.sh + - run: set +e; cat gss.out >>"$GITHUB_STEP_SUMMARY"; cat go.out >>"$GITHUB_OUTPUT" - uses: actions/upload-artifact@v4 with: @@ -254,13 +151,6 @@ jobs: permissions: write-all needs: [spellcheck, shellcheck, clangcheck] steps: - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: pending - description: ${{ steps.status.outputs.DESCR }} - context: Build for riscv64 - uses: awalsh128/cache-apt-pkgs-action@latest with: packages: "git" @@ -274,27 +164,8 @@ jobs: install: | apt-get update && \ apt-get install -y make gcc libpam0g-dev - run: | - make -j$(nproc) 2> /tmp/stderr || (ERR=$?; cat /tmp/stderr >&2; exit $ERR) - - cat /tmp/stderr >&2 - mv lidm lidm-riscv64 - - - if: inputs.set-statuses - id: status - run: | - HSIZE="$(stat --printf="%s" lidm-riscv64 | numfmt --to=iec-i)B" - WARNS="$(cat /tmp/stderr | grep '^[^ ]*\.[ch]:' | wc -l)" - - echo "DESCR='$HSIZE, $WARNS warnings'" >> "$GITHUB_OUTPUT" - - - uses: myrotvorets/set-commit-status-action@master - if: inputs.set-statuses - with: - token: ${{ secrets.GITHUB_TOKEN }} - status: ${{ job.status }} - description: ${{ steps.status.outputs.DESCR }} - context: Build for riscv64 + run: ARCH=riscv64 GITHUB_STEP_SUMMARY=gss.out GITHUB_OUTPUT=go.out assets/github_scripts/build.sh + - run: set +e; cat gss.out >>"$GITHUB_STEP_SUMMARY"; cat go.out >>"$GITHUB_OUTPUT" - uses: actions/upload-artifact@v4 with: diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index c0daa81..d036719 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -13,8 +13,6 @@ jobs: name: Check and Build uses: ./.github/workflows/check-and-build.yml permissions: write-all - with: - set-statuses: false release: name: Make Release v${{ inputs.version }} diff --git a/assets/github_scripts/build.sh b/assets/github_scripts/build.sh new file mode 100755 index 0000000..8536363 --- /dev/null +++ b/assets/github_scripts/build.sh @@ -0,0 +1,47 @@ +#!/usr/bin/env bash +set -euo pipefail + +if [ -z "$ARCH" ]; then + echo "\$ARCH not present" >&2 + exit 1 +fi + +ERR=0 +# shellcheck disable=SC2034 +make -j"$(nproc)" "$@" 2> /tmp/stderr || ERR=$? + +BSIZE=$(stat --printf="%s" lidm) +HSIZE=$(numfmt --to=iec-i<<<"$BSIZE")B +WARNS=$( + { grep -E '^[^ ]+\.[ch]:[0-9]+:[0-9]+: [a-z]+:' /tmp/stderr || :; } \ + | sed -E 's/^([^ ]+\.[ch]):([0-9]+):([0-9]+): ([a-z]+): (.*)$/::\4 file=\1,line=\2,col=\3::\5/' +) +WARNS_NUM=$({ [[ "$WARNS" == "" ]] && echo 0; } || wc -l <<<"$WARNS") + +echo "$WARNS" + +{ + echo "# Build for $ARCH" + echo "" + if [ -s "/tmp/stderr" ]; then + echo "
stderr" + echo "" + echo "\`\`\`" + cat "/tmp/stderr" + echo "\`\`\`" + echo "" + echo "
" + else + echo "*no \`stderr\` to show*" + fi + echo "" + echo "## Stats" + echo "* **Filesize:** $HSIZE ($BSIZE B)" + echo "* **Warnings & Errors:** $WARNS_NUM" +} >> "$GITHUB_STEP_SUMMARY" + +if [ "$ERR" -ne 0 ]; then exit "$ERR"; fi + +mv lidm lidm-"$ARCH" + +echo "DESCR='$HSIZE, $WARNS_NUM warnings'" >> "$GITHUB_OUTPUT" From 3d6efa448b6642792e086b3d76a07b421d4f27b2 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 18:59:04 +0200 Subject: [PATCH 13/15] ci: update make release action --- .github/workflows/make-release.yml | 42 +++++++++++++++++++++++------- Makefile | 8 ++++-- 2 files changed, 38 insertions(+), 12 deletions(-) diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index d036719..c44c01a 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -2,23 +2,45 @@ name: Check and Build Release on: workflow_dispatch: - inputs: - version: - required: true - default: '' - type: string jobs: + release-checks: + name: Release Checks + runs-on: ubuntu-24.04 + permissions: write-all + outputs: + VERSION: ${{ steps.check-ver-changed.outputs.VERSION }} + steps: + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "git" + version: 1.0 + - uses: actions/checkout@v4 + + - name: Check Version Changed + id: check-ver-changed + run: | + GIT_TAG=$(git describe --no-long --abbrev=0 --tags --always) + MAKE_TAG=$(make print-version) + + if [[ "$GIT_TAG" == "v$MAKE_TAG" ]]; then + echo "ERR: Git tag matches makefile, did you bump Makefile up?" >&2 + exit 1 + fi + echo "VERSION=$MAKE_TAG" >> "$GITHUB_OUTPUT" + + build: name: Check and Build + needs: release-checks uses: ./.github/workflows/check-and-build.yml permissions: write-all release: - name: Make Release v${{ inputs.version }} + name: Make Release v${{ needs.release-checks.outputs.VERSION }} runs-on: ubuntu-24.04 permissions: write-all - needs: build + needs: [ release-checks, build ] steps: - uses: actions/download-artifact@v4 with: @@ -28,7 +50,7 @@ jobs: - uses: ncipollo/release-action@v1 with: - tag: v${{ inputs.version }} + tag: v${{ needs.release-checks.outputs.VERSION }} commit: ${{ github.sha }} artifacts: builds/lidm-* artifactErrorsFailBuild: true @@ -39,7 +61,7 @@ jobs: runs-on: ubuntu-24.04 container: archlinux:latest permissions: write-all - needs: release + needs: [ release-checks, release ] steps: - run: pacman -Sy --noconfirm git github-cli base-devel pacman-contrib @@ -51,7 +73,7 @@ jobs: cd "assets/pkg/aur" chown nobody:nobody . -R - su - -s /bin/bash nobody -c "$PWD/update-pkgs.sh ${{ inputs.version }}" + su - -s /bin/bash nobody -c "$PWD/update-pkgs.sh ${{ needs.release-checks.outputs.VERSION }}" su - -s /bin/bash nobody -c "$PWD/test-makepkg.sh" # This will also update -git pkgver chown $UID:$(id -g) . -R diff --git a/Makefile b/Makefile index f2f1a5a..ff9ef8b 100644 --- a/Makefile +++ b/Makefile @@ -1,4 +1,4 @@ -VERSION = 1.1.1 +VERSION = 1.2.0 .DEFAULT_GOAL := lidm CDIR=src @@ -91,6 +91,9 @@ pre-commit: clang-format -i $$(git ls-files "*.c" "*.h") clang-tidy -p . $$(git ls-files "*.c" "*.h") +print-version: + @echo $(VERSION) + .PHONY: clean \ install uninstall \ install-service \ @@ -99,4 +102,5 @@ pre-commit: install-service-runit \ install-service-openrc \ install-service-systemd \ - pre-commit + pre-commit \ + print-version From c05218d30acf84108112a5beb0e1a3549b594ef5 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 19:19:44 +0200 Subject: [PATCH 14/15] ci: split check & build --- .../{check-and-build.yml => build.yml} | 56 ++----------------- .github/workflows/check.yml | 43 ++++++++++++++ .github/workflows/make-release.yml | 14 +++-- .github/workflows/push.yml | 13 +++-- 4 files changed, 66 insertions(+), 60 deletions(-) rename .github/workflows/{check-and-build.yml => build.yml} (72%) create mode 100644 .github/workflows/check.yml diff --git a/.github/workflows/check-and-build.yml b/.github/workflows/build.yml similarity index 72% rename from .github/workflows/check-and-build.yml rename to .github/workflows/build.yml index 2461cd1..915d06c 100644 --- a/.github/workflows/check-and-build.yml +++ b/.github/workflows/build.yml @@ -1,53 +1,13 @@ -name: Check and Build +name: Build on: workflow_call: jobs: - spellcheck: - name: Check Grammar - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "codespell" - version: 1.0 - - run: codespell - - shellcheck: - name: Shell Check - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "shellcheck" - version: 1.0 - - run: find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck - - clangcheck: - name: Clang Check - runs-on: ubuntu-24.04 - - steps: - - uses: actions/checkout@v4 - - uses: awalsh128/cache-apt-pkgs-action@latest - with: - packages: "clang-format clang-tidy bear libpam0g-dev" - version: 1.0 - - run: bear -- make - - run: clang-format -ni src/*.c include/*.h - - run: clang-tidy -p . src/*.c include/*.h - build-linux-amd64: - name: Build for amd64 + name: amd64 runs-on: ubuntu-24.04 permissions: write-all - needs: [spellcheck, shellcheck, clangcheck] - steps: - uses: awalsh128/cache-apt-pkgs-action@latest with: @@ -64,10 +24,9 @@ jobs: retention-days: 1 build-linux-i386: - name: Build for i386 + name: i386 runs-on: ubuntu-24.04 permissions: write-all - needs: [spellcheck, shellcheck, clangcheck] steps: - uses: awalsh128/cache-apt-pkgs-action@latest @@ -90,10 +49,9 @@ jobs: retention-days: 1 build-linux-aarch64: - name: Build for aarch64 + name: aarch64 runs-on: ubuntu-24.04 permissions: write-all - needs: [spellcheck, shellcheck, clangcheck] steps: - uses: awalsh128/cache-apt-pkgs-action@latest with: @@ -118,10 +76,9 @@ jobs: retention-days: 1 build-linux-armv7: - name: Build for armv7 + name: armv7 runs-on: ubuntu-24.04 permissions: write-all - needs: [spellcheck, shellcheck, clangcheck] steps: - uses: awalsh128/cache-apt-pkgs-action@latest with: @@ -146,10 +103,9 @@ jobs: retention-days: 1 build-linux-riscv64: - name: Build for riscv64 + name: riscv64 runs-on: ubuntu-24.04 permissions: write-all - needs: [spellcheck, shellcheck, clangcheck] steps: - uses: awalsh128/cache-apt-pkgs-action@latest with: diff --git a/.github/workflows/check.yml b/.github/workflows/check.yml new file mode 100644 index 0000000..0a15b44 --- /dev/null +++ b/.github/workflows/check.yml @@ -0,0 +1,43 @@ +name: Check + +on: + workflow_call: + +jobs: + spellcheck: + name: Grammar + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "codespell" + version: 1.0 + - run: codespell + + shellcheck: + name: Shellcheck + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "shellcheck" + version: 1.0 + - run: find . -type f -name '*.sh' -not -path './assets/pkg/aur/*/src/*' | xargs shellcheck + + clangcheck: + name: Clang + runs-on: ubuntu-24.04 + + steps: + - uses: actions/checkout@v4 + - uses: awalsh128/cache-apt-pkgs-action@latest + with: + packages: "clang-format clang-tidy bear libpam0g-dev" + version: 1.0 + - run: bear -- make + - run: clang-format -ni src/*.c include/*.h + - run: clang-tidy -p . src/*.c include/*.h diff --git a/.github/workflows/make-release.yml b/.github/workflows/make-release.yml index c44c01a..87bb98c 100644 --- a/.github/workflows/make-release.yml +++ b/.github/workflows/make-release.yml @@ -30,17 +30,23 @@ jobs: echo "VERSION=$MAKE_TAG" >> "$GITHUB_OUTPUT" - build: - name: Check and Build + check: + name: Check needs: release-checks - uses: ./.github/workflows/check-and-build.yml + uses: ./.github/workflows/check.yml + permissions: write-all + + build: + name: Build + needs: release-checks + uses: ./.github/workflows/build.yml permissions: write-all release: name: Make Release v${{ needs.release-checks.outputs.VERSION }} runs-on: ubuntu-24.04 permissions: write-all - needs: [ release-checks, build ] + needs: [ release-checks, check, build ] steps: - uses: actions/download-artifact@v4 with: diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 427d926..0530da1 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,6 +1,3 @@ -# Kinda based by https://github.com/myrotvorets/set-commit-status-action/actions/runs/12344741285/workflow -name: Push Checks - on: push: branches: @@ -9,7 +6,11 @@ on: workflow_dispatch: jobs: - check-and-build: - name: Check and Build - uses: ./.github/workflows/check-and-build.yml + check: + name: Check + uses: ./.github/workflows/check.yml + permissions: write-all + build: + name: Build + uses: ./.github/workflows/build.yml permissions: write-all From 335459e1272f590ace6711a71c4cfe047d565d73 Mon Sep 17 00:00:00 2001 From: javalsai Date: Fri, 4 Jul 2025 19:21:29 +0200 Subject: [PATCH 15/15] ci: rename push workflow --- .github/workflows/push.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/push.yml b/.github/workflows/push.yml index 0530da1..a6b85b4 100644 --- a/.github/workflows/push.yml +++ b/.github/workflows/push.yml @@ -1,3 +1,5 @@ +name: _ + on: push: branches: