Newer
Older
thu-learn-downloader-optimized / .github / workflows / ci.yaml
@Qin Li Qin Li on 12 Nov 2022 3 KB feat: refactor
name: CI/CD

on:
  push:
    branches:
      - "main"

jobs:
  cz:
    if: ${{ github.repository != 'liblaf/template' }}
    outputs:
      bumped: ${{ steps.bumped.outputs.bumped }}
      version: ${{ steps.cz.outputs.version }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/[email protected]
        with:
          fetch-depth: 0
      - id: cz
        name: Create Bump and Changelog
        uses: commitizen-tools/[email protected]
        with:
          github_token: ${{ github.token }}
          changelog_increment_filename: body.md
      - id: bumped
        run: |
          if [[ -n "$(cat body.md)" ]]; then
            echo "bumped = true"
            echo "bumped=true" >> $GITHUB_OUTPUT
          else
            echo "bumped = false"
            echo "bumped=false" >> $GITHUB_OUTPUT
          fi
      - if: ${{ steps.bumped.outputs.bumped == 'true' }}
        name: Upload Changelog
        uses: actions/[email protected]
        with:
          name: changelog
          path: body.md

  publish:
    needs: cz
    if: ${{ needs.cz.outputs.bumped == 'true' }}
    continue-on-error: true
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/[email protected]
      - run: git pull
      - name: Publish Package
        uses: ./.github/actions/publish
        with:
          pypi_token: ${{ secrets.PYPI_TOKEN }}

  deploy:
    needs: cz
    if: ${{ needs.cz.outputs.bumped == 'true' }}
    continue-on-error: true
    strategy:
      matrix:
        os:
          - macos-latest
          - ubuntu-latest
          - windows-latest
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/[email protected]
      - run: git pull
      - id: detect
        name: Detect Build Script
        shell: bash
        run: |
          set +o errexit
          set +o pipefail
          cat pyproject.toml | grep "build = \".*.build:run\""
          if (( $? == 0 )); then
            echo "build=true" >> $GITHUB_OUTPUT
          else
            echo "build=false" >> $GITHUB_OUTPUT
          fi
      - if: ${{ steps.detect.outputs.build == 'true' }}
        name: Build Artifacts
        uses: ./.github/actions/deploy
      - if: ${{ steps.detect.outputs.build == 'true' }}
        name: Upload Artifacts
        uses: actions/[email protected]
        with:
          name: ${{ matrix.os }}
          path: dist/**/*

  release:
    needs:
      - cz
      - deploy
    if: ${{ needs.cz.outputs.bumped == 'true' }}
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/[email protected]
      - run: git pull
      - name: Download Changelog
        uses: actions/[email protected]
        with:
          name: changelog
      - name: Download Artifacts
        uses: actions/[email protected]
        with:
          path: artifacts
      - name: GitHub Release
        uses: softprops/action-gh-release@v1
        with:
          tag_name: ${{ needs.cz.outputs.version }}
          body_path: body.md
          files: |
            artifacts/macos-latest/**/*
            artifacts/ubuntu-latest/**/*
            artifacts/windows-latest/**/*