Newer
Older
thu-learn-downloader-optimized / .github / workflows / ci.yaml
name: CI

on:
  push:

concurrency:
  group: ${{ github.workflow }}-${{ github.ref }}

jobs:
  build-pkg:
    name: Build Package
    runs-on: ubuntu-latest
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Poetry
        run: pipx install poetry
      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: poetry
      - name: Install Dependencies
        run: poetry install
      - name: Build Package
        run: poetry build
      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: package-py${{ matrix.python-version }}
          path: dist/*
    strategy:
      matrix:
        python-version:
          - "3.11"

  build-exe:
    name: Build Executable
    runs-on: ${{ matrix.os }}
    steps:
      - name: Checkout
        uses: actions/checkout@v4
      - name: Install Task
        uses: arduino/setup-task@v1
        with:
          repo-token: ${{ github.token }}
      - name: Install Poetry
        run: pipx install poetry
      - name: Setup Python
        uses: actions/setup-python@v5
        with:
          python-version: ${{ matrix.python-version }}
          cache: poetry
      - name: Install Dependencies
        run: poetry install
      - name: Install GNU Softwares
        uses: liblaf/template/.github/actions/install@main
        with:
          brew: coreutils
          choco: gnuwin32-coreutils.install
      - name: Build Executable
        run: poetry run task dist
      - name: Upload Artifacts
        uses: actions/upload-artifact@v4
        with:
          name: ${{ runner.os }}-${{ runner.arch }}-py${{ matrix.python-version }}
          path: dist/*
    strategy:
      matrix:
        os:
          - ubuntu-latest
          - macos-latest
          - windows-latest
        python-version:
          - "3.10"
          - "3.11"
          - "3.12"

  upload:
    name: Upload Release Assets
    permissions:
      contents: write
    needs:
      - build-pkg
      - build-exe
    if: github.ref == 'refs/heads/main'
    runs-on: ubuntu-latest
    steps:
      - name: Download Artifacts
        uses: actions/download-artifact@v4
        with:
          path: artifacts
      - name: Delete Existing Release
        run: gh release --repo="${{ github.repository }}" delete dev --cleanup-tag
        env:
          GH_TOKEN: ${{ github.token }}
        continue-on-error: true
      - name: Upload Release Assets
        run: gh release --repo="${{ github.repository }}" create dev artifacts/**/* --generate-notes --prerelease
        env:
          GH_TOKEN: ${{ github.token }}

  check:
    name: Check
    needs:
      - build-pkg
      - build-exe
      - upload
    if: always()
    runs-on: ubuntu-latest
    steps:
      - name: Check
        uses: re-actors/alls-green@release/v1
        with:
          jobs: ${{ toJSON(needs) }}
          allowed-skips: upload