From 5eb2bafe5f48b46a8036368617e0a62ae2580e0a Mon Sep 17 00:00:00 2001 From: msclock Date: Mon, 4 Mar 2024 10:40:41 +0800 Subject: [PATCH 1/2] ci: add consistency checker Signed-off-by: msclock --- .github/workflows/ci.yml | 55 ++++++++++++++++++- .../workflows/ci.yml | 55 ++++++++++++++++++- 2 files changed, 108 insertions(+), 2 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 76db4bee..7438a649 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,12 +42,65 @@ jobs: with: commit_message: 'ci: auto fixes from pre-commit' + consistency: + if: ${{ !cancelled() && ! failure() }} + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Install copier for template rendering using pipx + run: pipx install copier + + - name: Generate the project with the default value + run: | + find . -maxdepth 1 ! -name '.' \ + ! -name 'template' \ + ! -name 'includes' \ + ! -name '.git' \ + ! -name 'copier.yml' \ + ! -name 'CHANGELOG.md' \ + -exec rm -r {} + + copier copy -r HEAD -f . . + rm .copier-answers.yml + + - name: Test for consistency + run: | + echo "List inconsistent files:" + git status --porcelain + git diff --exit-code || ( \ + echo "# :warning: Inconsistent files found" >> $GITHUB_STEP_SUMMARY && \ + echo "The following files are inconsistent with the template:" >> $GITHUB_STEP_SUMMARY && \ + git status --porcelain | while read file; do echo "- $file"; done >> $GITHUB_STEP_SUMMARY && \ + echo "" >> $GITHUB_STEP_SUMMARY && \ + echo "Please run 'copier copy -r HEAD -f . .' to fix them." >>$GITHUB_STEP_SUMMARY && \ + exit 1 \ + ) + + pass: + if: always() + needs: [pre-commit, consistency] + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + release: name: release runs-on: ubuntu-latest permissions: contents: write - needs: [pre-commit] + needs: [pass] steps: - name: Checkout diff --git a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml index 76db4bee..7438a649 100644 --- a/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml +++ b/template/[% if repo_host_type == 'github.com' %].github[% endif %]/workflows/ci.yml @@ -42,12 +42,65 @@ jobs: with: commit_message: 'ci: auto fixes from pre-commit' + consistency: + if: ${{ !cancelled() && ! failure() }} + runs-on: ubuntu-22.04 + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Set up Git + run: | + git config --global user.name "github-actions[bot]" + git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" + + - name: Install copier for template rendering using pipx + run: pipx install copier + + - name: Generate the project with the default value + run: | + find . -maxdepth 1 ! -name '.' \ + ! -name 'template' \ + ! -name 'includes' \ + ! -name '.git' \ + ! -name 'copier.yml' \ + ! -name 'CHANGELOG.md' \ + -exec rm -r {} + + copier copy -r HEAD -f . . + rm .copier-answers.yml + + - name: Test for consistency + run: | + echo "List inconsistent files:" + git status --porcelain + git diff --exit-code || ( \ + echo "# :warning: Inconsistent files found" >> $GITHUB_STEP_SUMMARY && \ + echo "The following files are inconsistent with the template:" >> $GITHUB_STEP_SUMMARY && \ + git status --porcelain | while read file; do echo "- $file"; done >> $GITHUB_STEP_SUMMARY && \ + echo "" >> $GITHUB_STEP_SUMMARY && \ + echo "Please run 'copier copy -r HEAD -f . .' to fix them." >>$GITHUB_STEP_SUMMARY && \ + exit 1 \ + ) + + pass: + if: always() + needs: [pre-commit, consistency] + runs-on: ubuntu-latest + timeout-minutes: 2 + steps: + - name: Decide whether the needed jobs succeeded or failed + uses: re-actors/alls-green@release/v1 + with: + jobs: ${{ toJSON(needs) }} + release: name: release runs-on: ubuntu-latest permissions: contents: write - needs: [pre-commit] + needs: [pass] steps: - name: Checkout From 801b33f4c2e3e94731f976f8608a1e953a026db1 Mon Sep 17 00:00:00 2001 From: msclock Date: Mon, 4 Mar 2024 14:45:48 +0800 Subject: [PATCH 2/2] ci: conform to consistency checker results Signed-off-by: msclock --- LICENSE | 2 +- docs/conf.py | 2 +- .../cmake_workflow.md | 24 +++++++++++++++++++ 3 files changed, 26 insertions(+), 2 deletions(-) create mode 100644 template/[% if docs_type == 'sphinx' %]docs[% endif %]/cmake_workflow.md diff --git a/LICENSE b/LICENSE index ac4fb552..49eb8e21 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2022-2023 Serious Scaffold +Copyright (c) 2022-2024 Serious Scaffold Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/docs/conf.py b/docs/conf.py index ea3d91d7..f8a776e5 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -18,7 +18,7 @@ # -- Project information ----------------------------------------------------- project = "SS Cpp" -copyright = "2022-2023 Serious Scaffold" +copyright = "2022-2024 Serious Scaffold" author = "msclock" # -- General configuration --------------------------------------------------- diff --git a/template/[% if docs_type == 'sphinx' %]docs[% endif %]/cmake_workflow.md b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/cmake_workflow.md new file mode 100644 index 00000000..7f45c5c4 --- /dev/null +++ b/template/[% if docs_type == 'sphinx' %]docs[% endif %]/cmake_workflow.md @@ -0,0 +1,24 @@ +# CMake workflow + +CMake common workflow command. + +```bash +# Configure +cmake -S . -B build +# Build +cmake --build build --config Debug +# Testing +cd build && ctest -C Debug -T test --output-on-failure +# Memcheck +cd build && ctest -C Debug -T memcheck +# Install +cmake --build build --config Debug --target install + +# with presets https://cmake.org/cmake/help/latest/manual/cmake-presets.7.html +cmake -S . --list-presets # list all configure presets +cmake -S . --preset= # configure using desired configure preset +cmake --build --list-presets # list all build presets +cmake --build --preset= # build the desired build preset +ctest --list-presets # list all test presets +ctest --preset= # test the desired test preset +```