This question is very close to this 3 year old question from 2019.
I'm seeking advise/reference to a bot/github action that semver bumps up the package.json version (as a commit) on merge/rebase pending on the labels major, minor or patch that the PR has.
You can test out Konsentus/action.bump-version-and-tag:
This action will find the last version tag made on the current branch, bump it and tag the current commit with the new version.
If a package.json file is present, the version contained will also be bumped to the same version as the tag.
As tags are commit specific and not branch specific, these version tags are prefixed with the current branch name, e.g. master/v1.0.0.
Example
name: Bump Version and Tag
on:
push:
branches:
- 'master'
- 'sit'
- 'alpha'
- 'sandbox'
jobs:
bump-and-tag:
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
name: Bump and Tag
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v2
with:
fetch-depth: 0
- name: Get Tags
run: git fetch origin +refs/tags/*:refs/tags/*
- name: Bump Version
id: bump_and_tag
uses: konsentus/action.bump-version-and-tag#v2
Related
Currently, when I have a new release on a GitHub repo, I need to update all the readme with the new tag.
Example of readme.md (version 1.0.0):
My Java library project
You need to add
`implementation io.github.me:javalib:1.0.0`
And I update the readme to (version 2.0.0):
My Java library project
You need to add
`implementation io.github.me:javalib:2.0.0`
But this manual update is fastidious and sometimes I forgot some tag when I update the documentation.
How can we can automate that?
You can automatize that with a GitHub Action like this:
Requirements
You need to give permission to your GitHub Actions to create a pull request in your GitHub repo settings (Settings -> Actions -> General).
GitHub Actions examples
These GitHub Actions get automatically the tag of the new release and update your readme with the old tag with the new tag.
Update the readme with a pull request
name: Update files
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Update files
uses: MathieuSoysal/file-updater-for-release#v1.0.1
with:
files: README.md # List of files to update
prefix: "io.github.me:javalib:" # Prefix before the version in your cas is io.github.me:javalib:
- name: Create Pull Request
uses: peter-evans/create-pull-request#v4
with:
token: ${{ secrets.GITHUB_TOKEN }} # You need to create your own token with pull request rights
commit-message: update readme
title: Update readme
body: Update readme to reflect release changes
branch: update-readme
base: main
Update the readme directly with a commit
name: Update files with commit
on:
release:
types: [published]
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
with:
fetch-depth: 0
token: ${{ secrets.GITHUB_TOKEN }} # You need to create your own token with commit rights
ref: main # The branch you want to commit to
- name: Update files
uses: MathieuSoysal/file-updater-for-release#v1.0.1
with:
files: README.md # List of files to update
prefix: "io.github.me:javalib:" # Prefix before the version in your cas is io.github.me:javalib:
with-checkout: false # If you don't want to checkout the repo, default is: true
- name: Push changes
uses: EndBug/add-and-commit#v9
with:
committer_name: GitHub Actions
committer_email: actions#github.com
add: .
message: 'update files'
Source
file-updater-for-release
I have the following action set up in my private GitHub repo:
# This workflow will do a clean install of node dependencies, build the source code and run tests across different versions of node
# For more information see: https://help.github.com/actions/language-and-framework-guides/using-nodejs-with-github-actions
name: Node.js CI
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
build:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.17.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- run: yarn install --frozen-lockfile
- run: yarn test
Previously, the node-version was set to [15.x] and everything worked wonderfully. Since updating the required Node version to 14.17.x I have a check in my PRs that never resolves. It says:
build (15.x) Expected — Waiting for status to be reported Required
What am I missing here? It’s almost as if something is cached.
The issue ended up being a required status check that was added in “Settings » Branches » Require status checks to pass before merging » Require branches to be up to date before merging”. I removed that status check and re-added the updated version, then the message disappeared from the Checks list in all open PRs.
My scenario: I am in a repo1 (that is where I have this workflow file) and trying to pull repo 2 (both are in the same organization) from repo 1 with the following code:
- name: Checkout aaa-frontend repo
uses: actions/checkout#v2
with:
repository: Orgn1-Global/aaa-frontend
path: develop
token: ${{ github.token }}
From the below error, I assume that, it is able to locate the repository but only has a problem in locating the branch. Is this correct?
Run actions/checkout#v2
Syncing repository: Orgn1-Global/aaa-frontend
Getting Git version info
Initializing the repository
Disabling automatic garbage collection
Setting up auth
Determining the default branch
Retrieving the default branch name
Not Found
Waiting 17 seconds before trying again
Retrieving the default branch name
Not Found
Waiting 12 seconds before trying again
Retrieving the default branch name
Error: Not Found
and what's the right way to pull the 'main' branch of repo 2 from this repo 1?
If I understand your requirement correctly, do you want to checkout repo1 and repo2 in the repo1 action workflow ?
If Yes - It has to be like this:
# checkout of repo1 - where you have your workflow file
- name: Checkout
uses: actions/checkout#v2
with:
path: main
# checkout repo2 in a folder called my-tools
- name: Checkout tools repo
uses: actions/checkout#v2
with:
repository: my-org/repo2
path: my-tools
you can always find an awesome examples in Github action public repository. Here is the checkout one.
Below piece of code should fetch you main branch of aaa-frontend repo
- name: Checkout aaa-frontend repo
uses: actions/checkout#v2
with:
repository: Orgn1-Global/aaa-frontend
path: develop
token: ${{ github.token }}
ref: main
I want to define a workflow as follows, for a node.js repo:
When new code is merged into master AND version in package.json is changed, create a new Github release for that version
When a new Github release is created, publish package to NPM
What I hope to achieve is that in our most typical workflow (PR merged to master) a release s created and package is automatically uploaded to NPM but to also be able to trigger an upload to NPM directly from a feature branch (usually a pre-release version, 1.0.3-rc1) by manually creating a release from such branch.
I've set up two Github workflows, each with a single job.
The first:
name: Create release on new version merge
on:
push:
branches:
- master
jobs:
release-on-new-version:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Check for version change
id: check
uses: EndBug/version-check#v1
with:
file-url: ::before
static-checking: localIsNew
token: ${{ secrets.GITHUB_TOKEN }}
- name: Log when changed
if: steps.check.outputs.changed == 'true'
run: 'echo "Version change found: ${{ steps.check.outputs.version }}"'
- name: Create Release
if: steps.check.outputs.changed == 'true'
id: create_release
uses: actions/create-release#v1
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
with:
tag_name: v${{ steps.check.outputs.version }}
release_name: v${{ steps.check.outputs.version }}...
The second:
name: Publish on new release
on:
release:
types: created
jobs:
publish-on-release:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: actions/setup-node#v1
with:
node-version: 10
registry-url: https://registry.npmjs.org/
- run: npm publish
env:
NODE_AUTH_TOKEN: ${{secrets.npm_token}}
Individually these workflows work as expected: When I merge some work onto master that changes the version number a release is created, and when I manually create a release it gets published to NPM. However I would also expect the release created as the effect of the first workflow to trigger the second flow and therefore when I merge a version change into master eventually automatically see it published to NPM. But to my amazement that does not happen. Is there some sort of mechanism that prevents the effects of one job to (indirectly) trigger another? Or am I missing something?
You might consider to explicitly mention the dependency of one job needed another job, using needs.
You can see that approach illustrated with:
"GitHub Actions: Dependent Jobs" from Edward Thomson (who is also on Stack Overflow)
That would allow to define a third action which would need the first two, forcing them to be chained in their execution.
I have the following action on Github actions that automatically packs and deploy a package to nuget.org every time a PR gets merged into master.
name: Nuget Deploy
on:
push:
branches: [ master ]
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout#v2
- name: Setup .NET Core
uses: actions/setup-dotnet#v1
with:
dotnet-version: 3.1.101
- name: Generate Nuget package
run: dotnet pack
working-directory: DateOverride
- name: Deploy to nuget.org
run: dotnet nuget push *.nupkg -k ${{ secrets.NUGET_DEPLOY_KEY }} -s https://api.nuget.org/v3/index.json
working-directory: DateOverride/DateOverride/bin/Debug
But I would like that it was not run if my update is only a README.md update, is it possible to do so?
I'd think the paths-ignore setting should help:
on:
push:
branches:
- master
paths-ignore:
- '**/README.md'
You might want to combine your current GitHiub Action with another like MarceloPrado/has-changed-path
This action outputs whether a path or combination of paths has changed in the previous commit.
[This] action is meant to be used inside your job steps, not at the root of your workflow file
Or (opposite filter): dorny/paths-filter
With this Github Action you can execute your workflow steps only if relevant files are modified.