Git action 이란?
: github 의 컴퓨터라고 보면 된다.
나의 상황은
내가 만든 코드를 내 컴퓨터 안에서 내가 항상 컴퓨터를 키고 있으면서
실행하기엔 너무 비효율적이니, 내가 아닌 다른 컴퓨터로 코드 실행을 원하는
주기대로 실행시키고 싶다.
그래서 git 컴퓨터 git action를 사용하는 것.
내가 실행하고 싶은 코드에는
공개하면 안될 slack 토큰, azure 스토리지 계정 키 값 환경변수가 있다.
github privacy는 비용이 들어
git action 으로 돌리면 공개적으로 코드가 다 나오니까 안되지 않을까 했으나
git action 에 secert 기능으로 보안처리를 할 수 있다.
1. Secret으로 git action 세팅하기
settings에 들어가 secret 에다가 필요한 보안키들을 저장한다.
New repository secret을 눌러 원하는 name, value 값 두가지 저장.
2. git action yml 파일 작성하기
(1) 새로운 workflow 생성
new를 누르면,
여러가지 환경 구축이 되어있는 workflow 가 보인다.
나는 python파일을 실행하고, 단순 python 실행이니까 만만한 python application 선택.
3. yml 작성하기
처음에, 생성되는 defalut 코드를 나와 맞게 변경해줘야 한다.
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python application
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics
# exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide
flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics
- name: Test with pytest
run: |
pytest
# This workflow will install Python dependencies, run tests and lint with a single version of Python
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-python-with-github-actions
name: Python application
on:
push:
branches: [ main ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v2
- name: Set up Python 3.9
uses: actions/setup-python@v2
with:
python-version: 3.9
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install os uuid re time datetime json pandas requests
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with python
run: |
python slackbot_2020.py
<1> on 변경
(1)pull_request 삭제
pull, push 가 같이 있는데,
일단 완성된 코드라는 가정하에 더이상의 pull는 없다 해서 삭제
branches : [main] 으로 push, pull 된다는 뜻.
<2>jobs :
bulid:
(1) runs-on
리눅스 우분투 최신버전-> 윈도우 최신버전으로 변경
(2)steps
다양한 names
- Install dependencies
run : |
이 파일을 실행할 때 필요한 import 값들을 넣어준다.
나는
import os
import uuid
import re
import time
from azure.storage.blob import BlobServiceClient, BlobClient, ContainerClient
import datetime
import json
import pandas as pd
from pandas import json_normalize
import requests
이렇게 썼기 때문에
pip install os uuid re time datetime json pandas requests
근데 from -- import 는 어떻게 써야하지 ㅠㅠ
-Lint with flake8
이건 필요없으니 과감히 삭제
-Test with pytest
나는 python으로 test 한다.
그리고 실행 코드는 python 파일.py
-name : run with python
run: |
python 파일.py
'Git, Github' 카테고리의 다른 글
Branch 이용해 pull 충돌 해결하기 (0) | 2022.01.26 |
---|---|
Git. Github 간단히 정리하기 (0) | 2021.12.31 |
git fork 상태에서 업데이트된 소스 가져오기 (git bash) (0) | 2021.03.06 |
git repository 생성, 소스 올리기, pull request 까지(Git Bash) (0) | 2021.03.06 |
Git action yml 실행 오류 - python version (2) | 2021.01.13 |