Python 项目调用 Github Actions 中的 Secrets

配置 Secret

设置好名为 mySecret 的 Secret

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
name: 'GitHub Actions Demo'

on:
push:
schedule:
- cron: '0 23 * * *'

jobs:
Weather-daily:
runs-on: ubuntu-latest
steps:
- name: 'Checkout'
uses: actions/[email protected]
- name: 'Set up Python'
uses: actions/[email protected]
with:
python-version: 3.7
- name: 'Install requirements'
run: |
python -m pip install --upgrade pip
pip install -r requirements.txt
- name: 'Working'
env:
apiID: ${{ secrets.APIID }}
appSecret: ${{ secrets.APPSECRET }}
SCKEY: ${{ secrets.SCKEY }}
run: python Demo.py

Demo

1
2
3
4
import os

mySecret = os.environ['mySecret']
print(mySecret)