Skip to content

Commit

Permalink
Merge pull request #69 from wemogy/main
Browse files Browse the repository at this point in the history
Release
  • Loading branch information
Bennet Ranft authored Apr 26, 2024
2 parents 33e7279 + 2258922 commit 54cfbc6
Show file tree
Hide file tree
Showing 16 changed files with 548 additions and 35 deletions.
12 changes: 12 additions & 0 deletions .github/actions/local-action/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,14 @@ inputs:
description: "Create a Git Tag for the version and push it if a remote is configured."
required: false
default: "true"
git-username:
description: "The username for creating the (annotated) git tag. Use `NONE` for no username."
required: false
default: "NONE"
git-email:
description: "The email address for creating the (annotated) git tag. Use `NONE` for no email address."
required: false
default: "NONE"
mode:
description: "The mode to use for determining the next version. Possible values: `semantic`, `hash-based`."
required: false
Expand Down Expand Up @@ -57,5 +65,9 @@ runs:
- ${{ inputs.only-bump-suffix }}
- --create-tag
- ${{ inputs.create-tag }}
- --git-username
- ${{ inputs.git-username }}
- --git-email
- ${{ inputs.git-email }}
- --mode
- ${{ inputs.mode }}
7 changes: 2 additions & 5 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,13 @@ jobs:
with:
fetch-depth: 0

- name: Setup git
run: |
git config user.email "[email protected]"
git config user.name "wemogy IT"
- name: Get version for next release
id: get-release-version
uses: ./.github/actions/local-action
with:
create-tag: "true"
git-username: "wemogy IT"
git-email: "[email protected]"

- name: Build Containers
uses: ./.github/actions/containers
Expand Down
5 changes: 0 additions & 5 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ jobs:
- name: Setup Python
uses: ./.github/actions/setup-python

- name: Setup git
run: |
git config --global user.email "[email protected]"
git config --global user.name "Wemogy IT"
- name: Run pytest
run: poetry run pytest --junit-xml test-result.xml tests/e2e

