今天主要要來講述 GitHub Actions CI 部分的文件撰寫,主要會來實作測試和建置這兩個步驟,因此話不多說,我們開始!
name: CI - testing
on:
push:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.10
uses: actions/setup-python@v3 # 此指令為採用別人寫好的流程
with: # 將他人流程當中的參數填入
python-version: "3.10"
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install pytest
pip install requests
pip install flask
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Test with pytest
run: |
pytest
name: CI - docker building
on:
push:
branches: [ "master" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Build & Push Image
run: |
cd ./src
echo "${{ secrets.DOCKER_PASSWORD }}" | docker login -u "kylekao" --password-stdin
docker image build -t kylekao/ithome .
docker push kylekao/ithome
${{ secrets.DOCKER_PASSWORD }}
,這部分是 GitHub Actions 提供將機密資料隱藏的方法,若要使用可以在專案的 Settings -> Secrets and variables -> Actions 中進行此設定,點擊後會進入到以下畫面,自行設定所需要隱藏的資料。