github命令行玩法
Table of Contents
git本身可以管理仓库的各种数据和信息,但git的托管平台比如github之类有一些信息并不在仓库中管理,比如项目的description和issue之类的。我个人更喜欢用命令行将这些数据拉到本地存储或修改。
首先登录和切换账号
gh auth login gh auth switch
获取自己所有的项目并生成表格
ghpsum 我自己写的一个对GitHub用户生成所有项目和描述的摘要文件的工具,可以通过下面命令使用生成csv、json、html等多种类型的文件。
python ghpsum.py --username GZJ --output-format csv python ghpsum.py --username GZJ --output-format json python ghpsum.py --username GZJ --output-format html
description
查询项目的description
gh repo view gzj/zemp --json description --jq .description
修改description
gh repo edit gzj/zemp --description "New description"
列出所有项目的issues
gh issue list
构建自己的runner
创建token
gh api \ --method POST \ -H "Accept: application/vnd.github+json" \ -H "X-GitHub-Api-Version: 2022-11-28" \ /repos/OWNER/REPO/actions/runners/registration-token
下载配置运行runner
windows pwsh
mkdir actions-runner ; cd actions-runner Invoke-WebRequest -Uri https://github.com/actions/runner/releases/download/v2.321.0/actions-runner-win-x64-2.321.0.zip -OutFile actions-runner-win-x64-2.321.0.zip Add-Type -AssemblyName System.IO.Compression.FileSystem ; [System.IO.Compression.ZipFile]::ExtractToDirectory("$PWD\actions-runner-win-x64-2.321.0.zip", "$PWD")
linux bash
mkdir actions-runner && cd actions-runner curl -O -L https://github.com/actions/runner/releases/download/v2.321.0/actions-runner-linux-x64-2.321.0.tar.gz tar xzf ./actions-runner-linux-x64-2.321.0.tar.gz
下载的脚本在windows下叫config.cmd,在linux下叫config.sh。
./config.cmd --url https://github.com/your-organization/your-repository --token YOUR_REGISTRATION_TOKEN --unattended --replace --labels self-hosted
然后启动run.cmd 或者run.sh
.github/workflows目录中创建yml文件
name: CI on: push: branches: [ main ] jobs: build: runs-on: self-hosted steps: - uses: actions/checkout@v3 - name: Run a single command using the runner's shell run: echo Hello, world!
运行
当你向 main 分支推送代码时,GitHub 会触发yml中的run工作流。运行命令 echo Hello, world! 命令,并输出 "Hello, world!"。
你后续可以后续根据官方文档进行更多的私人设置,这样就可以在私人的机器中设置对github 仓库的push事件的响应,在本地跑一些测试用例。