Skip to content

Instantly share code, notes, and snippets.

@sanbei011
Created April 3, 2024 06:13
Show Gist options
  • Save sanbei011/c8145ebb51fa187316a62aff00fda19a to your computer and use it in GitHub Desktop.
Save sanbei011/c8145ebb51fa187316a62aff00fda19a to your computer and use it in GitHub Desktop.
上传zip自动解压到github仓库
name: extract a zip file # 工作流程的名称
on:
push: # 当有代码推送时触发
paths: # 触发条件:指定的文件路径
- '**/*.zip' # 当任何文件夹下的 .zip 文件发生变化时触发
workflow_dispatch: # 允许手动触发工作流程
jobs:
unzip-and-organize: # 工作流程中的任务名为 unzip-and-organize
runs-on: ubuntu-latest # 在 Ubuntu 最新版本上运行
permissions:
contents: write # 允许任务对文件进行写操作
steps: # 任务中的步骤列表
- uses: actions/checkout@v4 # 使用 GitHub 提供的官方 Action,将代码仓库的内容检出到工作目录
- name: Extract to same-named directory and delete ZIP # 步骤名称:提取到同名目录并删除 ZIP 文件
run: | # 执行以下 shell 命令
for zipfile in *.zip; do # 遍历所有的 .zip 文件
# 获取不含 .zip 扩展名的基本文件名
filename=$(basename "$zipfile" .zip)
# 如果同名文件夹不存在,则创建
mkdir -p "$filename"
# 解压内容到同名文件夹中
unzip -o "$zipfile" -d "$filename"
# 删除 ZIP 文件
rm "$zipfile"
done
# 配置 Git 用户
git config --local user.email "github-actions@users.noreply.github.com"
git config --local user.name "github-actions"
# 将所有更改添加到 Git,提交并推送
git add .
git commit -m "Extract ZIP files to same-named directories"
git push
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment