Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
lfilho opened this issue Jun 15, 2020 · 7 comments
Open

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

lfilho opened this issue Jun 15, 2020 · 7 comments
Labels

Comments

@lfilho
Copy link

lfilho commented Jun 15, 2020

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!

@gr2m
Copy link
Member

gr2m commented Jun 15, 2020

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

@gr2m gr2m added the support label Jun 15, 2020
@coderbyheart
Copy link
Contributor

No, you can't use the template strings when resolving files, because they are not replaced and passed verbatim:

github/lib/publish.js

Lines 51 to 60 in 32654fb

globbedAssets.map(async (asset) => {
const filePath = isPlainObject(asset) ? asset.path : asset;
let file;
try {
file = await stat(resolve(cwd, filePath));
} catch (_) {
logger.error('The asset %s cannot be read, and will be ignored.', filePath);
return;
}

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

@jedwards1211
Copy link
Contributor

jedwards1211 commented Oct 28, 2020

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
Copy link
Contributor

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

@jedwards1211
Copy link
Contributor

jedwards1211 commented Oct 28, 2020

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.

@levibostian
Copy link

@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.

@molvqingtai
Copy link

molvqingtai commented Sep 28, 2024

Why is it not consistent with GitLab's implementation? If the intention is to not support templates for paths, it should at least be mentioned in the documentation, which has cost me a whole day.

https://github.com/semantic-release/gitlab/pull/630/files

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants