Skip to content

Commit

Permalink
clean ci (#18)
Browse files Browse the repository at this point in the history
* clean ci

* clean
  • Loading branch information
ysawa0 authored May 12, 2024
1 parent 22291b2 commit 35523cb
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 38 deletions.
6 changes: 4 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
SHFMT_VERSION := v3.8.0

.PHONY: setuppc
setuppc:
@echo "Setting up pre-commit and hooks..."
Expand All @@ -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
Expand Down
39 changes: 8 additions & 31 deletions templates/.github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,14 @@ jobs:
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0

- name: Set up Python
uses: actions/setup-python@v4
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:
Expand All @@ -32,9 +31,8 @@ jobs:
uses: actions/cache@v3
with:
path: /usr/local/bin/shfmt
key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
key: ${{ runner.os }}-shfmt-
restore-keys: |
${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
${{ runner.os }}-shfmt-
- name: Cache Pre-Commit environments
Expand All @@ -48,37 +46,16 @@ jobs:
- name: Install dependencies
run: |
python -m pip install pre-commit
pre-commit install
- name: Install shfmt
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
- name: Run pre-commits
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///')
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" \
"https://api.github.com/repos/$GITHUB_REPOSITORY" | jq -r '.default_branch')
git fetch
CUR_SHA=$(git log --pretty=tformat:"%H" -n1 . | tail -n1)
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
echo "Default branch is $DEFAULT_BRANCH"
echo "Current SHA is $CUR_SHA"
echo "Default branch = $DEFAULT_BRANCH"
echo "Current SHA = ${{ github. sha }}"
if [[ $GITHUB_REF == "refs/heads/$DEFAULT_BRANCH" ]]; then
pre-commit run --all
else
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref $CUR_SHA
fi
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref "${{ github. sha }}"
{%- endraw %}
8 changes: 3 additions & 5 deletions templates/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -112,10 +112,8 @@ repos:
name: prettier
args: [--config, .ci/prettier.json, --write]
types_or:
- css
- scss
- ts
- tsx
- javascript
- tsx
- ts
- yaml
- markdown
66 changes: 66 additions & 0 deletions templates/rust/.pre-commit-config.yaml
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 35523cb

Please sign in to comment.