Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hardnorth/github-version-generate
A GitHub action for application version bump, generation, reading and format in release pipelines
https://github.com/hardnorth/github-version-generate
actions bump bump-version bumping bumpversion generate github prerelease release release-automation release-pipelines version versioning
Last synced: 3 months ago
JSON representation
A GitHub action for application version bump, generation, reading and format in release pipelines
- Host: GitHub
- URL: https://github.com/hardnorth/github-version-generate
- Owner: HardNorth
- License: apache-2.0
- Created: 2020-06-25T06:02:20.000Z (over 4 years ago)
- Default Branch: develop
- Last Pushed: 2024-06-16T13:01:04.000Z (8 months ago)
- Last Synced: 2024-10-10T23:49:36.477Z (4 months ago)
- Topics: actions, bump, bump-version, bumping, bumpversion, generate, github, prerelease, release, release-automation, release-pipelines, version, versioning
- Language: JavaScript
- Homepage:
- Size: 1.33 MB
- Stars: 23
- Watchers: 2
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Version generation and bumping for GitHub Actions
[![CI Build](https://github.com/HardNorth/github-version-generate/actions/workflows/ci.yml/badge.svg)](https://github.com/HardNorth/github-version-generate/actions/workflows/ci.yml)
[![License](https://img.shields.io/badge/License-Apache%202.0-brightgreen.svg)](https://opensource.org/licenses/Apache-2.0)> Please star this repository if you like the application, it will help more people see it. Thank you!
A GitHub action for reading, bumping, generating, formatting applications versions in release pipelines.
Outputs four environment / output variables:- 'env.CURRENT_VERSION' - a current, extracted version of application without any changes
- 'env.RELEASE_VERSION' - a generated release version with `SNAPSHOT` suffix removed by default
- 'env.NEXT_VERSION' - a new version supposed to put into version source file instead of CURRENT_VERSION
- 'env.NEXT_RELEASE_VERSION' - the same new version with `SNAPSHOT` suffix removed by defaultAlso, there are 5 postfixes for environment variables listed above:
- '_MAJOR'
- '_MINOR'
- '_PATCH'
- '_PRERELEASE'
- '_BUILDMETADATA'They contain corresponding version fragments, so for release version `5.0.3` environment / output variable
`RELEASE_VERSION_PATCH` will contain `3`.The action uses so-called "[Semantic version](https://semver.org/)" system, please check out the
specification first to avoid misunderstanding and misuses.By default, the action increments prerelease version. Basically it picks a number in a substring starting with
alpha|beta|rc + a number. It also possible to notate all caps or starting with a capital letter (ALPHA, alpha and Alpha
are OK).E.G.:
- TESTNG7-BETA-7-SNAPSHOT → TESTNG7-BETA-8-SNAPSHOT
- rc1 → rc2
- TESTNG6-Alpha1 → Alpha2Here are some prerelease fragments and a regex which is used to extract the prerelease number:
https://regex101.com/r/O5GUdN/2If there is no regex match in prerelease section the patch version fragment will be incremented. You
can force action increment a specific version fragment you like by configuring [Next version](#next-version) parameters.
If any of such parameters was specified the default behavior will be ignored.## Usage
To use the action introduce it into your job steps of a github actions workflow.
### Example 1: Java application built with gradle
A pretty simple pipeline which launches a release task. To update development version back in a release branch Gradle
release plugin needs at least one parameter specified (`release.newVersion`). This pipeline provides gradle both
necessary versions: which to release and which to commit back into the release branch.```yaml
name: Releaseon:
push:
branches:
- 'master'jobs:
build:
runs-on: ubuntu-lateststeps:
- name: Checkout repository
uses: actions/checkout@v3- name: Set up JDK 1.8
uses: actions/setup-java@v3
with:
distribution: 'temurin'
java-version: '8'- name: Generate versions
uses: HardNorth/[email protected]
with:
version-source: file
version-file: gradle.properties
version-file-extraction-pattern: '(?<=version=).+'- name: Grant execute permission for gradlew
run: chmod +x gradlew- name: Release with Gradle
id: release
run: |
./gradlew release -Prelease.useAutomaticVersion=true \
-Prelease.releaseVersion=${{ env.RELEASE_VERSION }} \
-Prelease.newVersion=${{ env.NEXT_VERSION }}
```### Example 2: A specific version fragment incrementation
The pipeline demonstrates how you can control which version fragment to increment by a file with a specific keyword:
```yaml
name: releaseon:
push:
branches:
- masterenv:
VERSION_FILE_NAME: 'VERSION'
VERSION_BUMP_FILE: 'version_fragment'
jobs:
calculate-version:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v3- name: Get version fragment to bump
id: getVersionFragment
run: |
read -r versionFragment < ${{ env.VERSION_BUMP_FILE }}
echo "'$versionFragment' version will be incremented"
echo "::set-env name=VERSION_FRAGMENT::${versionFragment}"- name: Generate versions
uses: HardNorth/[email protected]
with:
version-source: file
version-file: ${{ env.VERSION_FILE_NAME }}
next-version-increment-patch: ${{ contains(env.VERSION_FRAGMENT, 'patch') }}
next-version-increment-minor: ${{ contains(env.VERSION_FRAGMENT, 'minor') }}
next-version-increment-major: ${{ contains(env.VERSION_FRAGMENT, 'major') }}
```If the content of the `version_fragment` file will be "minor" then minor version will be incremented respectively.
## Configuration
### Version sources
| Parameter | Type | Default value | Description |
|---------------------------------|----------------------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| version-source | enum{file, variable} | variable | A source of a CURRENT_VERSION |
| version | string | | A version variable for version source |
| version-file | string | | A path to a file which holds a version |
| version-file-extraction-pattern | string | .+ | A RegEx to extract version from a version-source file. Should either match a full version, or return it as the first group. E.G:
- `(?<=version=).+` - pattern match, e.g: 'version=5.0.3-SNAPSHOT' will extract matched string '5.0.3-SNAPSHOT'
- `"version":\s*"([^"]+)"` - group match, will extract the first group. e.g: '"version": "1.0.0",' to '1.0.0'
### Release version
| Parameter | Type | Default value | Description |
|-----------------------------------------|---------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| release-version-cut-snapshot | boolean | true | Remove "SNAPSHOT" suffix from source version |
| release-version-cut-build-metadata | boolean | true | Remove build metadata suffix from source version |
| release-version-cut-prerelease | boolean | false | Remove prerelease part from source version |
| release-version-generate-build-metadata | boolean | false | Put build metadata (release date, commit sha, etc.) into result RELEASE_VERSION |
| release-version-build-metadata-pattern | string | build.{date}.{hash} | Format pattern for build metadata. EG: `build.{date[YYYY-MM-dd]}.{hash[0, 6]}`. It is also possible not to customize variable outputs omitting square braces ([]) or even not to use any variables. Supported variables:
- `date[date_format]`: a current date in UTC or time set in 'release-version-build-metadata-datetime' variable. Supports formatting included in square braces ([]). The date format will be applied by "Moment.js". Default format is `['YYYY-MM-DD']`.
Library: https://momentjs.com/ - `hash[begin_index_inclusive, end_index_exclusive]`: a commit hash, which triggered this build. You can shorten the hash by specifying begin and end characters indexes included in square braces ([]), separated by a comma. Default begin, end values are: `[0, 8]`. |
| release-version-build-metadata-datetime | string | | A time stamp in ISO format to put into a build metadata string, by default the action uses current time in UTC timezone |### Next version
| Parameter | Type | Default value | Description |
|-----------------------------------|---------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------|
| next-version-increment-major | boolean | false | Increment major version in result NEXT_VERSION, resets all other versions to "0" and prerelease to "1" if found. E.G.: `5.0.3-BETA-3` → `6.0.0-BETA-1` |
| next-version-increment-minor | boolean | false | Increment minor version in result NEXT_VERSION, resets patch to "0" and prerelease to "1" if found. E.G.: `5.0.3-BETA-3` → `5.1.0-BETA-1` |
| next-version-increment-patch | boolean | false | Increment patch version in result NEXT_VERSION, resets prerelease to "1" if found. E.G.: `5.0.3-BETA-3` → `5.0.4-BETA-1` |
| next-version-increment-prerelease | boolean | false | Increment prerelease version in result NEXT_VERSION. E.G.: `5.0.3-BETA-3` → `5.0.3-BETA-4` |
| next-version-cut-prerelease | boolean | false | Remove prerelease part from source version. In case this parameter is set the action increments patch version by default. |
| next-version-cut-build-metadata | boolean | true | Remove build metadata suffix from source version |
| next-version-put-build-metadata | boolean | false | Put build metadata (release date, commit sha, etc.) into result NEXT_VERSION. Will be the same as for RELEASE_VERSION' |### Data extract
Built-in data extraction mechanism.
Example:
```yaml
data-extract: true
data-extract-name: 'first_variable'
data-extract-paths: '/path/to/file'
data-extract-patterns: '/(?<=variable.name=).+/i'
```There are several use cases depending on RegEx format and flags:
* RegEx Match only - As on example, above. Variable name in 'data-extract-name' parameter will be used 'as is',
variable value will be set on matched text. Extraction will fail if 'data-extract-name' is not set.
* One group - Variable name in 'data-extract-name' parameter will be used 'as is', variable value will be set on
group value. Extraction will fail if 'data-extract-name' is not set.
* Two or more groups - If 'data-extract-name' value is set then the first group will be used as value, and other
groups will be ignored, if it's not set, then the first group will used as variable name and the second group
will be used as value.
* Multiple match (multiple RegEx, 'g' flag in RegEx is set, etc) - If 'data-extract-name' value is set the action
will extract all RegEx matches and export variables with underscore and variable index as suffix, except the
first one.
E.G.: first_variable -> FIRST_VARIABLE, FIRST_VARIABLE_1, etc; If 'data-extract-name' value is not set then
two groups in every RegEx is a requirement, the first group will used as variable name and the second group will
be used as value. If multiple files have the same variable names, output values will be overwritten with the
latter matches.Variable name convert rules:
* Spaces and symbols '-', even multiple in a row, will be converted to single symbol '_';
* Other special characters except digits and letters will be cut off;
* The variable name will be converted to upper case.| Parameter | Type | Default value | Description |
|---------------------------------|---------|---------------|-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| data-extract | boolean | false | Enable data extraction mechanism |
| data-extract-name | string | null | Variable name to which extracted data will be placed, standard variable name conversion rules are also applied to this field. If not set it will be extracted from RegEx groups. See usage use cases above. |
| data-extract-paths | string | null | Semicolon (";") separated path list of files which to use to extract data |
| data-extract-patterns | string | null | Semicolon (";") separated RegEx pattern list wrapped with "/" symbols, with flags |### Real-life examples
- The action builds using itself, check
out [Release](https://github.com/HardNorth/github-version-generate/blob/master/.github/workflows/release.yml)
pipeline.
- [Report Portal](https://reportportal.io/) uses the action to build its agents.
E.G.: [JUnit](https://github.com/reportportal/agent-java-junit/blob/master/.github/workflows/release.yml)### License
Apache License Version 2.0 - [repo link](https://github.com/HardNorth/github-version-generate/blob/master/LICENSE).
### Credits
The action was created by [Vadzim Hushchanskou](https://github.com/HardNorth)
at [HardNorth/github-version-generate](https://github.com/HardNorth/github-version-generate)