Build Python Firefox Image #82
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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" |