LoginSignup
9
2

More than 3 years have passed since last update.

Github Actions

Last updated at Posted at 2019-12-22

Github ActionsでCIしよう!

11月13日から、GithubはActionsと言う機能をリリースしました。
そのActionsは簡単なCIを使いたいチーム向けです。YAMLファイルを作ると、コードをプッシュした時か、プルリクエストをオープンするときに、Githubは自動にCode Styleのチェックして、ユニットテストを起動する。

この記事でDjangoのチュートリアルのアプリを使います。
https://docs.djangoproject.com/en/2.2/intro/tutorial01/

まずはGithubのプライベートリポジトリを作りましょう
Screen Shot 2019-12-20 at 10.10.10.png

Screen Shot 2019-12-20 at 10.20.35.png

Guacamole 完了!やった!guacamole.jpg

これでターミナルをオープンして、ローカルリポジトリを作る

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

Screen Shot 2019-12-20 at 15.36.02.png
これで、DjangoのサンプルプロジェクトをGithubにプッシュしました。
その後、Actionsをクリックして、Python application を選択して、pythonapp.ymlが自動で作ります。これでプルリクエストをオープンしましょう。
Screen Shot 2019-12-20 at 15.39.51.png
/!\ pytestの設定はここにしませんのでその代わりに、
python manage.py test でテストを起動します /!\
これでGithubは自動でビルドを起動する。Screen Shot 2019-12-20 at 15.56.19.png
Screen Shot 2019-12-20 at 15.43.54.png

Private Submoduleがある時にどうすれば良い?

Submoduleを加う

まずは新しいPrivate Repository を作りましょう
Screen Shot 2019-12-20 at 15.48.05.png
Screen Shot 2019-12-20 at 17.24.08.png
やった!ミュジカルパンケーキを作った!
musical pancake.jpg

この後 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を加えて、プルリクエストをオープンしましょう。
Screen Shot 2019-12-20 at 17.17.36.png
Screen Shot 2019-12-20 at 17.33.10.png
Screen Shot 2019-12-20 at 17.31.40.png

ビルドが失敗した!
その理由は、ビルドする環境が認証情報が無いです。
Github ActionsをPAT(Personal Access Token)をあげれば、Private RepositoryのSubmoduleをプルできるになります。
Screen Shot 2019-12-20 at 17.38.32.png
Generate new token をクリックして、新しいトークンが作られる
repoをチェックしてね!
Screen Shot 2019-12-20 at 18.48.14.png
Screen Shot 2019-12-20 at 17.42.55.png

PATができた!でも今どうやって使えるか?

super-duper-guacamoleに戻ってSettingsタブでAdd a new secret をクリックして、PATを登録しましょう!
Screen Shot 2019-12-20 at 17.47.02.png

もうすぐ終わる!最後にステップは、そのSecretをpythonapp.ymlに加えましょう。
Screen Shot 2019-12-20 at 17.58.04.png
Screen Shot 2019-12-20 at 17.57.36.png
やった!ビルドが成功した!
これでGithubで自動でCode Styleチェックとユニットテストを自動で起動できる!

長かった。。。疲れた。。。おやすみなさい!
tired cat.jpg

9
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
2