github icon indicating copy to clipboard operation
github copied to clipboard

Can I use the templates in asset's path config?

Open lfilho opened this issue 5 years ago • 7 comments

Hi there, thanks for the great project!

I have the following files:

dist/file1-v1.0.0.zip
dist/file1-v1.0.1.zip
dist/file1-v1.1.0.zip
...etc

I wanted to attach the last generated file on the release in question. For that, I had this configuration:

      [
        "@semantic-release/github",
        {
          "assets": "dist/*.zip"
        }
      ]

With the config above, all my files in dist/ folder were getting attached to each release in Github's release page. So far so good, it was working as expected and it was a silly mistake of mine.

Then I tried to fix it by doing the following:

      [
        "@semantic-release/github",
        {
          "assets": "dist/*${nextRelease.version}.zip"
        }
      ]

But it didn't work -- no assets were attached to the next release. Am I missing something? Are templates even supported in path?

Thank you!

lfilho avatar Jun 15 '20 21:06 lfilho

I don't know out of my head. But I think @coderbyheart implemented the file templates feature. Maybe he can help?

gr2m avatar Jun 15 '20 21:06 gr2m

No, you can't use the template strings when resolving files, because they are not replaced and passed verbatim: https://github.com/semantic-release/github/blob/32654fb26dbba597170408ab181255ae863ed748/lib/publish.js#L51-L60

I recommend to store assets with an unversioned name define individual asset entries, with a name property that contains the desired name.

Here is an example of how I use it in a project: https://github.com/bifravst/firmware/blob/8632a44c5201c24c554c06861cbb32db11682b26/package.json#L44-L90

coderbyheart avatar Jun 16 '20 12:06 coderbyheart

I'm looking at releasing apps bundled with javapackager, which appends the project version to the base output name I choose. It doesn't seem possible to disable this, so it would be nice to have the flexibility to use template strings in asset paths. I guess I have to rename the files after the fact (ewww)

jedwards1211 avatar Oct 28 '20 03:10 jedwards1211

@gr2m would you be opposed to a PR to also call template on the asset paths before actually globbing them?

jedwards1211 avatar Oct 28 '20 03:10 jedwards1211

Or I guess making an unversioned symlink to the versioned filename would be palatable. I don't get the reasoning behind intentionally not supporting parameterized filenames though. Seems highly unlikely that someone would put literal ${nextRelease.version} or any other ${...} in a filename and need to match it verbatim. And if so, not hard to escape the $ in asset path config/not hard to explain this in the docs.

jedwards1211 avatar Oct 28 '20 03:10 jedwards1211

@jedwards1211 if it helps, here is what I did to get it working in the mean time.

Follow the advice from @coderbyheart and add path, label, and name properties. The name can add the version number.

Rename the file that javapacker produced to a static file name. Reference the hard coded path in path of the assets object.

levibostian avatar Oct 28 '20 14:10 levibostian