Fix code style #304
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Fix code style | |
| on: | |
| push: | |
| branches: | |
| - main | |
| paths: | |
| - '.github/workflows/format.yml' | |
| - '.github/actions/init-node/action.yml' | |
| pull_request: | |
| paths: | |
| - '.github/workflows/format.yml' | |
| - '.github/actions/init-node/action.yml' | |
| schedule: | |
| - cron: '00 04 * * *' # Runs at midnight UTC every day | |
| permissions: | |
| contents: write | |
| jobs: | |
| format: | |
| name: Format | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Harden the runner | |
| uses: step-security/harden-runner@20cf305ff2072d973412fa9b1e3a4f227bda3c76 # v2.14.0 | |
| with: | |
| egress-policy: block | |
| allowed-endpoints: > | |
| api.github.com:443 | |
| github.com:443 | |
| nodejs.org:443 | |
| release-assets.githubusercontent.com:443 | |
| objects.githubusercontent.com:443 | |
| registry.npmjs.org:443 | |
| - name: Checkout the repository | |
| uses: actions/checkout@8e8c483db84b4bee98b60c0593521ed34d9990e8 # v6.0.1 | |
| - name: Initialize Node.js | |
| uses: ./.github/actions/init-node | |
| - name: Check for today commits | |
| id: today | |
| run: | | |
| today=$(date -u +"%Y-%m-%d") | |
| last_commit_date=$(git log -1 --format=%cd --date=short) | |
| if [ "$today" == "$last_commit_date" ]; then | |
| echo "has_commits=true" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "has_commits=false" >> "$GITHUB_OUTPUT" | |
| echo "No commits today. Stopping the workflow." | |
| fi | |
| - name: Format code | |
| if: steps.today.outputs.has_commits == 'true' | |
| run: node --run format | |
| - name: Commit changes | |
| if: steps.today.outputs.has_commits == 'true' | |
| run: | | |
| git config --local user.email "action@github.com" | |
| git config --local user.name "GitHub Action" | |
| git add . | |
| if [ -n "$(git status --porcelain)" ]; then | |
| git commit -m "Auto-format code" | |
| git push | |
| else | |
| echo "No changes to commit" | |
| fi |