#https://github.com/yyx990803/release-tag

name: Create Release

on:
  push:
    tags:
      - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10

#on:
#  push:
#    branch: ['master']

jobs:
  build:
    name: Create Release
    runs-on: ubuntu-latest
    steps:
      - name: Checkout Master
        uses: actions/checkout@master

      # 拉取web前端dist的代码
      - name: Checkout Web Dist
        uses: actions/checkout@v3
        with:
          repository: 'mouday/domain-admin-web'
          ref: 'dist'
          token: ${{ secrets.GH_PAT }}
          path: 'domain_admin/public'

      - name: Checkout Mini Dist
        uses: actions/checkout@v3
        with:
          repository: 'mouday/domain-admin-mini'
          ref: 'dist'
          token: ${{ secrets.GH_PAT }}
          path: 'domain_admin/public/m'

      - name: Set up Python
        uses: actions/setup-python@v3
        with:
          python-version: '3.x'

      - name: Install dependencies
        run: |
          python -m pip install --upgrade pip
          pip install setuptools wheel twine

      - name: Build Dist
        run: |
            python setup.py sdist bdist_wheel --python-tag py2.py3

      # 拉取前端最新的master代码
      - name: Checkout Web Master
        uses: actions/checkout@v3
        with:
          repository: 'mouday/domain-admin-web'
          ref: 'master'
          token: ${{ secrets.GH_PAT }}
          path: 'domain_admin_web'

      # https://github.com/a7ul/tar-action
      # https://docs.github.com/zh/actions/learn-github-actions/contexts#github-context
      - name: Compress action step Web
        uses: a7ul/tar-action@v1.1.0
        id: compress-web
        with:
          command: c
          cwd: ./
          files: |
            ./domain_admin_web
          outPath: ./dist/domain-admin-web-${{github.ref_name}}.tar.gz

      # 拉取H5前端最新的master代码
      - name: Checkout Mini Master
        uses: actions/checkout@v3
        with:
          repository: 'mouday/domain-admin-mini'
          ref: 'master'
          token: ${{ secrets.GH_PAT }}
          path: 'domain_admin_mini'

      # remove .git
      - name: Remove .git Dir
        run: rm -rf '.git' 'domain_admin/public/.git' 'domain_admin/public/m/.git'

      - name: Compress action step Mini
        uses: a7ul/tar-action@v1.1.0
        id: compress-mini
        with:
          command: c
          cwd: ./
          files: |
            ./domain_admin_mini
          outPath: ./dist/domain-admin-mini-${{github.ref_name}}.tar.gz

      - name: Release
        uses: softprops/action-gh-release@v1
        if: startsWith(github.ref, 'refs/tags/')
        with:
          files: ./dist/*
          body: Please refer to [CHANGELOG.md](https://domain-admin.readthedocs.io/zh_CN/latest/manual/changelog.html) for details.
          # note you'll typically need to create a personal access token
          # with permissions to create releases in the other repo
