Skip to content

Commit

Permalink
ci: commitlint entirely through nix
Browse files Browse the repository at this point in the history
  • Loading branch information
richen604 committed Nov 16, 2024
1 parent e474d3f commit 5309ede
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 833 deletions.
31 changes: 26 additions & 5 deletions .commitlintrc.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,29 @@
module.exports = {
extends: ["@commitlint/config-conventional"],
rules: {
"scope-case": [2, "always", "lower-case"],
"subject-case": [2, "always", "lower-case"],
"scope-empty": [0, "never"],
},
'scope-case': [2, 'always', 'lower-case'],
'subject-case': [2, 'always', 'lower-case'],
'scope-empty': [0, 'never'],
'type-enum': [
2,
'always',
[
'build',
'chore',
'ci',
'docs',
'feat',
'fix',
'perf',
'refactor',
'revert',
'style',
'test'
]
],
'type-case': [2, 'always', 'lower-case'],
'type-empty': [2, 'never'],
'subject-empty': [2, 'never'],
'subject-full-stop': [2, 'never', '.'],
'header-max-length': [2, 'always', 72]
}
};
3 changes: 0 additions & 3 deletions .envrc
Original file line number Diff line number Diff line change
@@ -1,4 +1 @@
watch_file flake.nix
watch_file flake.lock

use flake
10 changes: 3 additions & 7 deletions .github/workflows/commit-lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,12 @@ jobs:
with:
fetch-depth: 0

- uses: actions/setup-node@v4
- uses: cachix/install-nix-action@v24
with:
node-version: "20"

- name: Install commitlint
run: |
npm install --global @commitlint/cli @commitlint/config-conventional
nix_path: nixpkgs=channel:nixos-unstable

- name: Copy commitlint config
run: cp .commitlintrc.js $HOME/.commitlintrc.js

- name: Validate PR commits
run: npx commitlint --config $HOME/.commitlintrc.js --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose
run: nix-shell -p commitlint --run "commitlint --from ${{ github.event.pull_request.base.sha }} --to ${{ github.event.pull_request.head.sha }} --verbose"
3 changes: 1 addition & 2 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,5 @@ result
*.log
*.tmp
output-*
.husky
.direnv
node_modules
.git-hooks
24 changes: 13 additions & 11 deletions lib/dev-shell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,26 @@ pkgs.mkShell {
buildInputs = with pkgs; [
nodejs
commitlint
pnpm
direnv
nix-direnv
];

shellHook = ''
export USE_DIRENV=1
# Install dependencies and setup husky if needed
if [ ! -d "node_modules" ]; then
pnpm install
pnpm prepare
fi
# Set up git hooks directory
git config core.hooksPath .git-hooks
# Set up commit-msg hook if it doesn't exist
mkdir -p .husky
echo '#!/usr/bin/env sh
pnpm dlx commitlint --edit "$1"' > .husky/commit-msg
chmod +x .husky/commit-msg
# Ensure .git-hooks directory exists
mkdir -p .git-hooks
# Create commit-msg hook
cat > .git-hooks/commit-msg <<'EOF'
#!/usr/bin/env sh
${pkgs.commitlint}/bin/commitlint --edit "$1"
EOF
# Make hook executable
chmod +x .git-hooks/commit-msg
'';
}
12 changes: 2 additions & 10 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,4 @@
{
"name": "hydenix",
"private": true,
"scripts": {
"prepare": "pnpm dlx husky"
},
"devDependencies": {
"@commitlint/cli": "^19.5.0",
"@commitlint/config-conventional": "^19.5.0",
"husky": "^9.0.0"
}
}
"private": true
}
Loading

0 comments on commit 5309ede

Please sign in to comment.