name: Release

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

jobs:
  build:
    name: Build dist
    runs-on: ubuntu-latest
    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0
    - name: Set up Python 3.10
      uses: actions/setup-python@v5
      with:
        python-version: "3.10"
    - name: Set up Node.js
      uses: actions/setup-node@v4
      with:
        node-version: '20'
    - name: Install dependencies
      run: |
        pip install build
    - name: Build web assets
      run: |
        cd web
        npm install
        npm run build
    - name: Build Python package
      run: |
        python -m build
    - uses: actions/upload-artifact@v4
      with:
        name: dist
        path: dist

  release:
    needs: build
    name: Upload release to PyPI
    runs-on: ubuntu-latest
    environment:
      name: pypi
      url: https://pypi.org/p/memos
    permissions:
      id-token: write  # IMPORTANT: this permission is mandatory for trusted publishing
    steps:
    - uses: actions/download-artifact@v4
      with:
        name: dist
        path: dist
    - name: Publish package distributions to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1