Expand Down
38 changes: 19 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,20 +11,18 @@ for [Conventional Commits](https://www.conventionalcommits.org/) with support fo
with:
fetch-depth: 0

- name: Setup git for annotated tags
run: |
git config user.email "[email protected]"
git config user.name "Your username"
- uses: wemogy/[email protected]
- uses: wemogy/[email protected]
id: get-release-version
with:
prefix: "v"
suffix: "beta"
reference-version-suffix: "dev"
suffix: "NONE"
reference-version-suffix: "NONE"
bumping-suffix: "hotfix"
only-bump-suffix: "true"
only-bump-suffix: "false"
create-tag: "true"
git-username: "Your User"
git-email: "[email protected]"
mode: "semantic"

- run: echo ${{ steps.get-release-version.outputs.version }}
- run: echo ${{ steps.get-release-version.outputs.version-name }}
Expand All @@ -35,20 +33,22 @@ for [Conventional Commits](https://www.conventionalcommits.org/) with support fo
### Inputs
| Input | Required | Default | Description |
| -------------------------- | -------- | ---------- | -------------------------------------------------------------------------------------------------------- |
| `prefix` | `false` | `v` | The prefix that should be prepended to the version. |
| `suffix` | `false` | `NONE` | The suffix that should be appended to the version (e.g. `beta`). Use `NONE` for no suffix. |
| `reference-version-suffix` | `false` | `NONE` | The suffix that should be replaced with the value in `suffix` (e.g. `dev`). Use `NONE` for no suffix. |
| `bumping-suffix` | `false` | `hotfix` | The suffix to append to the version (or increment if it already exists) if `only-bump-suffix` is `true`. |
| `only-bump-suffix` | `false` | `false` | Bump the `bumping-suffix` instead of the version if changes were detected. |
| `create-tag` | `false` | `true` | Create a git tag for the version and push it if a remote is configured. |
| `mode` | `false` | `semantic` | The mode to use for determining the next version. Possible values: `semantic`, `hash-based`. |
| Input | Required | Default | Description |
|----------------------------|---------------------------|------------|----------------------------------------------------------------------------------------------------------|
| `prefix` | `false` | `v` | The prefix that should be prepended to the version. |
| `suffix` | `false` | `NONE` | The suffix that should be appended to the version (e.g. `beta`). Use `NONE` for no suffix. |
| `reference-version-suffix` | `false` | `NONE` | The suffix that should be replaced with the value in `suffix` (e.g. `dev`). Use `NONE` for no suffix. |
| `bumping-suffix` | `false` | `hotfix` | The suffix to append to the version (or increment if it already exists) if `only-bump-suffix` is `true`. |
| `only-bump-suffix` | `false` | `false` | Bump the `bumping-suffix` instead of the version if changes were detected. |
| `create-tag` | `false` | `true` | Create a git tag for the version and push it if a remote is configured. |
| `git-username` | If `create-tag` is `true` | `NONE` | The username for creating the (annotated) git tag. Use `NONE` for no username. |
| `git-email` | If `create-tag` is `true` | `NONE` | The email address for creating the (annotated) git tag. Use `NONE` for no email address. |
| `mode` | `false` | `semantic` | The mode to use for determining the next version. Possible values: `semantic`, `hash-based`. |

### Outputs

| Output | Description |
| ----------------------- | ----------------------------------------------------------- |
|-------------------------|-------------------------------------------------------------|
| `version` | The next version, without the prefix. |
| `version-name` | The next version, with the prefix. |
| `previous-version` | The previous version, without the prefix. |
Expand Down
18 changes: 15 additions & 3 deletions action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@ inputs:
required: false
default: "v"
suffix:
description: "The suffix that should appended to the version."
description: "The suffix that should appended to the version. Use `NONE` for no suffix."
required: false
default: "NONE"
reference-version-suffix:
description: "The suffix that should be replaced with the value in `suffix`."
description: "The suffix that should be replaced with the value in `suffix`. Use `NONE` for no suffix."
required: false
default: "NONE"
bumping-suffix:
Expand All @@ -26,6 +26,14 @@ inputs:
description: "Create a Git Tag for the version and push it if a remote is configured."
required: false
default: "true"
git-username:
description: "The username for creating the (annotated) git tag. Use `NONE` for no username."
required: false
default: "NONE"
git-email:
description: "The email address for creating the (annotated) git tag. Use `NONE` for no email address."
required: false
default: "NONE"
mode:
description: "The mode to use for determining the next version. Possible values: `semantic`, `hash-based`."
required: false
Expand All @@ -43,7 +51,7 @@ outputs:
description: "If any relevant changes got detected and a tag got created."
runs:
using: "docker"
image: "docker://ghcr.io/wemogy/get-release-version-action:4.2.2"
image: "docker://ghcr.io/wemogy/get-release-version-action:4.3.0"
args:
- --prefix
- ${{ inputs.prefix }}
Expand All @@ -57,5 +65,9 @@ runs:
- ${{ inputs.only-bump-suffix }}
- --create-tag
- ${{ inputs.create-tag }}
- --git-username
- ${{ inputs.git-username }}
- --git-email
- ${{ inputs.git-email }}
- --mode
- ${{ inputs.mode }}
16 changes: 16 additions & 0 deletions get_release_version_action/algorithms/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,22 @@ def cli_entrypoint() -> None:
help='Create a git tag for the version and push it if a remote is configured.'
)

parser.add_argument(
'--git-username',
dest='git_username',
required=False,
default='NONE',
help='The username for creating the (annotated) git tag. Use `NONE` for no username.'
)

parser.add_argument(
'--git-email',
dest='git_email',
required=False,
default='NONE',
help='The email address for creating the (annotated) git tag. Use `NONE` for no email address.'
)

parser.add_argument(
'--mode',
dest='mode',
Expand Down
10 changes: 9 additions & 1 deletion get_release_version_action/algorithms/main_algorithm.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,11 @@ def main_algorithm(inputs: Inputs) -> Outputs:
"""The main algorithm."""
logger.debug('Inputs: %s', inputs)

# If create_tag is true, a git email address and a username are required.
if inputs.create_tag:
if inputs.git_email is None or inputs.git_username is None:
raise ValueError('git email and username are required when a tag should be created!')

with git.Repo(os.getcwd()) as repo:
if inputs.mode == 'semantic':
previous_version_tag_name, new_version, version_bumped = get_next_semantic_version(inputs, repo)
Expand All @@ -41,7 +46,10 @@ def main_algorithm(inputs: Inputs) -> Outputs:
('0.0.0' not in new_version_tag_name and previous_version_tag_name != new_version_tag_name))

if inputs.create_tag and new_tag_needed:
create_git_tag(new_version_tag_name)
if inputs.git_email is None or inputs.git_username is None:
raise ValueError('git email and username are required when a tag should be created!')

create_git_tag(new_version_tag_name, inputs.git_username, inputs.git_email)

output = Outputs(
version=new_version,
Expand Down
6 changes: 6 additions & 0 deletions get_release_version_action/models/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ class Inputs:
create_tag: bool = True
"""Create a git tag for the version and push it if a remote is configured."""

git_username: str | None = None
"""The username for creating the (annotated) git tag. Use `NONE` for no username."""

git_email: str | None = None
"""The email address for creating the (annotated) git tag. Use `NONE` for no email address."""

mode: str = 'semantic'
"""The mode to use for determining the next version. Possible values: `semantic`, `hash-based`."""

Expand Down
6 changes: 5 additions & 1 deletion get_release_version_action/utils/git.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
tag_creation_history: list[str] = []


def create_git_tag(version: str) -> None:
def create_git_tag(version: str, username: str, email: str) -> None:
"""Create a new git tag for the given version and push it if a remote is configured."""
logger.info('Setting git username and email to %s <%s>', username, email)
run_command('git', 'config', 'user.email', email)
run_command('git', 'config', 'user.name', username)

logger.info('Creating tag %s', version)

# Create the tag
Expand Down
3 changes: 2 additions & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ max-line-length = 120

[tool.pylint.message-control]
disable = [
"too-many-return-statements"
"too-many-return-statements",
"too-many-instance-attributes"
]

[tool.flake8]
Expand Down
30 changes: 30 additions & 0 deletions tests/e2e/test_one_commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ def test_initial(repo: TestRepo) -> None:
"""Test Case: Run the action directly after the initial commit."""
# Arrange
args_release = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='pre',
reference_version_suffix=None,
Expand All @@ -24,6 +26,8 @@ def test_initial(repo: TestRepo) -> None:
)

args_beta = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='beta',
only_bump_suffix=True,
Expand All @@ -40,6 +44,8 @@ def test_initial(repo: TestRepo) -> None:
)

