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

Allow templating #409

Merged
merged 4 commits into from Jul 11, 2022
Merged

Allow templating #409

merged 4 commits into from Jul 11, 2022

Conversation

kaerbr
Copy link
Contributor

@kaerbr kaerbr commented Jun 20, 2022

I added templating functioniality to url, type and filepath like already done in #365 for label.
Closes #406

Hope you like it (:

@fgreinacher fgreinacher self-requested a review June 20, 2022 21:22
@MrSplint3r
Copy link

Why did you do these changes that can be seen here?
https://github.com/semantic-release/gitlab/compare/cc91eddc3bc7bbe7eee1253baeb2f51f1241d7d1..65deb545bccef9b779c84df87741c6af9e2f2ce8

This means you are using now template literals on your test, which is replacing the ${...} expressions before Lodash can even get to it. The $ needs to be kept escaped for them to be replaced only at Lodash time. Or simply don't use the backticks.

Your tests where you try to use process.env.XXX vars will most likely not work since the process object is not present in the context given to the Lodash template here:

const _url = asset.url ? template(asset.url)(context) : undefined;

@kaerbr
Copy link
Contributor Author

kaerbr commented Jun 22, 2022

Why did you do these changes that can be seen here? https://github.com/semantic-release/gitlab/compare/cc91eddc3bc7bbe7eee1253baeb2f51f1241d7d1..65deb545bccef9b779c84df87741c6af9e2f2ce8

This means you are using now template literals on your test, which is replacing the ${...} expressions before Lodash can even get to it. The $ needs to be kept escaped for them to be replaced only at Lodash time. Or simply don't use the backticks.

The linting stage of the test was failing before this change. But you are right that lodash wont get to the ${...} expressions. I will add a change. (:

Your tests where you try to use process.env.XXX vars will most likely not work since the process object is not present in the context given to the Lodash template here:

const _url = asset.url ? template(asset.url)(context) : undefined;

But why would the tests run if this was the case? -- sry I'm new to Javascript. :(
Ok so I did a testrun with semantic-release/gitlab@9.3.2 (since v9.2.0 label templating is implemented) and it seems to work :

  • relevant parts of the .releaserc.yml:
- - "@semantic-release/gitlab"
    - assets:
        - url: "https://my.url"
          label: "${process.env.LABEL}"
          type: other
  • relevant parts of the .gitlab-ci.yml:
semantic-release:
  stage: release
  script:
    - export LABEL="my-label"
    - npm install -g semantic-release@19 @semantic-release/changelog@6 @semantic-release/exec@6 @semantic-release/git@10 @semantic-release/gitlab@9
    - semantic-release --debug
  • relevant parts of the debug output:
2022-06-22T06:02:52.221Z semantic-release:gitlab POST-ing the following JSON to https://gitlab.com/api/v4/projects/kaerbr%2Fsemantic-release-test/releases:
{
  "tag_name": "v1.8.0",
  "description": "# [1.8.0](https://gitlab.com/kaerbr/semantic-release-test/compare/v1.7.0...v1.8.0) (2022-06-22)\n\n\n### Features\n\n* process:env.XXX ([a361fd5](https://gitlab.com/kaerbr/semantic-release-test/commit/a361fd5bce4785ffeb9c8f6c266507700ceefa00))\n\n\n\n",
  "assets": {
    "links": [
      {
        "name": "my-label",
        "url": "https://my.url/",
        "link_type": "other"
      }
    ]
  }
}

So since I implemented the changes like for the label templating I think this should work and be fine? (: -- Or am I missing something?

@MrSplint3r
Copy link

Sorry, I was mistaken, the env vars object is indeed available on the context passed to the template functions, just under the name env. See here:
https://github.com/semantic-release/semantic-release/blob/9589a96239826abe9b07e8deffcc7d8aeb9c2e40/index.js#L257
https://github.com/semantic-release/semantic-release/blob/9589a96239826abe9b07e8deffcc7d8aeb9c2e40/index.js#L250

In that sense, now I understood why your tests are succeeding, even though you were using ${process.env.XXX} instead of ${env.XXX}. That's because Lodash also interprets that as a JavaScript expression and since process.env is available globally, it was able to resolve it.

I could definitely use this functionality as well so from me a 👍 for the contribution. :)

test/publish.test.js Outdated Show resolved Hide resolved
README.md Outdated Show resolved Hide resolved
@fgreinacher
Copy link
Contributor

Thanks for your work @kaerbr, I left some comments, ping me if you need support!

@fgreinacher
Copy link
Contributor

@kaerbr Thanks for adapting the tests! Ping me once you addressed the other comments - also if I should take over something!

@kaerbr
Copy link
Contributor Author

kaerbr commented Jul 11, 2022

@kaerbr Thanks for adapting the tests! Ping me once you addressed the other comments - also if I should take over something!

@fgreinacher I think I replied to all comments or pushed changes. -- waiting for your review/answers. (:

Copy link
Contributor

@fgreinacher fgreinacher left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @kaerbr, looking great!

@fgreinacher fgreinacher merged commit 129dff5 into semantic-release:master Jul 11, 2022
@github-actions
Copy link

🎉 This PR is included in version 9.4.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

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

Successfully merging this pull request may close these issues.

asset url containing ${nextRelease.version} not working/expanded
3 participants