自定义 action 让其他项目使用
/ 3 min read
自定义 action 让其他项目使用
背景
近期使用 issues
写 blog
,突发奇想能不能将 issues blog
生成概览信息同步到项目的README.md
中,再加上刚学了Rust
,就准备来实现这个action
,这里主要流程就是使用github api
获取项目issues
,再将issues
生成概览信息,action 项目 关于代码实现比较简单,主要是记录怎么才能让其他项目使用。
配置 action.yml
action项目
需要在根目录下建立一个action.yml
,并且这个项目需要是使用者能访问。
name: 'blog-archive'description: 'issues blog sync README.md Summary'branding: icon: 'activity' color: 'white'
inputs: api-github-token: description: 'github api token' required: true default: ''
repo: description: 'sync github issues repo name' required: true default: ''
owner: description: 'sync github issues repo owner' required: true default: ''
git-user-name: description: 'update user name' required: true default: ''
git-user-email: description: 'update user email' required: true default: ''
runs: using: "composite"
steps: - run: echo "${{ github.action_path }}" >> $GITHUB_PATH shell: bash - name: Set up Rust uses: actions-rs/toolchain@v1 with: toolchain: stable - name: Run blog-archive run: | cd ${{ github.action_path }} cargo run -- ${{ inputs.api-github-token }} ${{ inputs.owner }} ${{ inputs.repo }} ls pwd shell: bash - name: Checkout code uses: actions/checkout@v2 - name: sync README.md shell: bash run: | pwd ls cat ${{ github.action_path }}/output.txt cat ${{ github.action_path }}/output.txt > README.md git config user.name ${{ inputs.git-user-name }} git config user.email ${{ inputs.git-user-email }} git add README.md git commit -m "Update README.md with issues blog" git push
- 使用其他人的action原理就是把其他的action项目获取到自己项目工作流空间中执行
${{ github.action_path }}
是action项目路径,确定执行文件路径是否正确- 其他项目使用只需要引入
owner/repo@tag or branch
,owner 是用户,repo 是仓库名,@后面可以版本号,也可以是分支,例如刚刚创建的action项目就是zhang-cn/blog-archive@main
,在其他项目中action引入使用就可以。