-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
732 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
--- | ||
name: Test and Release | ||
|
||
on: | ||
push: | ||
branches: | ||
- '**' | ||
tags-ignore: | ||
- '**' | ||
|
||
jobs: | ||
lint: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Run ShellCheck | ||
uses: ludeeus/action-shellcheck@94e0aab03ca135d11a35e5bfc14e6746dc56e7e9 | ||
with: | ||
check_together: 'yes' | ||
|
||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Setup bats | ||
uses: mig4/setup-bats@af9a00deb21b5d795cabfeaa8d9060410377686d | ||
with: | ||
bats-version: 1.2.1 | ||
|
||
- name: Test | ||
run: bats tests/*.bats | ||
|
||
release: | ||
needs: | ||
- lint | ||
- test | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v2 | ||
|
||
- name: Lookup version | ||
id: version-lookup | ||
run: ./version-lookup.sh | ||
|
||
- name: Increment version | ||
id: version-increment | ||
run: ./version-increment.sh | ||
env: | ||
current_version: ${{ steps.version-lookup.outputs.current-version }} | ||
INPUT_SCHEME: calver | ||
|
||
- name: Release version | ||
uses: marvinpinto/action-automatic-releases@919008cf3f741b179569b7a6fb4d8860689ab7f0 | ||
if: ${{ github.ref == 'refs/heads/main' }} | ||
with: | ||
repo_token: "${{ secrets.GITHUB_TOKEN }}" | ||
draft: false | ||
prerelease: false | ||
automatic_release_tag: "${{ steps.version-increment.outputs.version }}" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
# ➕ Version Increment | ||
|
||
## 📄 Use | ||
|
||
### ⌨️ Example | ||
|
||
```yaml | ||
- name: Get next version | ||
uses: reecetech/version-increment | ||
id: version | ||
with: | ||
scheme: semver | ||
increment: patch | ||
|
||
- name: Build image | ||
uses: docker/build-push-action@v2 | ||
with: | ||
push: false | ||
tags: "example/application:${{ steps.version.outputs.version }}" | ||
context: . | ||
``` | ||
### 🔖 semver | ||
This action will detect the current latest _normal_ semantic version (semver) from the tags in | ||
a git repository. It will increment the version as directed (by default: +1 to | ||
the patch digit). Both the current latest and the incremented version are | ||
reported back as outputs. | ||
Normal semantic versions are made up of a major, minor and patch digit. Normal | ||
versions do not include pre-release versions, or versions with build meta-data. | ||
e.g. `1.2.7` | ||
|
||
See: https://semver.org/spec/v2.0.0.html | ||
|
||
### 📅 calver (semver compliant) | ||
|
||
Optionally, this action can provide semver compliant calendar versions (calver). | ||
In this calver scheme, the semver major, minor and patch digits map to year, | ||
month and release digits. | ||
|
||
Note: to be semver compliant, digits must not have leading zeros. | ||
|
||
e.g. `2021.6.2` | ||
|
||
| semver | calver | example | note | | ||
| :--- | :--- | :--- | :--- | | ||
| major | year | `2021` | | ||
| minor | month | `6` | | ||
| patch | release | `2` | The *n*th release for the month | | ||
|
||
If the current latest normal version is not the current year and month, then the year and month digits will be | ||
set to the current year and month, and the release digit will be reset to 1. | ||
|
||
### 🎋 Default branch vs. any other branch | ||
|
||
**Default branch** | ||
|
||
The action will return a _normal_ version if it is detected that the current commit is on the default branch (usually `main`). | ||
|
||
Examples: | ||
* `1.2.7` | ||
* `2021.6.2` | ||
|
||
**Any other branch** | ||
|
||
The action will return a _pre-release_ version if any other branch is detected (e.g. `new-feature`, `bugfix/foo`, etc). The _pre-release_ portion of the version number will be the literal string `pre.` followed by the git commit ID short reference SHA (trimmed of any leading zeros). | ||
|
||
Examples: | ||
* `1.2.7-pre.41218aa78` | ||
* `2021.6.2-pre.32fd19841` | ||
|
||
### 📥 Inputs | ||
|
||
| name | description | required | default | | ||
| :--- | :--- | :--- | :--- | | ||
| scheme | The versioning scheme in-use, either `semver` or `calver` | No | `semver` | | ||
| increment | The digit to increment, either `major`, `minor` or `patch`, ignored if `scheme` == `calver` | No | `patch` | | ||
|
||
### 📤 Outputs | ||
|
||
| name | description | | ||
| :--- | :--- | | ||
| current_version | The current latest version detected from the git repositories tags | | ||
| version | The incremented version number (e.g. the next version) | | ||
|
||
## 💕 Contributing | ||
|
||
Please raise a pull request, but note the testing tools below | ||
|
||
### bats | ||
|
||
BATS is used to test the logic of the shell scripts. | ||
|
||
See: https://github.com/bats-core/bats-core | ||
|
||
### shellcheck | ||
|
||
Shellcheck is used to lint our shell scripts. | ||
|
||
Please use [local ignores](https://stackoverflow.com/a/52659039) if you'd like to skip any particular checks. | ||
|
||
See: https://github.com/koalaman/shellcheck |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
--- | ||
name: 'Version Increment' | ||
description: | | ||
Inspects the git tags to determine the current normal version, and returns the | ||
next version number. | ||
A normal version will be returned if the branch is the default branch | ||
(usually `main`), otherwise a pre-release version will be returned. | ||
inputs: | ||
scheme: | ||
description: 'Versioning scheme - semver, or, calver (defaults to semver)' | ||
required: false | ||
default: 'semver' | ||
increment: | ||
description: | | ||
Field to increment - major, minor, or, patch (defaults to patch) | ||
Not applicable to `calver` scheme | ||
required: false | ||
default: 'patch' | ||
|
||
outputs: | ||
current_version: | ||
description: 'Current normal version detected' | ||
value: ${{ steps.version-lookup.outputs.current-version }} | ||
version: | ||
description: 'Incremented version calculated' | ||
value: ${{ steps.version-increment.outputs.version }} | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- id: version-lookup | ||
run: ${{ github.action_path }}/version-lookup.sh | ||
shell: bash | ||
|
||
- id: version-increment | ||
run: ${{ github.action_path }}/version-increment.sh | ||
shell: bash | ||
with: | ||
current_version: ${{ steps.version-lookup.outputs.current-version }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#!/bin/bash | ||
# shellcheck disable=SC2034 | ||
set -euo pipefail | ||
|
||
# see: https://semver.org/spec/v2.0.0.html#is-there-a-suggested-regular-expression-regex-to-check-a-semver-string | ||
pcre_semver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)(?:-(?P<prerelease>(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*)(?:\.(?:0|[1-9]\d*|\d*[a-zA-Z-][0-9a-zA-Z-]*))*))?(?:\+(?P<buildmetadata>[0-9a-zA-Z-]+(?:\.[0-9a-zA-Z-]+)*))?$' | ||
pcre_master_ver='^(?P<major>0|[1-9]\d*)\.(?P<minor>0|[1-9]\d*)\.(?P<patch>0|[1-9]\d*)$' | ||
pcre_allow_vprefix="^v{0,1}${pcre_master_ver:1}" | ||
pcre_old_calver='^(?P<major>0|[1-9]\d*)-0{0,1}(?P<minor>0|[0-9]\d*)-R(?P<patch>0|[1-9]\d*)$' | ||
|
||
##==---------------------------------------------------------------------------- | ||
## MacOS compatibility - for local testing | ||
|
||
export grep="grep" | ||
if [[ "$(uname)" == "Darwin" ]] ; then | ||
export grep="ggrep" | ||
if ! grep --version 1>/dev/null ; then | ||
echo "🛑 GNU grep not installed, try brew install coreutils" 1>&2 | ||
exit 9 | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
#!/usr/bin/env bash | ||
# vim: set ft=sh sw=4 : | ||
|
||
# shellcheck disable=SC2154 | ||
|
||
function print_run_info() { | ||
echo "status: ${status}" | ||
echo "output: ${output}" | ||
} |
Oops, something went wrong.