Naming Artifacts after committed files

Hey there.
Yesterday I started using GitHub Actions so I’m very new to this.

My first action works very well:
If I commit a .tex file, it builds it into a PDF file and uploads it as an artifact.

name: Build LaTeX PDF files
on:
  push:
    paths:
    - '**.tex'

  workflow_dispatch:

jobs:
  build:
    runs-on: ubuntu-latest
    steps:
      - name: Set up Git repository
        uses: actions/checkout@v2
      - name: Read committed files
        uses: jitterbit/get-changed-files@v1
        id: files
        with:
          format: space-delimited
      - name: Print files
        id: print_files
        run: |
          for changed_file in ${{ steps.files.outputs.all }}; do
            echo "Found file: ${changed_file}."
          done
      - name: Compile LaTeX document
        uses: xu-cheng/latex-action@v2
        with:
          root_file: ${{ steps.files.outputs.all }}
      - name: Save PDF file
        uses: actions/upload-artifact@v2
        with:
          name: PDF
          path: test.pdf

This only works if the .tex file has the name “test.tex” because the upload-artifact action is hardcoded to use the “test.pdf” file.

Now my question is if there is any way to name files dynamically after the name of the .tex file because I read that substrings aren’t a thing in yml and I want to name the pdf after the tex file.

Technically you could reference the output of another step, like you do in the “Print files” step with ${{ steps.files.outputs.all }}.

However, as I understand the workflow there could be a list of files, right? If you want all of them it would be easier to tell actions/upload-artifact to grab all PDF files:

      - name: Save PDF file
        uses: actions/upload-artifact@v2
        with:
          name: PDF
          path: |
            *.pdf
            **/*.pdf
1 Like

Oh wow, I didn’t even think about this notation: *.pdf

  1. What does **/*.pdf mean?
  2. The first part of the script is able to work with multiple files but the part where the latex action is called gets a filename as input. Is there any way to extract every string of the list ${{ steps.files.outputs.all }} and run following code on every item:
- name: Compile LaTeX document
    uses: xu-cheng/latex-action@v2
    with:
       root_file: filename

Thanks for your help!

The ** matches any number of directories, so it would find any PDF files you might have in subdirectories (e.g. a/b/c.pdf). If you don’t have any of those or don’t want them in the artifact you can just remove that part.

There isn’t any looping on the step level, but the README for the xu-cheng/latex-action action says you can give multiple files as a multi-line string (which might require some formatting).

Or you could install the necessary packages on the runner (Ubuntu has texlive packages) and run pdflatex or lualatex in a shell loop.

1 Like

Well I think that can be helpful.

Yeah I also found that but how do I format the output list to something like that:

root_file: |
      file1.tex
      file2.tex

I just did some experimenting, based on hints from this thread:

The key is that to have newlines in an output you need to URL-encode them. I’ve been using Python to do the space-to-newline conversion because shlex makes it easy to handle escapes (e.g. a file name containing a space) when splitting the space-separated list:

You could use something similar to convert the list you have. :slightly_smiling_face:

1 Like

Thanks a lot for investing time in uploading an example, I finally got it working.

Thanks for your time!

1 Like