name: Release

# 触发器
on:
  push:
    tags:
      - v*
  pull_request:
    tags:
      - v*
  workflow_dispatch:
    inputs:
      root_sol:
        description: "Release Title"
        required: true
        default: "SmsForwarder"

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      # 检出代码
      - uses: actions/checkout@v2
      # 设置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
      # 创建release
      - name: Create Release
        id: create_release
        uses: actions/create-release@v1
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          tag_name: ${{ github.ref }}
          release_name: SmsForwarder ${{ github.ref }}
          draft: false
          prerelease: false
      # 上传至release的资源
      - name: Upload release binaries
        uses: alexellis/upload-assets@0.2.2
        env:
          GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
        with:
          asset_paths: '["./build/app/outputs/apk/release/SmsForwarder_release_*"]'
