name: CI

on:
  push:
    tags:
      - v*
  workflow_run:
    workflows: ["Auto Tag"]
    types:
      - completed

jobs:
  build:
    if: >-
      github.event_name == 'push' ||
      (github.event_name == 'workflow_run' && github.event.workflow_run.conclusion == 'success' && startsWith(github.event.workflow_run.head_branch, 'main'))
    runs-on: ubuntu-latest
    permissions:
      id-token: write
      contents: read

    steps:
    - uses: actions/checkout@v4
      with:
        fetch-depth: 0

    - name: Set up Python
      uses: actions/setup-python@v5
      with:
        python-version: "3.11"

    - name: Install uv
      run: |
        pip install uv

    - name: Install dependencies
      run: |
        uv pip install --system build twine

    - name: Build the package
      run: |
        python -m build

    - name: Publish to PyPI
      uses: pypa/gh-action-pypi-publish@release/v1
      with:
        attestations: true
      env:
        SETUPTOOLS_SCM_DEBUG: "1"

    - name: Upload artifact
      uses: actions/upload-artifact@v4
      with:
        name: personalinfo-${{ github.ref_name }}
        path: dist/*

    - name: Show git tags
      run: git tag --list
