Next, we create another GitHub action file called. That's why this approach works very well because then the CI pipelines are not incrementing the version number on every little change, but rater when we release bug fixes and features or in other words when we merge a pull request. So we are not always directly committing and pushing to the main branch. This is also known as the pull request model. ![]() Note: We internally as a team are working with the feature branching approach as a pattern for managing the source code. This helps us to determine that this new commit is created by the pipeline and not by a user. Furthermore, using the parameter -m we can define the custom prefix for the commit message generated by this command. #Npm install from github with version number Patch#We also tell the npm version command to only make a patch release and so only increment the last number of the version string. ![]() In this example we used the variable name GH_PERSONAL_ACCESS_TOKEN to store and reference the token. The token must be stored as a secret in the GitHub repository. If we would not provide a personal access token for the checkout action, then the GitHub actions would not be started for the commit that is pushed by this GitHub action. #Npm install from github with version number code#In addition, you have to adjust the checkout action to clone the code using a personal GitHub access token that has repo permissions. By checking every commit message for the prefix, we can make sure that we only increment the version number for commits generated by a user. github/workflows/version.yml that increments the version number:ħ 8 jobs : 9 version : 10 runs-on : ubuntu - latestġ1 if : "!startsWith(_ssage, '')" 12 steps : 13 - uses : with : 15 token : $ 16 - run : git config - global user.name 'AboutBits Tech'ġ7 - run : git config - global user.email - run : npm version patch - m " %s"Īs you can see from the code, the steps get only executed for commits on the main branch that do not start with the prefix "". Workflow 1 - Increment Version and Push Changesįirst, we create a GitHub action file called. In order to overcome this problem, we create two separate GitHub action workflow files with two distinct responsibilities. Since the npm version command makes changes to the codebase and creates a new commit, we have to deal with two separate commits that run both their own GitHub action jobs. However, this brings also some problems with it. This command increments the currently given version number inside the package.json file and commits the modified file with a Git commit. To avoid that developers forget to increment the version number by hand, we automated this process especially for web applications by using the built-in command from NPM called npm version. We show this version number to the user on the website, and it helps us for debugging purposes and bug reports. ![]() One of our prerequisites before releasing a web application is, that we always want to increment automatically the application version number. Lately, we switched to GitHub actions to test and deploy our libraries and applications.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |