forked from hplush/slowreader
-
Notifications
You must be signed in to change notification settings - Fork 0
62 lines (62 loc) · 1.97 KB
/
format.yml
File metadata and controls
62 lines (62 loc) · 1.97 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
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