Overview
项目 在 GitHub Actions 的仓库中自动化、自定义和执行【测试、打包、发布】等软件开发工作流程。
Billing
- 公共仓库和自托管运行器,免费使用 GitHub Actions。
- 私有仓库,Github Free 每月可免费使用 2000分钟Linux 或 1000分钟Windows 或 200分钟macOS。
Workfile
GitHub Actions 的工作流程语法,使用 YAML 语法,放入 .github/workflows。
name
可选,工作流名称。
on
触发工作流程的事件, 常用有 <push
|pull_request
>。
jobs
作业 group,默认并行执行。
runs-on
GitHub 托管的运行器, iOS 项目使用 macos-latest。
steps
任务 group
Testing
以iOS 项目为例, 构建测试,需执行 swiftlint
, pod lib lint
, xcodebuild test
. xchelper 可以提供便捷的命令.
添加 .ios_test.yml文件
mkdir -p .github/workflows
vi .github/workflows/iOS-test.yml
复制代码
name: iOS testing
on:
push:
branches: [ master ]
pull_request:
branches: [ master ]
jobs:
build:
name: Build and Test default scheme using any available iPhone simulator
runs-on: macos-latest
steps:
- uses: actions/checkout@v2
- name: setup
run: |
sh -c "$(curl -fsSL https://raw.githubusercontent.com/BlueIntent/xchelper/main/scripts/install.sh)"
- name: lint
run: |
xchelper swiftlint
xchelper pod-lib-lint
- name: xcodebuild-test
run: |
xchelper install
xchelper test
复制代码
提交后,可查看 GitHub Actions 进度。
添加工作流程状态徽章
github badge
https://github.com/<OWNER>/<REPOSITORY>/actions/workflows/<WORKFLOW_FILE>/badge.svg
复制代码
比如
shields badge
https://img.shields.io/github/workflow/status/:user/:repo/:workflow
复制代码
比如
备注:shields 里的 workflow,不是 wokrflow 文件名,而是 workflow flie 配置里的 name
Examples
- 可于 QiuZhiFei/ci-examples 直接编辑, 提 PR 测试 ci.
Automate Task
获取 github owner/repo
git config --get remote.origin.url | sed -e 's/\(https:\/\/github.com\/\)//g' | sed -e 's/\(git@github.com:\)//g' | sed -e 's/\.git//g' | awk {'print $0'}
复制代码
获取 github actions url
git config --get remote.origin.url | sed -e 's/\(https:\/\/github.com\/\)//g' | sed -e 's/\(git@github.com:\)//g' | sed -e 's/\.git//g' | awk {'print "https://github.com/" $0 "/actions"'}
复制代码
查看所有 actions runs
owner_repo=`git config --get remote.origin.url | sed -e 's/\(https:\/\/github.com\/\)//g' | sed -e 's/\(git@github.com:\)//g' | sed -e 's/\.git//g' | awk {'print $0'}`
open "https://api.github.com/repos/$owner_repo/actions/runs"
复制代码
删除所有 actions
#!/bin/bash
# 1. should install https://github.com/stedolan/jq
# 2. should install https://github.com/httpie/httpie
# 3. should set access_token
access_token=''
## 获取 github owner/repo
owner_repo=`git config --get remote.origin.url | sed -e 's/\(https:\/\/github.com\/\)//g' | sed -e 's/\(git@github.com:\)//g' | sed -e 's/\.git//g' | awk {'print $0'}`
## 获取 github repo actions runs(前100个)
actions_runs_ids=( `http "https://api.github.com/repos/$owner_repo/actions/runs?per_page=100" | jq .workflow_runs | jq '.[]|.id'` )
echo ${actions_runs_ids[@]}
## 删除 actions runs
for run_id in ${actions_runs_ids[@]}; do
http DELETE "https://api.github.com/repos/$owner_repo/actions/runs/$run_id?access_token=$access_token" Accept:"application/vnd.github.v3+json"
done
复制代码
References
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END