Skip to content

Build Java Firefox Image #132

Build Java Firefox Image

Build Java Firefox Image #132

# https://docs.github.com/en/actions/guides
# CI name , it will display on github's action page menu
name: Build Java 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: "javafirefox"
jobs:
release_java:
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 }}
# 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 java
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d_%H:%M:%S')" >> $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: ${{ success() }}
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_java
if: ${{needs.release_java.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:
java_version: ["11.0.16","11.0-jdk","17.0.2-jdk","17.0.2", "17.0-jdk","8u342-jdk","8u342" ]
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
- name: Output Docker info
run: docker info
- name: Sets build date
run: echo "BUILD_DATE=$(date '+%Y%m%d')" >> $GITHUB_ENV
- name: check firefox_version
run: |
echo ${{env.FIREFOX_ESR_VERSION}}
- name: check geckodriver_version
run: |
echo ${{env.GECKODRIVER_VERSION}}
- name: check java_version
run: |
echo ${{matrix.java_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: ./java/Dockerfile
#构造环境变量传入list https://github.com/docker/build-push-action
build-args: |
JAVA_VERSION=${{matrix.java_version}}
FIREFOX_ESR_VERSION=${{env.FIREFOX_ESR_VERSION}}
GECKODRIVER_VERSION=${{env.GECKODRIVER_VERSION}}
# tag 不允许出现-
tags: "${{ secrets.DOCKER_USERNAME }}/${{ env.TAG_NAME }}:${{matrix.java_version}}.latest,${{ secrets.DOCKER_USERNAME }}/${{ env.TAG_NAME }}:${{matrix.java_version}}.firefox${{env.FIREFOX_ESR_VERSION}}"
push: true
- name: The job has succeeded
if: ${{ success() }}
run: echo "success"