3

That's a very nerdy topic, maybe overkill, maybe also off-topic on this forum (if so, sorry about that!), but I did a CI on GitHub allowing to automatically generate the archive to drop on CTAN for a package submission (or update).

3
  • 1
    see also l3build ctan for making ctan zips and l3build upload which we use for some of the core latex bundles that have automatic ctan releases Commented Oct 18 at 14:06
  • 4
    it would better fit the format of this site if you rephrased this as a question (how do you package for ctan?) then your existing answer makes more sense as an answer Commented Oct 18 at 14:09
  • For info, I have a github action that builds my documentation and then uploads it to ctan github.com/cmhughes/latexindent.pl/blob/main/.github/workflows/… Commented Oct 18 at 16:18

1 Answer 1

5

This file sets the CI up, here it is done for the library tikz-shieds, but it can be easily adapted to any package :)

name: Automated testing
on:
  push:
    branches:
      - main
    tags:
      - 'v*'
  pull_request:
    branches:
      - '*'
jobs:
  artifact:
    name: Test and create artifact
    runs-on: ubuntu-latest
    steps:
    - name: checkout code
      uses: actions/checkout@v5
    - name: Compile documentation document
      uses: xu-cheng/latex-action@v4
      with:
        root_file: |
          tests/test-0.tex
          # include here all the test files you want
          tikz-shields-doc.tex     # and the documentation
        latexmk_shell_escape: true
        post_compile: "latexmk -c; rm -rf _minted*"
    - name: Upload Artifact
      uses: actions/upload-artifact@v4
      with:
        name: tikz-shields
        path: |
          ./tikz-shields.sty
          ./tikz-shields-doc.tex
          ./tikz-shields-doc.pdf
          ./README.md
          ./LICENSE
          ./doc/**
          !./.git*
          !./.gitignore
  release:
    needs: [artifact]
    runs-on: ubuntu-latest
    name: Create Release
    if: startsWith(github.ref, 'refs/tags/v')
    steps:
      - name: Download artifact
        uses: actions/download-artifact@v4
        with:
          path: ${{ github.workspace }}/artifact

      - name: Create archive
        run: |
          temp_dir=$(mktemp -d)
          cd artifact
          zip -r "${temp_dir}/tikz-shields.zip" ./
          cd ..
          mv "${temp_dir}/tikz-shields.zip" ./
          rm -rf "${temp_dir}"

      - name: Create Release
        id: create_release
        uses: softprops/action-gh-release@v2
        with:
          tag_name: ${{ github.ref }}
          name: Release ${{ github.ref }}
          draft: true
          prerelease: false
          token: ${{ secrets.GITHUB_TOKEN }}
          files: tikz-shields.zip

Some notes:

  • In step Compile documentation document, the documentation is compiled, as well as various tests that can be added.
  • The step Upload Artifact generates an archive that contains only the files necessary for the upload on CTAN: the sty file, the documentation (the source file as well as the compiled one), and the README file. Note here that files are present in the directory doc.

After each commit to the main branch (or in another branch to which a pull request is open), the CI will be triggered, and this archive will be available as an artifact (with a few days of retention).

When you want to create a new version of the package, you just need to create a tag (git tag v1.0) and push it (git push then git push --tags), then the CI will create a draft release that can be manually published afterwards.

It contains the archive that can be sent to CTAN (example here).

You also need to give the permissions to the workflow so it can create the release. To do so, on GitHub, go to Settings > Action > General > Workflow permissions and check Read and write permissions.

The full pipeline for the example I used is available here: https://github.com/thomas-saigre/tikz-shields/blob/main/.github/workflows/ci.yml It may be updated in the future, but what I described above has worked well!

2
  • 1
    Does it also automatically update the date/version in each file, so that they all agree? Commented Oct 19 at 0:47
  • You're right, it doesn't. And so sty the file actually deployed as v1.0 of my package still has v0.1. Thanks for spotting it, I'll try to find a fix to this Commented Oct 19 at 9:56

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.