본문으로 바로가기

Github Actions 연동하는 방법

category Coding/DevOps 2019. 10. 30. 18:03
반응형

일반적으로 CI에는 TravisCI/CircleCI/Bitbucket Pipeline등 다양한 옵션들이 존재한다. 나는 소스 저장소로 깃허브를 사용하고 있는데, 2018년도에 Github Actions가 등장하면서 깃허브 자체적으로도 CI기능을 이용할 수 있다고 한다. 따라서 이렇게 간단하게나마 포스팅으로 정리한다. 먼저 아래의 사이트로 들어가서 Sign up for beta 버튼을 누른다.


https://github.com/features/actions


그다음으로 액션을 적용할 레포지터리로 이동하면



위처럼 Actions 탭이 존재한다. 클릭하여 들어간다. 



기본적으로 위처럼 다양한 템플릿을 제공해준다. 하지만 우리는 직접 원하는 것을 작성할 것이므로 오른쪽 상단에 있는 Set up a workflow yourself 버튼을 누른다.



그러면 이렇게 기본적인 내용이 추가된채로 파일을 생성할 수 있다. 원하는 내용을 채워넣고 오른쪽 상단에 있는 Start Commit 버튼을 누르면 원하는 커밋 메시지와 함께 커밋을 할 수 있다.



커밋을 하게되면 레포지터리명/.github/workflows/지정한이름.yml 파일이 생성된다. 다시 Actions 탭으로 이동해보면,



무언가가 실행되고 있음을 알 수 있다. 클릭하여 들어가서 확인해본다.



왼쪽 탭에 단계들이 나오며 오른쪽 창을 통해 정확하게 작업들을 실행한 내용들이 출력된다.


name: HFive

on:
push:
branches:
- master
- develop

jobs:
build:
name: CI
runs-on: ubuntu-latest

services:
mysql:
image: mysql:5.7
env:
MYSQL_ROOT_PASSWORD: root
ports:
- 3306
options: --health-cmd="mysqladmin ping" --health-interval=10s --health-timeout=5s --health-retries=3

steps:
- uses: actions/checkout@v1

- name: Setup Python 3.7.4
uses: actions/setup-python@v1
with:
python-version: 3.7.4

- name: Init Database
run: |
mysql -uroot -h127.0.0.1 -proot -e 'CREATE USER hfive@localhost IDENTIFIED BY "hfive"'
mysql -uroot -h127.0.0.1 -proot -e 'CREATE DATABASE test'
mysql -uroot -h127.0.0.1 -proot -e 'CREATE DATABASE hfive'
mysql -uroot -h127.0.0.1 -proot -e 'GRANT ALL PRIVILEGES ON test.* TO hfive@localhost IDENTIFIED BY "hfive" WITH GRANT OPTION'
mysql -uroot -h127.0.0.1 -proot -e 'GRANT ALL PRIVILEGES ON hfive.* TO hfive@localhost IDENTIFIED BY "hfive" WITH GRANT OPTION'

- name: Install Dependencies
run: |
pip3 install pipenv
pipenv install --system

- name: Testing
env:
env: testing
unexpired_token: ${{ secrets.unexpired_token }}
unexpired_refresh_token: ${{ secrets.unexpired_refresh_token }}
run: pytest


(master, develop 브랜치에서만 동작하고, MySQL 5.7버전과 Python 3.7.4버전을 사용하며 관련 디펜던시를 설치하고 최종적으로 pytest를 통해 테스트를 진행하는 예제)

반응형