Github ActionsでCIしよう!
11月13日から、GithubはActionsと言う機能をリリースしました。
そのActionsは簡単なCIを使いたいチーム向けです。YAMLファイルを作ると、コードをプッシュした時か、プルリクエストをオープンするときに、Githubは自動にCode Styleのチェックして、ユニットテストを起動する。
この記事でDjangoのチュートリアルのアプリを使います。
https://docs.djangoproject.com/en/2.2/intro/tutorial01/

これでターミナルをオープンして、ローカルリポジトリを作る
django-admin startproject super_duper_guacamole
git init
touch requirements.txt
echo ‘django==3.0.1’ > requirements.txt
これをした後で、かんたんなテストファイルを作りましょう
tests.py と言うファイルを作って、そのファイルに次のコードを使いましょう
from django.test import TestCase
class testCase(TestCase):
def test_test(self):
return True
git add .
git commit -m “first commit”
git remote add origin https://github.com/<username>/super-duper-guacamole.git
git push -u origin master




Private Submoduleがある時にどうすれば良い?
Submoduleを加う
まずは新しいPrivate Repository を作りましょう
やった!ミュジカルパンケーキを作った!
この後 super-duper-guacamoleに戻って、submoduleを加えましょう。
git checkout -b add_submodule && git push -u origin add_submodule
git submodule add https://github.com/<username>/musical-pancake.git
git commit -m “added musical pancake”
git push
その後Githubでpythonapp.ymlのファイルにSubmoduleのCheckoutを加えて、プルリクエストをオープンしましょう。
ビルドが失敗した!
その理由は、ビルドする環境が認証情報が無いです。
Github ActionsをPAT(Personal Access Token)をあげれば、Private RepositoryのSubmoduleをプルできるになります。
Generate new token をクリックして、新しいトークンが作られる
repoをチェックしてね!
PATができた!でも今どうやって使えるか?
super-duper-guacamoleに戻ってSettingsタブでAdd a new secret をクリックして、PATを登録しましょう!
もうすぐ終わる!最後にステップは、そのSecretをpythonapp.ymlに加えましょう。
やった!ビルドが成功した!
これでGithubで自動でCode Styleチェックとユニットテストを自動で起動できる!