GitHub 推送自动化
入口脚本 scripts/push-github.ps1(与本 SKILL.md 同目录)。决策树由脚本自动完成,不要自行搜索环境:
-Action check一条命令报告 git/gh/token 状态与预计分支;- 有 git → 本地 init/commit/远程 push(凭证不足时自动转设备码);
- 无 git → GitHub REST API 建仓 + base64 上传文件;
- 无 token → 设备码授权:脚本输出形如
ABCD-1234的验证码和https://github.com/login/device,用户浏览器输入授权,脚本轮询拿到 token 自动继续。
用法(pwsh 工具;每个新进程先执行第一句)
$s = '<本 skill 目录>\scripts\push-github.ps1' # 已设 DSH_HOME 时也可:Join-Path $env:DSH_HOME 'skills\github-push\scripts\push-github.ps1'
Set-ExecutionPolicy -Scope Process Bypass -Force
& $s -Action check
& $s -Action push -Path 'G:\项目目录' -Repo 'repo-name' -Visibility public # 推整个目录
& $s -Action push -Path '单个文件.txt' -Repo 'repo-name' # 推单个文件
& $s -Action release -Path 'G:\项目目录' -Repo 'repo-name' -Tag 'v1.0.0' -Body '变更说明' # 打 zip 发 Release
- 设备码流程会阻塞最长 15 分钟:需要授权时用
run_in_background跑推送,把脚本输出的验证码和网址立即告诉用户;用户授权后脚本自动继续,不必干预。 - token 优先级:
-TokenFile参数 →$env:GH_PAT→ 工作目录.github-token.txt→%USERPROFILE%\.github-token.txt。设备码成功后自动存到%USERPROFILE%\.github-token.txt,下次直接复用。 -Owner可省略:脚本用 token 调GET /user自动识别账号;推他人/组织仓库时显式传-Owner。-Action release:把-Path目录打成<Repo>-<Tag>.zip,创建 Release(tag 取自 main)并上传 zip 资产;tag 已存在会 422,需换新版本号。- 改过 push-github.ps1 后若报乱码解析错误:脚本必须带 UTF-8 BOM。补 BOM:
$p=$s; $c=[IO.File]::ReadAllText($p,[Text.UTF8Encoding]::new($false)); [IO.File]::WriteAllText($p,$c,[Text.UTF8Encoding]::new($true)) - 排障细节:
references/troubleshooting.md(设备码机制、PAT 创建、常见错误码)。