# action name
name: Test with Junit

# 什么时候触发这个workflow
on:
  # push 到master分之的时候 这里可以指定多个
  push:
    branches:
      - master
    paths-ignore:
    - '**.md'
  # pull request 到master分之的时候, 这里可以指定多个
  pull_request:
    branches:
      - master
    paths-ignore:
      - '**.md'
  # 定时调度执行
  schedule:
    - cron: '26 10,11 * * *'
env:
  https_proxy: http://172.20.32.253:3128
  http_proxy: http://172.20.32.253:3128

# 一个workflow可以由多个job组成，多个job可以并行运行
jobs:
  junit:
    strategy:
      matrix:
        # 指定jdk 版本。可以指定多个版本 比如[8,11,17]
        java: [11]
        # 指定运行 os 版本 也是多个
        os: [ 'ubuntu-latest' ]
    # 运行环境，这里就是上面定义的多个 os
    runs-on: 'ubuntu-latest'
    steps:
      # 将job的工作目录指向$GITHUB_WORSPACES checkout@v2比较旧不推荐使用
      - name: Checkout codes
        uses: actions/checkout@v3
      - name: Install Java and Maven
        uses: actions/setup-java@v3
        with:
          java-version: '11'
          distribution: 'temurin'
      # 设置jdk环境
      - name: download latest temurin JDK
        id: download_latest_jdk
        env:
          HTTPS_PROXY: http://172.20.32.253:3128
          HTTP_PROXY: http://172.20.32.253:3128
        #run: curl -o https://testgitea2.trustie.net/xxq250/licensee-identify-api-sss/raw/branch/master/openlogic-openjdk-11.0.22+7-linux-x64.tar.gz
        run: wget -O $RUNNER_TEMP/java_package.tar.gz "http://172.20.32.202:10082/xxq250/licensee-identify-api-sss/raw/branch/master/OpenJDK11U-jdk_x64_linux_hotspot_11.0.22_7.tar.gz"
      - uses: actions/setup-java@v4
        with:
          distribution: 'jdkfile'
          jdkFile: ${{ runner.temp }}/java_package.tar.gz
          java-version: '11.0.0'
          architecture: x64
          mvn-toolchain-vendor: 'Oracle'
      # 设置maven 仓库缓存 避免每次构建时都重新下载依赖
      - name: Cache local Maven repository
        uses: actions/cache@v3
        with:
          path: ~/.m2/repository
          key: ${{ runner.os }}-maven-${{ hashFiles('**/pom.xml') }}
          restore-keys: |
            ${{ runner.os }}-maven-
      - name: Test java version
        run: java -version
      - name: Set up Maven
        uses: stCarolas/setup-maven@v5
        with:
          maven-version: 3.8.2
      - name: Setup Maven mirrors
        uses: s4u/maven-settings-action@v3.0.0
        with:
          mirrors: '[{"id": "alimaven", "name": "aliyun maven", "mirrorOf": "central", "url": "http://172.20.32.181:30005/repository/aliyun-maven/"}]'
      - name: env show
        run: env
      - name: cat maven-settings.xml
        run: cat /root/.m2/settings.xml
      - name: Test with Maven
        run: mvn clean test -B -U
        env:
          https_proxy: http://172.20.32.253:3128
          http_proxy: http://172.20.32.253:3128
