I have a problem with a pipeline which is used to increase a npm lib
version (a storybook project with some react components). I didn't find a perfect way to increase the version automatically being one-to-one with each Pull Request
. So, for each completed PR, I want to increase the version (patch
): 0.0.1 -> 0.0.2 -> 0.0.3 ...
So, the principal pipeline is triggered on main branch. When somebody complete a PR, because the main branch receive updates will trigger the pipeline, which build and deploy the lib to a private registry. There, we can not deploy a new lib with an existing name, so we need to increase the version for each deploy:
lib-app-0.0.3 (current version)
lib-app-0.0.2
lib-app-0.0.1
for thix example, we should deploy the lib-app-0.0.4
.
So, I created another pipeline, which only increase the version of the project, which contain a script:
git config --global user.email "alex@company.com"
git add .
$BranchName = $(Build.SourceBranch)" -replace "refs/heads/"
npm version patch
git push origin HEAD:$BranchName --force
This will works perfect if is triggered manually or after each commit (which I don't want, because a PR can contains 10 commits, so a lot of version numbers will be skipped). But I need it to be triggered only when I create the PR, or better, only when the PR is completed.
Problem: I can not trigger it when PR is completed, because in that time, the changes are already on main and the principal pipeline will be fired (build & deploy main branch !!! without increasing the version - because we can not push code directly into main)
So I thought of something: use the increase version
pipeline as a Build Validator for this repository. So I just create a PR and then the pipeline will be executed. Partially correct, but here I found another problem: the pipeline will COPY (using mirroring I think) the repository, increase the version, but not push the package.json
with updates to the repository because have limited permissions)
! [remote rejected] HEAD -> refs/pull/13554/merge (The current action can only be performed by the system)
error: failed to push some refs to 'https://dev.azure.com/org/repo'
Oh, I already set all permissions in repo settings (for both, source & target branches) for the organization.
I'm not sure if there is a solution ... how you solve something like that? thanks