name: Weekly Build

# 触发器
on:
  schedule:
    - cron: '0 15 * * 0' #每周天在国际标准时间15点(北京时间+8，即 23:00)
  workflow_dispatch:
    inputs:
      root_sol:
        description: "Weekly Build Title"
        required: true
        default: "SmsForwarder"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # 检出代码
      - uses: actions/checkout@v2
      # 删除旧的工作流
      - name: Delete Weekly Build
        uses: Mattraks/delete-workflow-runs@v2
        with:
          token: ${{ github.token }}
          repository: ${{ github.repository }}
          retain_days: 0 # 全部删除只留正在跑的一条
          keep_minimum_runs: 0 # 全部删除只留正在跑的一条
          delete_workflow_pattern: 'Weekly Build'
      # 设置jdk环境为11
      - name: set up JDK 11
        uses: actions/setup-java@v1
        with:
          java-version: 11
      # 获取打包秘钥
      - name: Checkout Android Keystore
        uses: actions/checkout@v2
        with:
          repository: pppscn/keystore
          token: ${{ secrets.TOKEN }} # 连接仓库的token,需要单独配置
          path: keystore # 仓库的根目录名
      # 打包release
      - name: Build with Gradle
        run: bash ./gradlew assembleRelease
      # 存档打包的文件
      - name: Archive production artifacts
        uses: actions/upload-artifact@v3
        with:
          name: SmsForwarder Weekly Build
          path: app/build/outputs/apk/release/*.apk
          if-no-files-found: error
