name: make dist

on:
  push:
    branches: [ "main" ]
    tags: v**
  pull_request:
    branches: [ "main" ]

jobs:
  make-dist:
    runs-on: ubuntu-latest

    steps:
    - uses: actions/checkout@v3

    - name: Build dist
      uses: xu-cheng/texlive-action/full@v1
      with:
        run: |
          apk add make git zip
          git config --global --add safe.directory '*'
          echo "VERSION=$(make version)" >> $GITHUB_ENV
          make dist CTAN

    - name: Release
      uses: softprops/action-gh-release@v1
      if: startsWith(github.ref, 'refs/tags/')
      with:
        files: dist/photobook*.zip
        
    - name: Artifacts - build
      uses: actions/upload-artifact@v3
      with:
        name: build artifacts
        path: photobook.pdf

    - name: Artifacts - dist
      uses: actions/upload-artifact@v3
      with:
        name: dist artifacts
        path: dist/photobook*.zip
        
    - name: Upload to CTAN (release)
      uses: paolobrasolin/ctan-submit-action@v1
      if: startsWith(github.ref, 'refs/tags/')
      with: 
        action: upload
        file_path: dist/CTAN/photobook.zip
        fields: |
            pkg: photobook
            version: ${{ env.VERSION }}
            author: Alex A. Naanou
            email: alex.nanou@gmail.com
            uploader: Alex A. Naanou <alex.nanou@gmail.com>
            license: bsd
            home: https://github.com/flynx/photobook
            repository: https://github.com/flynx/photobook
            summary: >
              Document class for typesetting photo books.
            description: >
              The photobook LaTeX document class extends the book class
              defining a set of parameters, meta-macros, macros and
              environments with reasonable defaults to help typeset,
              build and print books mainly based on visual/image content.
            #announcement: >
            #  I'm happy to announce the initial release on CTAN of the
            #  photobook document class.  
            #  
            #  The photobook class extends the book class defining a set
            #  of parameters, meta-macros, macros and environments with
            #  reasonable defaults to help typeset, build and print books
            #  mainly based on visual/image content.
               
        
        
