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

Fail dry run deploy if version already exists in the registry #508

Open
ianldgs opened this issue May 23, 2023 · 4 comments · May be fixed by #667
Open

Fail dry run deploy if version already exists in the registry #508

ianldgs opened this issue May 23, 2023 · 4 comments · May be fixed by #667

Comments

@ianldgs
Copy link

ianldgs commented May 23, 2023

It would be nice to do something like npm diff | grep version -q in --dryRun mode, as suggested in npm/cli#4927, to help checking if a version would fail deploy.

We do a deploy --dryRun in PRs, and a regular deploy when merged. Sometimes the merged version fails due to it already existing in the registry.

@dianjuar
Copy link
Member

dianjuar commented May 24, 2023

Hi @ianldgs
Thank you for bringing up your concerns by opening this issue.

This plugin intends to be a wrapper around npm publish, and as the NPM team suggested, I believe other approaches can be considered to verify the current version already published on the registry.

I suggest a verification step before you run the target deploy. You accomplish this by creating an executor on the project.json to run your verification script and using the feature dependsOn to run that script before the deployment. This would be a pseudo config:

"verify-version-already-on-the-registry": {
  "executor": "nx:run-commands",
  "options": {
    "command": "./tools/your-script-to-verify-versions.sh"
  },
},
"deploy": {
  "executor": "ngx-deploy-npm:deploy",
  "options": {
    "access": "public"
  },
  "dependsOn": ["verify-version-already-on-the-registry"]
}

Another suggestion I could bring is to use @jscutlery/semver to know if you have something to deploy based on your commit messages. We use ngx-deploy-npm to publish ngx-deploy-npm (Yes, it uses itself) and @jscutlery/semver to determine the next version. If there is nothing to publish, @jscutlery/semver doesn't invoke ngx-deploy-npm.

You can see the real example on our project.json

Here is how it looks in the CI.

image

https://github.com/bikecoders/ngx-deploy-npm/actions/runs/5060100711/jobs/9082656207

@dianjuar
Copy link
Member

dianjuar commented May 26, 2023

@ianldgs, Something else that we could do is add an extra param to work along with the --dry-run param to verify if the version is already published.

It would be something like nx deploy YOUR_LIB --dry-run --fail-on-version-already-deployed (we could work later on a better name). I'm proposing this because I don't think changing the original behavior of --dry-run on npm publish will be something that other users would like.

@dianjuar
Copy link
Member

@edbzn your input is always welcome.

@ianldgs
Copy link
Author

ianldgs commented May 26, 2023

@dianjuar yes, we use jscutlery/semver. But look at this comment:

jscutlery/semver#444 (comment)

I like the idea of implementing the check in this plugin. It would give people one more tool to make their setup more resilient.
Even if it's a separate flag or executor :) no strong opinion on the naming.

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

Successfully merging a pull request may close this issue.

2 participants