HamidMolareza / QueraLens

A static site generator showcasing organized solutions to Quera problems with clarity and insights.
https://hamidmolareza.github.io/Quera
GNU General Public License v3.0
0 stars 0 forks source link

ci(scripts): add powershell script for git hook #15

Closed ARiYaNSEp0-0 closed 5 days ago

ARiYaNSEp0-0 commented 6 days ago

this powershell script do following tasks:

closes #13

Pull Request type

Please check the type of change your PR introduces:

What is the current behavior?

Issue Number: N/A

What is the new behavior?

-

-

Does this introduce a breaking change?

Checklist

Other information

HamidMolareza commented 6 days ago

Did you test this on Windows? Was everything working correctly?

HamidMolareza commented 6 days ago

I create the below GitHub action and test it:

name: Test Setup-Hooks Script

on:
  workflow_dispatch:

jobs:
  test-script:
    runs-on: windows-latest

    steps:
      # Checkout repository
      - name: Checkout code
        uses: actions/checkout@v4

      # Install pre-commit
      - name: Install pre-commit
        run: |
          pip install pre-commit
          pre-commit --version

      # Install Node.js (for npm)
      - name: Setup Node.js
        uses: actions/setup-node@v4
        with:
          node-version: 18
      - run: npm --version

      # Ensure Git is installed
      - name: Check Git version
        run: git --version

      # Run the setup-hooks script
      - name: Execute setup-hooks script
        run: |
          pwsh ./scripts/setup-hooks.ps1

      - name: Invalid Commit
        run: |
          echo "sample content" > file.txt
          git add .
          git commit -m "Initial commit"

I got the output below, so everything seems fine.

Starting setup-hooks script...
Installing 'commit-msg' pre-commit hook...
pre-commit installed at .git\hooks\commit-msg
Installing 'prepare-commit-msg' pre-commit hook...
pre-commit installed at .git\hooks\prepare-commit-msg
Installing 'pre-merge-commit' pre-commit hook...
pre-commit installed at .git\hooks\pre-merge-commit
Installing 'pre-push' pre-commit hook...
pre-commit installed at .git\hooks\pre-push
Enabling 'pre-rebase' hook...
Template hook copied to D:\a\test-powershell\test-powershell\.git\hooks\pre-rebase.
Installing npm dependencies...

added 101 packages, and audited 102 packages in 7s

19 packages are looking for funding
  run `npm fund` for details

found 0 vulnerabilities
Setup-hooks script completed successfully.
don't commit to branch...................................................Failed
- hook id: no-commit-to-branch
- exit code: 1

Error: Process completed with exit code 1.
ARiYaNSEp0-0 commented 6 days ago

Did you test this on Windows? Was everything working correctly?

The only problem was package.json installing. I put this powershell script inside scripts folder and it didn't find outer package.json to install it so I did it manually with npm install on root

HamidMolareza commented 5 days ago

Yes, this is designed to execute from the root, but it would be better to enhance this aspect.

HamidMolareza commented 5 days ago

Please check new codes.

ARiYaNSEp0-0 commented 5 days ago

I removed the package-lock.json and also node_modules from root and I ran the setup-hooks.ps1 script from scripts folder and It worked properly. thanks