├── empty.txt ├── python-service ├── deploy_service.py ├── build.py └── test.py ├── .github └── workflows │ └── deploy.yml └── README.md /empty.txt: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /python-service/deploy_service.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | print("正在打包上传到远程服务器...") 5 | print("上传成功!") 6 | -------------------------------------------------------------------------------- /python-service/build.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | 3 | 4 | 5 | print("开始构建") 6 | n_range = 5 7 | for i in range(n_range): 8 | print("完成百分比 " + str(100 * (i+1)*1.0/n_range) + "...") 9 | 10 | print("构建完成!") 11 | -------------------------------------------------------------------------------- /python-service/test.py: -------------------------------------------------------------------------------- 1 | # -*- coding: utf-8 -*- 2 | import time 3 | 4 | n_test_cases = 5 5 | print("开始测试,共 " + str(n_test_cases) + " 个测试用例") 6 | 7 | 8 | for i in range(n_test_cases): 9 | time.sleep(1) 10 | print("test case " + str(i + 1) +" passed") 11 | 12 | print("所有测试用例通过") 13 | -------------------------------------------------------------------------------- /.github/workflows/deploy.yml: -------------------------------------------------------------------------------- 1 | name: Python Service 2 | 3 | on: [push] 4 | 5 | jobs: 6 | build: 7 | 8 | runs-on: ubuntu-latest #构建环境,如无特殊需要可以默认为ubuntu-latest 9 | 10 | steps: # 步骤 11 | - uses: actions/checkout@v1 # 注释1 12 | - name: Set up Python 3.7 # 使用python特定版本 13 | uses: actions/setup-python@v1 14 | with: 15 | python-version: 3.7 # 注释2 16 | - name: Test # 第二步,注意上面actions/checkout@v1 为第一步 17 | run: | 18 | ls -all -h # 可以直接运行普通的linux命令 19 | pwd # 注意此行输出,actions运行的默认路径是你的repo根目录 20 | python -m pip install --upgrade pip # 可直接运行普通的python命令 21 | python ./python-service/test.py # 开始测试 22 | - name: Build 23 | run: | 24 | python ./python-service/build.py 25 | - name: Deploy 26 | run: | 27 | python ./python-service/deploy_service.py 28 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # github-actions-tutorial 2 | Github Actions教程 3 | 4 | 教程全文在: https://kalasearch.com/github-actions-simple-tutorial/ 5 | 6 | 请Fork本repo,然后执行 7 | 8 | ```git clone git@github.com:YOUR_NAME/github-actions-tutorial.git 9 | cd github-actions-tutorial 10 | 11 | touch empty.txt # 向文件夹里添加一个空文件 12 | git add empty.txt 13 | git commit -m "Add empty file" 14 | git push origin master 15 | 16 | ``` 17 | 18 | 即可在你fork出的repo中看到Actions的输出 19 | 20 | 21 | 22 | ### Workflow YAML文件 23 | 请参考.github/workflow/deploy.yml 24 | 25 | 这里的deploy.yml命名不是必须,可替换。 26 | 27 | 本repo中的deploy.yml文件内容为 28 | 29 | ``` 30 | name: Python Service 31 | 32 | on: [push] 33 | 34 | jobs: 35 | build: 36 | 37 | runs-on: ubuntu-latest #构建环境,如无特殊需要可以默认为ubuntu-latest 38 | 39 | steps: # 步骤 40 | - uses: actions/checkout@v1 # 注释1 41 | - name: Set up Python 3.7 # 使用python特定版本 42 | uses: actions/setup-python@v1 43 | with: 44 | python-version: 3.7 # 注释2 45 | - name: Test # 第二步 46 | run: | 47 | ls -all -h # 可以直接运行普通的linux命令 48 | pwd # 注意此行输出,actions运行的默认路径是你的repo根目录 49 | python -m pip install --upgrade pip # 可直接运行普通的python命令 50 | python ./python-service/test.py # 开始测试 51 | - name: Build 52 | run: | 53 | python ./python-service/build.py 54 | - name: Deploy 55 | run: | 56 | python ./python-service/deploy_service.py 57 | 58 | ``` 59 | 60 | 注释1:默认必须提供的`checkout action`标准操作(见注释一)。这一步是使用一个标准的action来告诉github actions你的代码在哪里(详情见: [Checkout Action文档])。 61 | 62 | 注释2:这是为`actions/setup-python@v1`这个第三方action提供它需要的操作,即python版本 63 | 64 | 65 | 66 | --------------------------------------------------------------------------------