Upload-artifact : Variable name

Hi All,

I’ve been looking for ways to have a varying name for the artifact that I upload, but I haven’t found solutions on here that allow what I’m looking for. For reference, I’ve looked at both of these solutions:

What I’m looking for is a way to set the name based on items that are set in a file that is also in the repository. Specifically, I’m using the Gradle for Java Action, with some minor tweaks. I am specifically looking for my artifact to be named <base_name>-<game_version>-<project_version>.jar, where my gradle.properties file in the repo contains

base_name = exampleproject
game_version = 2.4.3
project-version = 0.3.2-SNAPSHOT

Thus the output would be exampleproject-2.4.3-0.3.2-SNAPSHOT.jar

If this is possible, please let me know how to specify that in my .yml file. If it can’t happen, then I’ll have to figure something else out.

Thanks

You’ll have to do this in two steps: Assemble the artifact name (or components) from the file and store it in a variable, and then use that in the upload-artifact step. I’d do the first part with a few lines of Python:

- run: |
    prop = dict()
    with open('gradle.properties') as fh:
        for line in fh:
            name, value = line.split('=', 1)
            prop[name.strip()] = value.strip()

    print(f'::set-env name=artifact_name::{prop["base_name"]}-'
          f'{prop["game_version"]}-{prop["project-version"]}.jar')
  shell: python
- uses: actions/upload-artifact@v2
  with:
    name: ${{ env.artifact_name }}
    path: # your file goes here