Skip to content

Commit 0363853

Browse files
authored
Initial Implementation (#1)
* Add semver tool * Add action definition * Additions * Update README * Add major-version to output * Simplify usage example * Add release workflow
1 parent 58e3533 commit 0363853

File tree

5 files changed

+814
-2
lines changed

5 files changed

+814
-2
lines changed

.github/release.yml

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# https://docs.github.com/en/repositories/releasing-projects-on-github/automatically-generated-release-notes#configuration-options
2+
changelog:
3+
exclude:
4+
labels:
5+
- ci
6+
- ignore-for-release
7+
authors:
8+
- github-actions
9+
- octocat
10+
categories:
11+
- title: Breaking Changes 🛠
12+
labels:
13+
- semver/major
14+
- breaking-change
15+
- title: New Features 🎉
16+
labels:
17+
- semver/minor
18+
- enhancement
19+
- title: Bug Fixes 🐛
20+
labels:
21+
- semver/patch
22+
- bug
23+
- title: Other Changes
24+
labels:
25+
- "*"

.github/workflows/release.yml

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
name: Release
2+
on:
3+
workflow_dispatch:
4+
inputs:
5+
release_type:
6+
description: Type of release
7+
type: choice
8+
required: true
9+
options:
10+
- patch
11+
- minor
12+
- major
13+
14+
jobs:
15+
release:
16+
name: Release
17+
runs-on: ubuntu-latest
18+
permissions:
19+
contents: write
20+
steps:
21+
- name: Git checkout
22+
uses: actions/checkout@v4
23+
24+
- name: Get latest release version
25+
id: get_current_version
26+
uses: actions/github-script@v7
27+
with:
28+
script: |
29+
const { data: { tag_name } } = await github.rest.repos.getLatestRelease({
30+
owner: context.repo.owner,
31+
repo: context.repo.repo
32+
})
33+
return tag_name
34+
35+
- name: Bump version
36+
id: bump
37+
uses: Mobelux/bump-version-action@v1
38+
with:
39+
release-type: ${{ inputs.release_type }}
40+
version: ${{ steps.get_current_version.outputs.result }}
41+
42+
- name: Push tag
43+
uses: actions/github-script@v7
44+
with:
45+
script: |
46+
github.rest.git.createRef({
47+
owner: context.repo.owner,
48+
repo: context.repo.repo,
49+
ref: 'refs/tags/v${{ steps.bump.outputs.version }}',
50+
sha: context.sha
51+
})
52+
53+
- name: Create new major version tag
54+
if: inputs.release_type == 'major'
55+
uses: actions/github-script@v7
56+
with:
57+
script: |
58+
github.rest.git.createRef({
59+
owner: context.repo.owner,
60+
repo: context.repo.repo,
61+
ref: 'refs/tags/v${{ steps.bump.outputs.major-version }}',
62+
sha: context.sha
63+
})
64+
65+
- name: Update major version tag
66+
if: inputs.release_type != 'major'
67+
uses: actions/github-script@v7
68+
with:
69+
script: |
70+
github.rest.git.updateRef({
71+
owner: context.repo.owner,
72+
repo: context.repo.repo,
73+
ref: 'tags/v${{ steps.bump.outputs.major-version }}',
74+
sha: context.sha
75+
})
76+
77+
- name: Create release
78+
uses: actions/github-script@v7
79+
with:
80+
script: |
81+
github.rest.repos.createRelease({
82+
owner: context.repo.owner,
83+
repo: context.repo.repo,
84+
tag_name: 'v${{ steps.bump.outputs.version }}',
85+
generate_release_notes: true,
86+
draft: false,
87+
prerelease: false
88+
})

README.md

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,41 @@
1-
# bump-version-action
2-
GitHub action to bump a semantic version
1+
# Bump Version
2+
3+
A GitHub Action to bump a given version number.
4+
5+
## Inputs
6+
7+
```yaml
8+
inputs:
9+
version:
10+
description: The current semantic version number.
11+
required: true
12+
release-type:
13+
description: Type of release. Must be one of `patch` | `minor` | `major`.
14+
required: true
15+
```
16+
17+
## Outputs
18+
19+
```yaml
20+
outputs:
21+
version:
22+
description: The new version number.
23+
major-version:
24+
description: The major version number.
25+
```
26+
27+
## Example Usage
28+
29+
```yaml
30+
- uses: uses: Mobelux/bump-version-action@v1
31+
id: bump
32+
with:
33+
version: `1.0.0'
34+
release-type: 'minor'
35+
```
36+
37+
See this repo's [release workflow](.github/workflows/release.yml) for a complete example.
38+
39+
## Acknowledgments
40+
41+
Uses [semver-tool](https://github.com/fsaintjacques/semver-tool)

action.yml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Bump Version
2+
author: Mobelux
3+
description: Bumps a given version number.
4+
5+
inputs:
6+
version:
7+
description: The current semantic version number.
8+
required: true
9+
release-type:
10+
description: Type of release. Must be one of `patch` | `minor` | `major`.
11+
required: true
12+
13+
outputs:
14+
version:
15+
description: The new version number.
16+
value: ${{ steps.bump.outputs.new-version }}
17+
major-version:
18+
description: The major version number.
19+
value: ${{ steps.major-version.outputs.major-version }}
20+
21+
runs:
22+
using: composite
23+
steps:
24+
- name: Bump Version
25+
id: bump
26+
shell: bash
27+
run: |
28+
echo "new-version=$( ${{ github.action_path }}/semver.sh bump ${{ inputs.release-type }} ${{ inputs.version }} )" >> $GITHUB_OUTPUT
29+
- name: Get Major Version
30+
id: major-version
31+
shell: bash
32+
run: |
33+
echo "major-version=$( ${{ github.action_path }}/semver.sh get major ${{ steps.bump.outputs.new-version }} )" >> $GITHUB_OUTPUT
34+
35+
branding:
36+
icon: 'triangle'
37+
color: 'orange'

0 commit comments

Comments
 (0)