-
Notifications
You must be signed in to change notification settings - Fork 0
176 lines (171 loc) · 7.71 KB
/
build_python_firefox_slim_image.yml
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
# https://docs.github.com/en/actions/guides
# CI name , it will display on github's action page menu
name: Build Python Firefox Image
# trigger on which this CI should be run
on: # push operation is operate
push:
# here since my repository branch is named `main` , you should follow your own repository like `master`
branches: [main]
schedule:
- cron: "0 0 */6 * *"
# release:
# types: [published]
# CI enviroment settings
env:
TAG_NAME: "pythonfirefox-slim"
jobs:
release_python:
name: 发布新版本
runs-on: ubuntu-latest # use latest ubuntu to run the job
if: ${{ github.event_name == 'push' || github.event_name == 'schedule' || (github.event_name == 'issues' && startsWith(github.event.issue.title,'release'))}}
permissions:
contents: write
outputs:
FIREFOX_ESR_VERSION: ${{ steps.version.outputs.FIREFOX_ESR_VERSION }}
GECKODRIVER_VERSION: ${{ steps.version.outputs.GECKODRIVER_VERSION }}
IS_NEW: ${{ steps.version.outputs.IS_NEW }}
NEW_TAG: ${{ steps.version.outputs.NEW_TAG }}-slim
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
steps:
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
# here are some step followed , each step must have `uses` or `run` key , for CI to run
# other key like `name`,`with`,`env` is optional
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest requests
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Get latest version
run: |
python -m pip install requests
python latest_version_firefox.py --lang python --tag slim
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: SET VERSION to GITHUB
id: version
run: |
tail ./FIREFOX_ESR_VERSION >> $GITHUB_OUTPUT
tail ./GECKODRIVER_VERSION >> $GITHUB_OUTPUT
tail ./IS_NEW >> $GITHUB_OUTPUT
tail ./NEW_TAG >> $GITHUB_OUTPUT
tail ./FIREFOX_ESR_VERSION >> $GITHUB_ENV
tail ./GECKODRIVER_VERSION >> $GITHUB_ENV
tail ./IS_NEW >> $GITHUB_ENV
tail ./NEW_TAG >> $GITHUB_ENV
#zip the project files
- name: Zip project # This would actually build your project, using zip for an example artifact
if: ${{ steps.version.outputs.IS_NEW=='True' }}
run: |
zip -q -r firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip *
# https://github.com/marketplace/actions/create-release
- uses: ncipollo/release-action@v1
if: ${{ steps.version.outputs.IS_NEW=='True' }}
id: create_release
with:
tag: ${{ env.NEW_TAG }}
continue-on-error: false
- name: Upload Release Asset
if: ${{ steps.version.outputs.IS_NEW=='True' }}
id: upload-release-asset
uses: actions/upload-release-asset@v1 #https://github.com/actions/upload-release-asset
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
upload_url: ${{ steps.create_release.outputs.upload_url }} # This pulls from the CREATE RELEASE step above, referencing it's ID to get its outputs object, which include a `upload_url`. See this blog post for more info: https://jasonet.co/posts/new-features-of-github-actions/#passing-data-to-future-steps
asset_path: firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip
asset_name: firefox_${{ env.FIREFOX_ESR_VERSION }}_geckodriver_${{ env.GECKODRIVER_VERSION }}-production.zip
asset_content_type: application/zip
continue-on-error: false
- name: The job has succeeded
id: success_step
if: ${{ steps.create_release.outputs.upload_url }}
run: echo "my_output=success" >> $GITHUB_OUTPUT
- name: The job has failed
id: failure_step
if: ${{ failure() }}
run: echo "my_output=failure" >> $GITHUB_OUTPUT # job1 将失败
build:
name: 新版本已建立,构建,发布镜像
needs: release_python
if: ${{needs.release_python.outputs.IS_NEW == 'True'}}
runs-on: ubuntu-latest # use latest ubuntu to run the job
# https://docs.github.com/en/actions/using-jobs/using-a-matrix-for-your-jobs
strategy:
matrix:
python_version: ["3.8", "3.8.17", "3.9", "3.9.17", "3.10" , "3.10.9", "3.11", "3.11.4"]
steps:
- env:
FIREFOX_ESR_VERSION: ${{needs.release_python.outputs.FIREFOX_ESR_VERSION}}
GECKODRIVER_VERSION: ${{needs.release_python.outputs.GECKODRIVER_VERSION}}
IS_NEW: ${{needs.release_python.outputs.IS_NEW}}
NEW_TAG: ${{needs.release_python.outputs.NEW_TAG}}
run: echo "FIREFOX_ESR_VERSION $FIREFOX_ESR_VERSION GECKODRIVER_VERSION $GECKODRIVER_VERSION"
- uses: actions/checkout@v3
- name: Set up Python 3.9
uses: actions/setup-python@v4
with:
python-version: "3.9"
# here are some step followed , each step must have `uses` or `run` key , for CI to run
# other key like `name`,`with`,`env` is optional
- name: Install dependencies
run: |
python -m pip install --upgrade pip
pip install flake8 pytest requests
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
- name: Get latest version
run: |
python -m pip install requests
python latest_version_firefox.py --lang python
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: SET VERSION to GITHUB
id: version
run: |
tail ./FIREFOX_ESR_VERSION >> $GITHUB_OUTPUT
tail ./GECKODRIVER_VERSION >> $GITHUB_OUTPUT
tail ./IS_NEW >> $GITHUB_OUTPUT
tail ./NEW_TAG >> $GITHUB_OUTPUT
tail ./FIREFOX_ESR_VERSION >> $GITHUB_ENV
tail ./GECKODRIVER_VERSION >> $GITHUB_ENV
tail ./IS_NEW >> $GITHUB_ENV
tail ./NEW_TAG >> $GITHUB_ENV
# here are some step followed , each step must have `uses` or `run` key , for CI to run
# other key like `name`,`with`,`env` is optional
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: check python_version
run: |
echo ${{matrix.python_version}}
- name: Login to DockerHub
uses: docker/login-action@v2
with:
username: ${{ secrets.DOCKER_USERNAME }}
password: ${{ secrets.DOCKER_PASSWORD }}
#版本号第一位不允许空格 https://github.com/docker/build-push-action
- name: Push to Docker Hub
id: docker_build
uses: docker/build-push-action@v4
with:
context: .
file: ./python/Dockerfile-slim
#构造环境变量传入list https://github.com/docker/build-push-action
build-args: |
PYTHON_VERSION=${{matrix.python_version}}
FIREFOX_ESR_VERSION=${{env.FIREFOX_ESR_VERSION}}
GECKODRIVER_VERSION=${{env.GECKODRIVER_VERSION}}
# tag 不允许出现-
tags: "${{ secrets.DOCKER_USERNAME }}/${{ env.TAG_NAME }}:${{matrix.python_version}}.latest,${{ secrets.DOCKER_USERNAME }}/${{ env.TAG_NAME }}:${{matrix.python_version}}.firefox${{env.FIREFOX_ESR_VERSION}}"
push: true
- name: The job has succeeded
if: ${{ success() }}
run: echo "success"