args_prod = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix=None,
only_bump_suffix=True,
Expand Down Expand Up @@ -83,6 +89,8 @@ def test_chore(repo: TestRepo) -> None:
"""Test Case: Run the action after a ``chore:`` commit."""
# Arrange
args_release = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='pre',
reference_version_suffix=None,
Expand All @@ -98,6 +106,8 @@ def test_chore(repo: TestRepo) -> None:
)

args_beta = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='beta',
only_bump_suffix=True,
Expand All @@ -114,6 +124,8 @@ def test_chore(repo: TestRepo) -> None:
)

args_prod = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix=None,
only_bump_suffix=True,
Expand Down Expand Up @@ -159,6 +171,8 @@ def test_fix(repo: TestRepo) -> None:
"""Test Case: Run the action after a ``fix:`` commit."""
# Arrange
args_release = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='pre',
reference_version_suffix=None,
Expand All @@ -174,6 +188,8 @@ def test_fix(repo: TestRepo) -> None:
)

args_beta = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='beta',
only_bump_suffix=True,
Expand All @@ -190,6 +206,8 @@ def test_fix(repo: TestRepo) -> None:
)

args_prod = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix=None,
only_bump_suffix=True,
Expand Down Expand Up @@ -235,6 +253,8 @@ def test_feat(repo: TestRepo) -> None:
"""Test Case: Run the action after a ``feat:`` commit."""
# Arrange
args_release = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='pre',
reference_version_suffix=None,
Expand All @@ -250,6 +270,8 @@ def test_feat(repo: TestRepo) -> None:
)

args_beta = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='beta',
only_bump_suffix=True,
Expand All @@ -266,6 +288,8 @@ def test_feat(repo: TestRepo) -> None:
)

args_prod = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix=None,
only_bump_suffix=True,
Expand Down Expand Up @@ -311,6 +335,8 @@ def test_breaking(repo: TestRepo) -> None:
"""Test Case: Run the action after a ``feat!:`` commit."""
# Arrange
args_release = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='pre',
reference_version_suffix=None,
Expand All @@ -326,6 +352,8 @@ def test_breaking(repo: TestRepo) -> None:
)

args_beta = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix='beta',
only_bump_suffix=True,
Expand All @@ -342,6 +370,8 @@ def test_breaking(repo: TestRepo) -> None:
)

args_prod = ActionInputs(
git_username='wemogy IT',
git_email='[email protected]',
prefix='v',
suffix=None,
only_bump_suffix=True,
Expand Down
Loading

0 comments on commit 54cfbc6

Please sign in to comment.