chore(github-actions): auto update CSV files by GitHub Actions

This commit is contained in:
wood chen 2024-10-27 12:15:47 +08:00
parent 995022af74
commit f2d4d5d2a4
2 changed files with 14 additions and 13 deletions

View File

@ -35,22 +35,23 @@ jobs:
- name: Copy and commit files - name: Copy and commit files
run: | run: |
# 复制文件 # 删除不需要的文件和目录
cp -rv lankong_csv/* target-repo/random-api.czl.net/url/pic/ rm -f public/index.html public/index.md
rm -rf public/css
# 创建目标目录
mkdir -p target-repo/random-api.czl.net/url/pic
# 复制所有CSV文件到pic目录
find public -name "*.csv" -exec cp -v {} target-repo/random-api.czl.net/url/pic/ \;
# 配置 git
cd target-repo cd target-repo
git config --local user.email "github-actions[bot]@users.noreply.github.com" git config --local user.email "github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]" git config --local user.name "github-actions[bot]"
# 设置远程仓库URL使用token认证
git remote set-url origin https://${{ secrets.TARGET_REPO_TOKEN }}@github.com/woodchen-ink/github-file.git git remote set-url origin https://${{ secrets.TARGET_REPO_TOKEN }}@github.com/woodchen-ink/github-file.git
# 添加并提交更改
git add . git add .
# 允许CI [skip ci] git commit -m "Auto update CSV files by GitHub Actions" || echo "No changes to commit"
git commit -m "Github Bot Update CSV files " || echo "No changes to commit"
# 推送更改
git push origin main git push origin main

View File

@ -50,7 +50,7 @@ func main() {
} }
// 创建输出目录 // 创建输出目录
if err := os.MkdirAll("lankong_csv", 0755); err != nil { if err := os.MkdirAll("public", 0755); err != nil {
panic(fmt.Sprintf("Failed to create output directory: %v", err)) panic(fmt.Sprintf("Failed to create output directory: %v", err))
} }
@ -60,13 +60,13 @@ func main() {
urls := fetchAllURLs(albumID, apiToken) urls := fetchAllURLs(albumID, apiToken)
// 确保目录存在 // 确保目录存在
dir := filepath.Dir(filepath.Join("lankong_csv", csvPath)) dir := filepath.Dir(filepath.Join("public", csvPath))
if err := os.MkdirAll(dir, 0755); err != nil { if err := os.MkdirAll(dir, 0755); err != nil {
panic(fmt.Sprintf("Failed to create directory for %s: %v", csvPath, err)) panic(fmt.Sprintf("Failed to create directory for %s: %v", csvPath, err))
} }
// 写入CSV文件 // 写入CSV文件
if err := writeURLsToFile(urls, filepath.Join("lankong_csv", csvPath)); err != nil { if err := writeURLsToFile(urls, filepath.Join("public", csvPath)); err != nil {
panic(fmt.Sprintf("Failed to write URLs to file %s: %v", csvPath, err)) panic(fmt.Sprintf("Failed to write URLs to file %s: %v", csvPath, err))
} }
} }