Skip to content
This repository was archived by the owner on Aug 11, 2024. It is now read-only.

Commit

Permalink
fix: initial import
Browse files Browse the repository at this point in the history
  • Loading branch information
ArwynFr committed Feb 24, 2022
0 parents commit fc8739a
Show file tree
Hide file tree
Showing 7 changed files with 174 additions and 0 deletions.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2020 Arwyn

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
56 changes: 56 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# Conventional Versioning

This Github action creates a new Github Release, using [Semantic Versioning](https://semver.org/) and [Conventional Commits](https://www.conventionalcommits.org/) messages.

## Current version
The current version is based on latest Github Release *tag name*.
If there is no release or the tag is not a valid version number, the action will default to `0.0.0`.
Current version should not include any prefix, values such as `v1.2.3` or `ver-1.2.3` are **not** understood by this action and will have the action default to `0.0.0`.

## Change type
The type of version change is based on HEAD commit message, taken from [`github.event` context](https://docs.github.com/en/actions/learn-github-actions/contexts).
* `Fix` will bump the patch version
* `Feature` will bump the minor version
* `Breaking` will bump major version

Breaking changes can either use the explicit notation (`BREAKING CHANGE:` in the body or footer) or the bang notation (`type(scope)!: description` in the first line).
If the message is not understood as a valid conventional commit, the change type will default to `Fix`.
You should consider using this action in conjunction with another one enforcing commit message format.

## Release creation
This action uses [Github CLI](https://cli.github.com/) and needs **not** to checkout the repository.
The release will autogenerate the notes, tag the source code, and include source archives to the release by default.
You can add additional files using the [`pattern` input variable](#pattern).
This pattern matches the syntax for [`gh release create`](https://cli.github.com/manual/gh_release_create) command.

## Inputs
### Pattern
Wildcard pattern used to add files in the release.

## Example

This action will create a release with artifacts for each commit on the master branch :

```yml
on:
push:
branches: [master]

jobs:

# insert another job that will build and upload some artifacts

publish:
runs-on: ubuntu-latest
name: 'Publish a new release'
steps:

- uses: actions/download-artifact@v2
with:
name: my-artifact
path: artifacts

- uses: arwynfr/[email protected]
with:
pattern: artifacts/*
```
21 changes: 21 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
name: 'Conventional Versioning'
description: 'Create Github Release using SemVer when pushing Conventional Comits'
author: ArwynFr
branding:
icon: tag
color: blue
inputs:
pattern:
description: 'Pattern of files to include in the release'
required: false
runs:
using: "composite"
steps:

- shell: pwsh
run: |
"${{ github.token }}" | gh auth login --with-token
& "$env:GITHUB_ACTION_PATH/functions/New-GithubRelease.ps1" `
-RepositoryName "${{ github.repository }}" `
-CommitMessage "${{ github.event.head_commit.message }}" `
-Pattern "${{ inputs.pattern }}"
13 changes: 13 additions & 0 deletions functions/Get-SemVer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
[CmdletBinding()]
param (
[Parameter()]
[string]
$RepositoryName
)

$private:PrevErrorActionPreference = $ErrorActionPreference
$ErrorActionPreference = 'silentlycontinue'
$private:currentVersionNumber = ((gh release view --json tagName --repo $RepositoryName) | convertfrom-json).TagName
$private:currentVersion = [semver]::new($private:currentVersionNumber)
$ErrorActionPreference = $private:PrevErrorActionPreference
return $private:currentVersion
21 changes: 21 additions & 0 deletions functions/Get-VersionBumpType.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
[CmdletBinding()]
param (
[Parameter()]
[string]
$CommitMessage
)

if ($CommitMessage -match 'BREAKING CHANGE:') {
return 'Breaking'
}

$private:commitFirstLine = ($CommitMessage -split [Environment]::NewLine)[0]
if (($private:commitFirstLine -split ": ")[0].EndsWith('!')) {
return 'Breaking'
}

if ($private:commitFirstLine.StartsWith("feat")) {
return 'Feature'
}

return 'Fix'
22 changes: 22 additions & 0 deletions functions/New-GithubRelease.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
[CmdletBinding()]
param (
[Parameter(Mandatory = $true)]
[string]
$RepositoryName,

[Parameter(Mandatory = $true)]
[string]
$CommitMessage,

[Parameter()]
[string]
$Pattern
)

$Private:currentVersion = & $env:GITHUB_ACTION_PATH/functions/Get-SemVer.ps1 -RepositoryName "$RepositoryName"
$Private:bumpType = & $env:GITHUB_ACTION_PATH/functions/Get-VersionBumpType.ps1 -CommitMessage "$CommitMessage"
$Private:nextVersion = & $env:GITHUB_ACTION_PATH/functions/New-SemVer.ps1 -Version $Private:currentVersion -BumpType $Private:bumpType
Write-Host "Current Version: $Private:currentVersion"
Write-Host "Change Category: $Private:bumpType"
Write-Host "Next Version: $Private:nextVersion"
gh release create "$private:nextVersion" --generate-notes --repo "$RepositoryName" "$Pattern"
20 changes: 20 additions & 0 deletions functions/New-SemVer.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
[CmdletBinding()]
param (
[Parameter()]
[semver]
$Version,

[Parameter()]
[string]
$BumpType
)

if ('Breaking' -eq $BumpType) {
return [semver]::new($Version.Major + 1)
}

if ('Feature' -eq $BumpType) {
return [semver]::new($Version.Major, $Version.Minor + 1)
}

return [semver]::new($Version.Major, $Version.Minor, $Version.Patch + 1)

0 comments on commit fc8739a

Please sign in to comment.