Repository navigation
65 lines (54 loc) · 2.24 KB
/
Copy pathupdate-gitignore.yml
File metadata and controls
65 lines (54 loc) · 2.24 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
63
64
65
name: Update Combined gitignore
on:
schedule:
- cron: '0 0 * * 1' # 每周一凌晨 0:00 自动运行
workflow_dispatch: # 允许手动触发
jobs:
build:
runs-on: ubuntu-latest
permissions:
contents: write # 赋予推送权限
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Download and Combine gitignore files
run: |
# 定义目标文件
TARGET_FILE=".gitignore"
# 清空旧内容并添加头部注释
echo "# Combined gitignore generated by GitHub Action" > $TARGET_FILE
echo "# Last updated: $(date)" >> $TARGET_FILE
# 定义 URL 列表 (使用 raw 链接以便直接下载文本)
URLS=(
"https://raw.githubusercontent.com/github/gitignore/main/Python.gitignore"
"https://raw.githubusercontent.com/github/gitignore/main/Go.gitignore"
"https://raw.githubusercontent.com/github/gitignore/main/Global/Windows.gitignore"
"https://raw.githubusercontent.com/github/gitignore/main/Node.gitignore"
)
for url in "${URLS[@]}"; do
echo -e "\n\n# --- Source: $url ---" >> $TARGET_FILE
curl -sL "$url" >> $TARGET_FILE
done
- name: Enable IDE ignore rules
shell: bash
run: |
# Upstream Python and Go templates comment out these IDE directories.
sed -i -E 's/^[[:space:]]*#[[:space:]]*(\.idea\/|\.vscode\/)[[:space:]]*$/\1/' .gitignore
for entry in '.idea/' '.vscode/'; do
if ! grep -Fqx "$entry" .gitignore; then
echo "::error::Missing expected IDE ignore rule: $entry"
exit 1
fi
done
- name: Commit and Push changes
run: |
git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
# 检查是否有文件更改
if [ -n "$(git status --porcelain)" ]; then
git add .gitignore
git commit -m "chore: auto-update combined .gitignore [skip ci]"
git push
else
echo "No changes detected in .gitignore"
fi