semantic-release: Dry-run for previewing release does nothing
Current behavior
Dry-run does nothing and instead reports something like:
This run was triggered by a pull request and therefore a new version won't be published.
or
[2:59:20 PM] [semantic-release] › ℹ This test run was triggered on the branch refs/pull/3/merge, while semantic-release is configured to only publish from main, therefore a new version won’t be published.
Expected behavior
Dry-run runs the normal steps and plugins like with a release but does not commit anything or release artifacts.
Environment
- semantic-release version: ^17.4.2
- CI environment: Github actions
- Plugins used:
- semantic-release configuration: https://github.com/XC-/semantic-release-commitlint/blob/test/releaserc-configuration/.releaserc
- CI logs: https://github.com/XC-/semantic-release-commitlint/runs/2334857005?check_suite_focus=true#step:3:29 and https://github.com/XC-/semantic-release-commitlint/runs/2334409061?check_suite_focus=true#step:3:31
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 7
- Comments: 16 (1 by maintainers)
The most annoying thing is that it ends up returning
refs/pull/35/merge
regardless if I let it run in GITHUB (my CI) or in GIT (doingunset GITHUB_ACTIONS
)Github env: https://github.com/semantic-release/env-ci/blob/b39d3440157a17e89fc964876f4b5eb38df991d5/services/github.js#L39
Git env: https://github.com/semantic-release/env-ci/blob/b39d3440157a17e89fc964876f4b5eb38df991d5/lib/git.js#L11
Which would be ok only if
semantic-release
wasn’t checking THAT against real branch names: which will never matchhttps://github.com/semantic-release/semantic-release/blob/1beeb84c9032a22d455fc21b9a736efbcfde6b5d/index.js#L40-L41
https://github.com/semantic-release/semantic-release/blob/1beeb84c9032a22d455fc21b9a736efbcfde6b5d/index.js#L68-L69
Any updates from semantic-release contributors on how to make this work?
I believe all messages ending with
...therefore a new version won’t be published.
should be followed by, on a new line…Or, for simplicity
Currently, errors irrelevant in dev environments such as
ENOGHTOKEN
and non-error rules as as “The local branchmain
is behind the remote one, therefore a new version won’t be published.” prevent users from troubleshooting configuration errors and improving existing configurations withoutPUSH
ing to remote…which, when checking single-line changes, can be annoying or even lead to undesired changes by the CI/CD environment. The latter can be resolved by first adjusting the CI/CD’s invokation of semantic-release to also use--dry-run
, but then you need at least two more commits (and/or changes in a web interface) for diagnostics that could have been done without committing or pushing.GitTools’ GitVersion CLI has comparable commit analysis and version generation capabilities. It can work offline, while out-of-sync with remote, and with uncommitted changes.
GitTools' GitVersion CLI output
Ok, I found a workaround. Not sure if it’s ideal, but it’s working if anyone is interested
env-ci
will infer the branch name from git instead of GH Actions dataIf you’re running in a CI other than GitHub actions, I suggest you look at its corresponding
detect
criteria so that you can force it to false and get forcesemantic-release
to use git@seedy I create an action for this. I combine it with
create-or-update-comment
, in a way that myyml
file looks like this:I hope this helps you!
Edit: here’s the marketplace link
@Avivbens your implementation also uses
${{ github.head_ref }}
so suffers from the same issues I described above. If that’s not a problem for your use case then great! I do like your addition of the PR comment logic though so will be adopting that, thank you!Hi all 👋
I’ve created a nice GitHub action workflow, with no additional configuration needed 👍
Here are the workflow results for
chore
commit:Once you committed additional stuff, it will remove the last report and create a new one. Here are the results for
fix
commit:The workflow:
Enjoy 🥳
CC: @TJM @seedy @OliverEhrhardt @XC- @BinToss
@TJM if you also pass through the
--no-ci
flag, semantic-release won’t do the CI environment checks and so will skip the pull request check. This command should do the full dry run:npx semantic-release --dry-run --no-ci --branches master,$CI_COMMIT_BRANCH