Currently, I have a GitHub action job where it updates the version of the NPM package, commits the changes, and pushes to the remote repo.
Here is the job responsible for this part:
update_package_version:
runs-on: ubuntu-latest
permissions: # Job-level permissions configuration starts here
contents: write # 'write' access to repository contents
pull-requests: write # 'write' access to pull requests
steps:
- name: Checkout repository
uses: actions/[email protected]
- name: Update package
run: |
local_branch_name=$(git rev-parse --abbrev-ref HEAD)
github_branch_name=${{ github.ref }}
git config --global user.email ${{vars.UserEmail}}
git config --global user.name ${{vars.UserName}}
if [[ $local_branch_name =~ --Major$ || $github_branch_name =~ --Major$ ]]; then
echo "Updating package.json version to a major release"
npm version major --no-git-tag-version
elif [[ $local_branch_name =~ --Minor$ || $github_branch_name =~ --Minor$ ]]; then
echo "Updating package.json version to a minor release"
npm version minor --no-git-tag-version
elif [[ $local_branch_name =~ --Patch$ || $github_branch_name =~ --Patch$ ]]; then
echo "Updating package.json version to a patch release"
npm version patch --no-git-tag-version
else
echo "No version update required for the current branch"
fi
git add package.json
git add package-lock.json
git commit -m "Update package.json version" --allow-empty
git push --verbose
The problem with the job above is that when it comes to pushing, it keeps on pushing and nothing happens. I get the following output and it never ends:
| [test-pipeline–Minor ee02442] Update package.json version| 2 files changed, 6284 insertions(+), 6284 deletions(-)
| Pushing to https://github.com/%7Borganization_name%7D/%7Brepo_name%7D
I checked that there are no branch protection rules yet still the same result.
Important notes:
-
I test out the GitHub action locally using
act
-
The branch name is test-pipeline–Minor
-
The configured user email and user name are as the git configs I have locally on my PC and they are also the same as my GitHub account
-
The workflow is set on
workflow_dispatch
and the main branch doesn’t have GitHub actions yet all of this is done on other branches -
If I used the
git add.
command instead of adding thepackage.json
andpackage-lock.json
I get a lot of files committed which I have no explanation for.