Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting Next tag version using semantic releases

Hi am using semantic release for versioning in my repo. In my Gitlab when i merge my branch with master my tag increases according to the commit and it works fine. Is there any way for me to get the " next tag version " that will come before the merge. I want to write the next version to a file before merging

Tried using exec but it doesn't seem to be running

i tried using exec but exec isn't running for me (Am quite new to semantic release i must be doing something wrong somewhere)

Could you push me in the right direction :)

My gitlab Ci script:

semantic_release:
stage: Tag
image: node:12.16
variables:
GITLAB_TOKEN: $TOKEN_ACCESS
before_script:
- npm install -g semantic-release/exec
- npm install -g semantic-release @semantic-release/gitlab-config
script:
- semantic-release -e @semantic-release/gitlab-config @semantic-release/exec
only:
- master

This is my package.json:

{
  "name": "@semantic-release/npm",
  "description": "semantic-release",
  "version": "0.0.0-development",
  "author": "",
  "release": {
    "analyzeCommits": "@semantic-release/commit-analyzer",
    "generateNotes": "@semantic-release/release-notes-generator",
    "publish": "@semantic-release/gitlab",
    "success": false,
    "fail": false,
    "branches": [
      "master"
    ],
    "npmPublish": false
  },
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    ["@semantic-release/exec", {
      "prepareCmd": "./my-build-script.sh ${nextRelease.version}"
    }]
  ]
}
1:30pm
[7:55:10 AM] [semantic-release] › ✔  Completed step "analyzeCommits" of plugin "@semantic-release/commit-analyzer"
[7:55:10 AM] [semantic-release] › ℹ  The next release version is 0.2.0
[7:55:10 AM] [semantic-release] › ℹ  Start step "verifyRelease" of plugin "[Function: verifyRelease]"
[7:55:10 AM] [semantic-release] › ✔  Completed step "verifyRelease" of plugin "[Function: verifyRelease]"
[7:55:10 AM] [semantic-release] › ℹ  Start step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[7:55:10 AM] [semantic-release] › ✔  Completed step "generateNotes" of plugin "@semantic-release/release-notes-generator"
[7:55:10 AM] [semantic-release] › ℹ  Start step "prepare" of plugin "[Function: prepare]"
[7:55:10 AM] [semantic-release] › ✔  Completed step "prepare" of plugin "[Function: prepare]"
[7:55:12 AM] [semantic-release] › ✔  Created tag v0.2.0
[7:55:12 AM] [semantic-release] › ℹ  Start step "publish" of plugin "@semantic-release/gitlab"
[7:55:12 AM] [semantic-release] [@semantic-release/gitlab] › ℹ  Verify GitLab authentication

Exec doesnt seem to be running

like image 565
Origin Avatar asked Mar 06 '20 15:03

Origin


People also ask

How do you manage releases with semantic versioning and Git tags?

Using semantic versioning in your project means being responsible for double-checking your version number before you release your code. As soon as your code is released into a production environment, you have to assume that somebody is using the code, and you should not change the version number.

How do you trigger a release with semantic-release?

Release steps Obtain the commit corresponding to the last release by analyzing Git tags. Determine the type of release based on the commits added since the last release. Verify the release conformity. Generate release notes for the commits added since the last release.


3 Answers

The next version tag will be passed to any plugin during the release. In order to update a file with the next version you can use the @semantic-release/exec during the prepare step:

{
  "plugins": [
    "@semantic-release/commit-analyzer",
    "@semantic-release/release-notes-generator",
    "@semantic-release/npm",
    ["@semantic-release/exec", {
      "prepareCmd": "./update-version.sh ${nextRelease.version}",
    }],
  ]
}

With this example the script ./update-version.sh will be called with the next version as its first parameter, before making the release.

Also See FAQ-How can I use a npm build script that requires the package.json’s version?

like image 171
Pierre Vanduynslager Avatar answered Oct 19 '22 02:10

Pierre Vanduynslager


Another solution (that I use in my shell script) is using grep on a "dry-run" (to not actually release a new version) npx semantic-release --dryRun | grep -oP 'Published release \K.*? '

like image 38
Ilan Schemoul Avatar answered Oct 19 '22 01:10

Ilan Schemoul


The solution that worked for me was the following which also:

  1. Still pipes the output of the semantic-release plugin to stdout.
  2. Pulls the version into an env var ($LATEST_VERSION) that you can do with what you will.
npx semantic-release --ci false --dryRun | tee /dev/tty | grep -i "Published release" > .semver-output

export LATEST_VERSION=$([[ $(cat .semver-output) =~ .*([[:digit:]]+\.[[:digit:]]+\.[[:digit:]]+) ]] && echo ${BASH_REMATCH[1]})
like image 27
Achintya Ashok Avatar answered Oct 19 '22 01:10

Achintya Ashok