From 1b8304c5f291989bf9f38927c49ff24eb92bf12b Mon Sep 17 00:00:00 2001 From: Yuki Sawa Date: Sun, 12 May 2024 15:33:33 -0700 Subject: [PATCH] clean ci --- Makefile | 6 ++- templates/.github/workflows/ci.yaml | 30 ++++++------ templates/.pre-commit-config.yaml | 8 ++-- templates/rust/.pre-commit-config.yaml | 66 ++++++++++++++++++++++++++ 4 files changed, 87 insertions(+), 23 deletions(-) create mode 100644 templates/rust/.pre-commit-config.yaml diff --git a/Makefile b/Makefile index 93a8312..586c5d3 100644 --- a/Makefile +++ b/Makefile @@ -1,3 +1,5 @@ +SHFMT_VERSION := v3.8.0 + .PHONY: setuppc setuppc: @echo "Setting up pre-commit and hooks..." @@ -12,9 +14,9 @@ ifeq ($(shell uname),Darwin) brew install shellcheck else @echo "Setting up shfmt (Linux)..." - wget -qO shfmt "https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_$(shell uname -m)" + wget -qO shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/shfmt_${SHFMT_VERSION}_$(shell uname -m)" chmod +x shfmt - sudo mv shfmt /usr/local/bin/shfmt + sudo mv shfmt /usr/local/bin/ @echo "Setting up shellcheck (Linux)..." sudo apt-get install shellcheck || sudo yum install shellcheck || sudo dnf install shellcheck diff --git a/templates/.github/workflows/ci.yaml b/templates/.github/workflows/ci.yaml index dc9ed00..b6db0a8 100644 --- a/templates/.github/workflows/ci.yaml +++ b/templates/.github/workflows/ci.yaml @@ -17,9 +17,6 @@ jobs: with: python-version: "3.10" - - name: Set shfmt version environment variable - run: echo "SHFMT_VERSION=v3.7.0" >> $GITHUB_ENV - - name: Cache pip dependencies uses: actions/cache@v3 with: @@ -46,22 +43,23 @@ jobs: ${{ runner.os }}-pc-${{ hashFiles('.pre-commit-config.yaml') }} ${{ runner.os }}-pc- - - name: Install dependencies - run: | - python -m pip install pre-commit - pre-commit install + # - name: Install dependencies + # run: | + # python -m pip install pre-commit + # pre-commit install - - name: Install shfmt + - name: Install dependencies run: | - SHFMT_VERSION=${{ env.SHFMT_VERSION }} - SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64" - if [[ ! -f /usr/local/bin/shfmt ]]; then - wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}" - chmod +x shfmt - sudo mv shfmt /usr/local/bin/ - fi - sudo apt-get install shellcheck + make setuppc + # SHFMT_VERSION=${{ env.SHFMT_VERSION }} + # SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64" + # if [[ ! -f /usr/local/bin/shfmt ]]; then + # wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}" + # chmod +x shfmt + # sudo mv shfmt /usr/local/bin/ + # fi + # sudo apt-get install shellcheck - name: Run pre-commits env: GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/templates/.pre-commit-config.yaml b/templates/.pre-commit-config.yaml index 65e50c3..0ecb0c9 100644 --- a/templates/.pre-commit-config.yaml +++ b/templates/.pre-commit-config.yaml @@ -103,7 +103,7 @@ repos: - id: clippy # Lints Rust code with clippy for common mistakes and style issues {%+ endif %} ############################################################################# - # CSS, Markdown, JavaScript, TypeScript, YAML style formatter + # Markdown, JavaScript, TypeScript, YAML style formatter ############################################################################# - repo: https://github.com/pre-commit/mirrors-prettier rev: v3.0.3 @@ -112,10 +112,8 @@ repos: name: prettier args: [--config, .ci/prettier.json, --write] types_or: - - css - - scss - - ts - - tsx - javascript + - tsx + - ts - yaml - markdown diff --git a/templates/rust/.pre-commit-config.yaml b/templates/rust/.pre-commit-config.yaml new file mode 100644 index 0000000..1fcc57b --- /dev/null +++ b/templates/rust/.pre-commit-config.yaml @@ -0,0 +1,66 @@ +default_language_version: + python: python3 + +repos: + ############################################################################# + # Misc + ############################################################################# + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict # Searches for merge conflict markers within files. + - id: check-added-large-files # Blocks commits that add large files. Default limit is 500kB. + # Can be configured with args, e.g., '--maxkb=1000' to change the limit. + # exclude: 'your_dir/.*' + # args: ['--maxkb=5000'] + - id: check-case-conflict # Identifies potential case-insensitive file name conflicts. + - id: check-ast # Validates the syntax of Python files. + - id: check-symlinks # Detects broken symlinks. + - id: trailing-whitespace # Removes any trailing whitespace at the end of lines. + - id: end-of-file-fixer # Ensures files end with a single newline or are empty. + + ############################################################################# + # JSON, TOML + ############################################################################# + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-json # Validates JSON files to ensure they are properly formatted and syntactically correct. + types: [json] + - id: check-toml # Checks TOML files for errors and format issues to ensure valid syntax. + types: [toml] + + ############################################################################# + # Shell + ############################################################################# + - repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shfmt # Formats shell scripts to a standard convention using shfmt. + - id: shellcheck # Lints shell scripts to identify syntax and usage errors, with a specified severity of 'warning'. + args: + - --severity=warning + ############################################################################# + # Rust + ############################################################################# + - repo: https://github.com/doublify/pre-commit-rust + rev: v1.0 + hooks: + - id: fmt # Formats Rust code using rustfmt + - id: cargo-check # Checks Rust code for compilation errors and warnings + - id: clippy # Lints Rust code with clippy for common mistakes and style issues + ############################################################################# + # Markdown, JavaScript, TypeScript, YAML style formatter + ############################################################################# + - repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.3 + hooks: + - id: prettier # An opinionated code formatter supporting multiple languages. + name: prettier + args: [--config, .ci/prettier.json, --write] + types_or: + - javascript + - tsx + - ts + - yaml + - markdown