はじめに
CICD導入+自分で1からAndroidアプリを作成しAppiumでE2Eテスト自動化をやってみて学んだことを備忘録として残しておく。
自分で1からAndroidアプリを作成してE2Eテスト自動化を行ったリポジトリは以下。
CircleCiのパイプラインのトリガー
デフォルトの設定について
By default, CircleCI automatically builds a project whenever you push changes to a version control system (VCS). You can override this behavior by adding a [ci skip] or [skip ci] tag anywhere in a commit’s title or description.
手動でパイプラインを実行する
curl https://circleci.com/api/v2/project/<vcs-type>/<org>/<repo>/pipeline \
--request POST \
--header "Circle-Token: <API_KEY>"
-
<vcs-type>
CircleCiのconfig.yml
を置いているVCSのタイプ
ex) github -
<org>
CircleCiのorganizationの名前 -
<repo>
VCSのリポジトリ名(CircleCiのパイプラインでcheckoutするブランチのリポジトリ) -
<API_KEY>
CircleにアクセスするためのToken
また、この手動トリガー以外でパイプラインを実行させたくない場合には、yamlを以下のように記述し、curlコマンドも次のように変更する事でそれが実現できる。
JSON=$(cat << EOS
{
"branch": "main",
"parameters": {
"manual": true
}
}
EOS)
curl https://circleci.com/api/v2/project/<vcs-type>/<org>/<repo>/pipeline \
--request POST \
--header "Circle-Token: <API_KEY>"
--header "Content-Type: application/json" \
--data "${JSON}"
version: 2.1
parameters:
manual:
type: boolean
default: false
workflows:
run_pipeline:
when: << pipeline.parameters.manual >>
jobs:
- hoge
- fuga
上記のような実装したソースコード(yaml)全体は以下。
- GitHub Actionsのyml(CircleCiのworkflowをキックするパイプライン)
https://github.com/yuta-katayama-23/MobileAppE2ETest/blob/happybirthday-app/.github/workflows/circleci-manual-start.yml - CircleCiのyml(手動トリガーのみで実行されるように実装したパイプライン)
https://github.com/yuta-katayama-23/MobileAppE2ETest/blob/happybirthday-app/.circleci/config.yml#L10
-
https://circleci.com/docs/ja/2.0/triggers/#skip-builds
基本的にはVCSへのpushをトリガーにしてパイプラインが走るようになっている。
push時にパイプラインが走らないようにするには、[ci skip]
とか[skip ci]
という文字列をコミットメッセージ or 説明に記載すればいい。1 ↩ -
https://circleci.com/docs/ja/2.0/triggers/#trigger-a-job-using-curl-and-your-api-token
https://circleci.com/docs/api/v2/#operation/triggerPipeline
手動のトリガーでCircleCiのパイプラインを実行したくなる場面も出てくるが、そんな時には、Web APIをcallすればいい。2 ↩