Skip to content

Commit 35523cb

Browse files
authored
clean ci (#18)
* clean ci * clean
1 parent 22291b2 commit 35523cb

4 files changed

Lines changed: 81 additions & 38 deletions

File tree

Makefile

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
SHFMT_VERSION := v3.8.0
2+
13
.PHONY: setuppc
24
setuppc:
35
@echo "Setting up pre-commit and hooks..."
@@ -12,9 +14,9 @@ ifeq ($(shell uname),Darwin)
1214
brew install shellcheck
1315
else
1416
@echo "Setting up shfmt (Linux)..."
15-
wget -qO shfmt "https://github.com/mvdan/sh/releases/download/v3.7.0/shfmt_v3.7.0_$(shell uname -m)"
17+
wget -qO shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/shfmt_${SHFMT_VERSION}_$(shell uname -m)"
1618
chmod +x shfmt
17-
sudo mv shfmt /usr/local/bin/shfmt
19+
sudo mv shfmt /usr/local/bin/
1820

1921
@echo "Setting up shellcheck (Linux)..."
2022
sudo apt-get install shellcheck || sudo yum install shellcheck || sudo dnf install shellcheck

templates/.github/workflows/ci.yaml

Lines changed: 8 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,14 @@ jobs:
1111
steps:
1212
- name: Checkout code
1313
uses: actions/checkout@v4
14+
with:
15+
fetch-depth: 0
1416

1517
- name: Set up Python
1618
uses: actions/setup-python@v4
1719
with:
1820
python-version: "3.10"
1921

20-
- name: Set shfmt version environment variable
21-
run: echo "SHFMT_VERSION=v3.7.0" >> $GITHUB_ENV
22-
2322
- name: Cache pip dependencies
2423
uses: actions/cache@v3
2524
with:
@@ -32,9 +31,8 @@ jobs:
3231
uses: actions/cache@v3
3332
with:
3433
path: /usr/local/bin/shfmt
35-
key: ${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
34+
key: ${{ runner.os }}-shfmt-
3635
restore-keys: |
37-
${{ runner.os }}-shfmt-${{ env.SHFMT_VERSION }}
3836
${{ runner.os }}-shfmt-
3937
4038
- name: Cache Pre-Commit environments
@@ -48,37 +46,16 @@ jobs:
4846
4947
- name: Install dependencies
5048
run: |
51-
python -m pip install pre-commit
52-
pre-commit install
53-
54-
- name: Install shfmt
55-
run: |
56-
SHFMT_VERSION=${{ env.SHFMT_VERSION }}
57-
SHFMT_BIN="shfmt_${SHFMT_VERSION}_linux_amd64"
58-
if [[ ! -f /usr/local/bin/shfmt ]]; then
59-
wget -O shfmt "https://github.com/mvdan/sh/releases/download/${SHFMT_VERSION}/${SHFMT_BIN}"
60-
chmod +x shfmt
61-
sudo mv shfmt /usr/local/bin/
62-
fi
63-
sudo apt-get install shellcheck
49+
make setuppc
6450
6551
- name: Run pre-commits
6652
env:
6753
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
6854
run: |
69-
REPO_NAME=$(echo $GITHUB_REPOSITORY | sed 's/^.*\///')
70-
DEFAULT_BRANCH=$(curl -H "Authorization: token $GITHUB_TOKEN" \
71-
"https://api.github.com/repos/$GITHUB_REPOSITORY" | jq -r '.default_branch')
72-
73-
git fetch
74-
CUR_SHA=$(git log --pretty=tformat:"%H" -n1 . | tail -n1)
55+
DEFAULT_BRANCH=$(git symbolic-ref refs/remotes/origin/HEAD | sed 's@^refs/remotes/origin/@@')
7556
76-
echo "Default branch is $DEFAULT_BRANCH"
77-
echo "Current SHA is $CUR_SHA"
57+
echo "Default branch = $DEFAULT_BRANCH"
58+
echo "Current SHA = ${{ github. sha }}"
7859
79-
if [[ $GITHUB_REF == "refs/heads/$DEFAULT_BRANCH" ]]; then
80-
pre-commit run --all
81-
else
82-
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref $CUR_SHA
83-
fi
60+
pre-commit run --from-ref origin/$DEFAULT_BRANCH --to-ref "${{ github. sha }}"
8461
{%- endraw %}

templates/.pre-commit-config.yaml

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ repos:
103103
- id: clippy # Lints Rust code with clippy for common mistakes and style issues
104104
{%+ endif %}
105105
#############################################################################
106-
# CSS, Markdown, JavaScript, TypeScript, YAML style formatter
106+
# Markdown, JavaScript, TypeScript, YAML style formatter
107107
#############################################################################
108108
- repo: https://github.com/pre-commit/mirrors-prettier
109109
rev: v3.0.3
@@ -112,10 +112,8 @@ repos:
112112
name: prettier
113113
args: [--config, .ci/prettier.json, --write]
114114
types_or:
115-
- css
116-
- scss
117-
- ts
118-
- tsx
119115
- javascript
116+
- tsx
117+
- ts
120118
- yaml
121119
- markdown
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
default_language_version:
2+
python: python3
3+
4+
repos:
5+
#############################################################################
6+
# Misc
7+
#############################################################################
8+
- repo: https://github.com/pre-commit/pre-commit-hooks
9+
rev: v4.5.0
10+
hooks:
11+
- id: check-merge-conflict # Searches for merge conflict markers within files.
12+
- id: check-added-large-files # Blocks commits that add large files. Default limit is 500kB.
13+
# Can be configured with args, e.g., '--maxkb=1000' to change the limit.
14+
# exclude: 'your_dir/.*'
15+
# args: ['--maxkb=5000']
16+
- id: check-case-conflict # Identifies potential case-insensitive file name conflicts.
17+
- id: check-ast # Validates the syntax of Python files.
18+
- id: check-symlinks # Detects broken symlinks.
19+
- id: trailing-whitespace # Removes any trailing whitespace at the end of lines.
20+
- id: end-of-file-fixer # Ensures files end with a single newline or are empty.
21+
22+
#############################################################################
23+
# JSON, TOML
24+
#############################################################################
25+
- repo: https://github.com/pre-commit/pre-commit-hooks
26+
rev: v4.5.0
27+
hooks:
28+
- id: check-json # Validates JSON files to ensure they are properly formatted and syntactically correct.
29+
types: [json]
30+
- id: check-toml # Checks TOML files for errors and format issues to ensure valid syntax.
31+
types: [toml]
32+
33+
#############################################################################
34+
# Shell
35+
#############################################################################
36+
- repo: https://github.com/jumanjihouse/pre-commit-hooks
37+
rev: 3.0.0
38+
hooks:
39+
- id: shfmt # Formats shell scripts to a standard convention using shfmt.
40+
- id: shellcheck # Lints shell scripts to identify syntax and usage errors, with a specified severity of 'warning'.
41+
args:
42+
- --severity=warning
43+
#############################################################################
44+
# Rust
45+
#############################################################################
46+
- repo: https://github.com/doublify/pre-commit-rust
47+
rev: v1.0
48+
hooks:
49+
- id: fmt # Formats Rust code using rustfmt
50+
- id: cargo-check # Checks Rust code for compilation errors and warnings
51+
- id: clippy # Lints Rust code with clippy for common mistakes and style issues
52+
#############################################################################
53+
# Markdown, JavaScript, TypeScript, YAML style formatter
54+
#############################################################################
55+
- repo: https://github.com/pre-commit/mirrors-prettier
56+
rev: v3.0.3
57+
hooks:
58+
- id: prettier # An opinionated code formatter supporting multiple languages.
59+
name: prettier
60+
args: [--config, .ci/prettier.json, --write]
61+
types_or:
62+
- javascript
63+
- tsx
64+
- ts
65+
- yaml
66+
- markdown

0 commit comments

Comments
 (0)