Skip to content

Commit 214932f

Browse files
authored
Merge pull request #11 from LuaanNguyen/workflows
New Workflows
2 parents f2c51d4 + 6d47538 commit 214932f

File tree

3 files changed

+134
-31
lines changed

3 files changed

+134
-31
lines changed

.github/workflows/go.yml

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,39 @@ name: Go
55

66
on:
77
push:
8-
branches: [ "main" ]
8+
branches: ["main"]
99
pull_request:
10-
branches: [ "main" ]
10+
branches: ["main"]
1111

1212
jobs:
13-
14-
build:
13+
test:
1514
runs-on: ubuntu-latest
1615
steps:
17-
- uses: actions/checkout@v4
16+
- uses: actions/checkout@v4
17+
18+
- name: Set up Go
19+
uses: actions/setup-go@v4
20+
with:
21+
go-version: "1.21"
22+
23+
- name: Verify dependencies
24+
run: go mod verify
25+
26+
- name: Run go fmt
27+
run: |
28+
if [ -n "$(go fmt ./...)" ]; then
29+
echo "Please run go fmt on your code"
30+
exit 1
31+
fi
32+
33+
- name: Run tests
34+
run: go test -v ./...
1835

19-
- name: Set up Go
20-
uses: actions/setup-go@v4
21-
with:
22-
go-version: '1.20'
36+
- name: Run vet
37+
run: go vet ./...
2338

24-
- name: Build
25-
run: go build -v ./...
39+
- name: Install staticcheck
40+
run: go install honnef.co/go/tools/cmd/staticcheck@latest
2641

27-
- name: Test
28-
run: go test -v ./...
42+
- name: Run staticcheck
43+
run: staticcheck ./...

.github/workflows/update-stats.yml

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
name: Update Repository Statistics
2+
3+
on:
4+
push:
5+
branches: ["main"]
6+
paths:
7+
- "easy/**"
8+
- "medium/**"
9+
- "hard/**"
10+
11+
jobs:
12+
update-stats:
13+
runs-on: ubuntu-latest
14+
permissions:
15+
contents: write
16+
steps:
17+
- uses: actions/checkout@v4
18+
19+
- name: Set up Python
20+
uses: actions/setup-python@v4
21+
with:
22+
python-version: "3.x"
23+
24+
- name: Update Statistics
25+
run: |
26+
python3 - <<EOF
27+
import os
28+
from collections import Counter
29+
30+
def count_solutions():
31+
counts = Counter()
32+
for difficulty in ['easy', 'medium', 'hard']:
33+
if os.path.exists(difficulty):
34+
counts[difficulty] = len([name for name in os.listdir(difficulty) if os.path.isdir(os.path.join(difficulty, name))])
35+
return counts
36+
37+
def update_readme(counts):
38+
with open('README.md', 'r') as f:
39+
content = f.read()
40+
41+
# Add statistics section if it doesn't exist
42+
stats_section = f"""
43+
## Statistics 📊
44+
45+
- Easy: {counts['easy']} solutions
46+
- Medium: {counts['medium']} solutions
47+
- Hard: {counts['hard']} solutions
48+
- Total: {sum(counts.values())} solutions
49+
"""
50+
51+
if '## Statistics' in content:
52+
# Replace existing statistics section
53+
import re
54+
content = re.sub(r'## Statistics.*?(?=##|$)', stats_section, content, flags=re.DOTALL)
55+
else:
56+
# Add statistics section before License
57+
content = content.replace('## License', stats_section + '\n## License')
58+
59+
with open('README.md', 'w') as f:
60+
f.write(content)
61+
62+
counts = count_solutions()
63+
update_readme(counts)
64+
EOF
65+
66+
- name: Commit changes
67+
run: |
68+
git config --local user.email "action@github.com"
69+
git config --local user.name "GitHub Action"
70+
git add README.md
71+
git diff --quiet && git diff --staged --quiet || git commit -m "Update repository statistics"
72+
git push

0 commit comments

Comments
 (0)