12

I would like to use a pure solution in a GitHub action to increment a version of the package. I don't want to use any existing actions from the GitHub marketplace such as "gh-action-bump-version ". I have this workflow, which will increase the version and create a tag.

name: Version Increment on: push: branches: - main tags-ignore: - v* jobs: version: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 with: token: ${{ secrets.ACCESS_TOKEN }} - run: git config user.email "[email protected]" - run: git config user.name "$GITHUB_ACTOR" - run: npm version minor -m "v%s" - run: VERSION=$(node -p "require('./package.json').version") - run: git tag ${VERSION} - run: git push origin --tags - run: git push origin --follow-tags 

It works, but it also cause a circular runs of the actions because of the last row. I know that I can use a custom message like "[RELEASE]" and put there a "if" condition and skip these commits. But my question is, is there any better solution to skip these commits from this action and do not use the "if" condition? Because the "tags-ignore" obviously doesn't work.

1
  • 2
    tags-ignore wouldn't work because you tell the action to run on commits pushed to master, while tags-ignore only works when you let the action run on tags pushed. Commented Sep 27, 2021 at 11:13

3 Answers 3

16

So I found several solutions. The first is that you can put "[skip actions]" to your commit message and that commit will skip any github action that should run within the commit. The second one is to use an address of the repository with access token.

This works pretty well for me:

name: Version Increment on: push: branches: - main jobs: version: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: git config user.email "[email protected]" - run: git config user.name "$GITHUB_ACTOR" - run: npm version minor -m "v%s" - run: VERSION=$(node -p "require('./package.json').version") - run: git tag ${VERSION} - run: git push "https://$GITHUB_ACTOR:${{ secrets.ACCESS_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --follow-tags - run: git push "https://$GITHUB_ACTOR:${{ secrets.ACCESS_TOKEN }}@github.com/$GITHUB_REPOSITORY.git" --tags 
Sign up to request clarification or add additional context in comments.

1 Comment

Note that you don't need the last line here to push tags since the one just before it has the --follow-tags option.
10

Try using the built in GITHUB_TOKEN instead of your custom ACCESS_TOKEN. That should prevent the workflow from triggering another workflow.

From the docs (https://docs.github.com/en/actions/using-workflows/triggering-a-workflow#triggering-a-workflow-from-a-workflow):

When you use the repository's GITHUB_TOKEN to perform tasks, events triggered by the GITHUB_TOKEN will not create a new workflow run. This prevents you from accidentally creating recursive workflow runs. For example, if a workflow run pushes code using the repository's GITHUB_TOKEN, a new workflow will not run even when the repository contains a workflow configured to run when push events occur.

Comments

1

Add one of:

  • [skip ci]
  • [ci skip]
  • [no ci]
  • [skip actions]
  • [actions skip]

to commit message, this will prevent another run for this commit.

Add it to your code here: - run: npm version minor -m "[ci skip] v%s"

source: https://docs.github.com/en/actions/managing-workflow-runs/skipping-workflow-runs

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.