Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions .github/workflows/Action-Test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Action-Test

run-name: "Action-Test - [${{ github.event.pull_request.title }} #${{ github.event.pull_request.number }}] by @${{ github.actor }}"

on:
push:
branches:
- main
paths:
- action.yml
- .github/workflows/Action-Test.yml
- scripts/**
pull_request:
branches-ignore:
- main
paths:
- action.yml
- .github/workflows/Action-Test.yml
- scripts/**

jobs:
ActionTestDefault:
name: Action-Test - [Default]
runs-on: ubuntu-latest
steps:
- name: Checkout repo
uses: actions/checkout@v4

- name: Action-Test
uses: ./
with:
WhatIf: true
5 changes: 5 additions & 0 deletions .github/workflows/Auto-Release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@ on:
concurrency:
group: ${{ github.workflow }}

permissions:
contents: write

jobs:
Auto-Release:
runs-on: ubuntu-latest
Expand All @@ -27,3 +30,5 @@ jobs:
uses: ./
env:
GH_TOKEN: ${{ github.token }} # Used for GitHub CLI authentication
with:
IncrementalPrerelease: false
13 changes: 7 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ Auto-Release follows:
- [GitHub Flow specifications](https://docs.github.com/en/get-started/using-github/github-flow)
- [Continiuous Delivery practices](https://en.wikipedia.org/wiki/Continuous_delivery)


## How it works

The workflow will trigger on pull requests to the main branch.
Expand All @@ -23,20 +22,20 @@ The following labels will inform the action what kind of release to create:
- `minor`
- `feature`
- `improvement`
- `enhancement`
- For a patch release, and increases the third number in the version.
- `patch`
- `bug`
- `fix`

When a pull request is closed, the action will create a release based on the labels and clean up any previous prereleases that was created.

> Note: The labels can be configured using the `MajorLabels`, `MinorLabels` and `PatchLabels` parameters/settings in the configuration file to trigger on other labels.

## Usage

The action have the following parameters:
The action can be configured using the following settings:

| Parameter | Description | Default | Required |
| Name | Description | Default | Required |
| --- | --- | --- | --- |
| `AutoCleanup`| Control wether to automatically cleanup prereleases. If disabled, the action will not remove any prereleases. | `true` | false |
| `AutoPatching` | Control wether to automatically handle patches. If disabled, the action will only create a patch release if the pull request has a 'patch' label. | `true` | false |
Expand All @@ -49,12 +48,13 @@ The action have the following parameters:
| `MinorLabels` | The labels to use for minor releases. | `minor, feature, improvement` | false |
| `PatchLabels` | The labels to use for patch releases. | `patch, fix, bug` | false |
| `VersionPrefix` | The prefix to use for the version number. | `v` | false |
| `WhatIf` | Control wether to simulate the action. If enabled, the action will not create any releases. Used for testing. | `false` | false |

### Configuration file

The configuration file is a YAML file that can be used to configure the action.
The file can be placed in the `.github` directory of the repository and named `auto-release.yml`.
The file can be used to configure the action using the same parameters as the action inputs.
By default, the configuration file is expected at `.github\auto-release.yml`, which can be changed using the `ConfigurationFile` setting.
The actions configuration can be change by altering the settings in the configuration file.

```yaml
DatePrereleaseFormat: 'yyyyMMddHHmm'
Expand All @@ -65,6 +65,7 @@ VersionPrefix: ''
This example uses the date format for the prerelease, disables the incremental prerelease and removes the version prefix.

## Example

Add a workflow in you repository using the following example:

```yaml
Expand Down
5 changes: 5 additions & 0 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ inputs:
description: The prefix to use for the version number.
required: false
default: 'v'
WhatIf:
description: If specified, the action will only log the changes it would make, but will not actually create or delete any releases or tags.
required: false
default: 'false'

runs:
using: composite
Expand All @@ -68,4 +72,5 @@ runs:
MinorLabels: ${{ inputs.MinorLabels }}
PatchLabels: ${{ inputs.PatchLabels }}
VersionPrefix: ${{ inputs.VersionPrefix }}
WhatIf: ${{ inputs.WhatIf }}
run: . "$env:GITHUB_ACTION_PATH\scripts\main.ps1"
86 changes: 58 additions & 28 deletions scripts/main.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ $createMinorTag = ($configuration.CreateMinorTag | IsNotNullOrEmpty) ? $configur
$datePrereleaseFormat = ($configuration.DatePrereleaseFormat | IsNotNullOrEmpty) ? $configuration.DatePrereleaseFormat : $env:DatePrereleaseFormat
$incrementalPrerelease = ($configuration.IncrementalPrerelease | IsNotNullOrEmpty) ? $configuration.IncrementalPrerelease -eq 'true' : $env:IncrementalPrerelease -eq 'true'
$versionPrefix = ($configuration.VersionPrefix | IsNotNullOrEmpty) ? $configuration.VersionPrefix : $env:VersionPrefix
$whatIf = ($configuration.WhatIf | IsNotNullOrEmpty) ? $configuration.WhatIf -eq 'true' : $env:WhatIf -eq 'true'

$majorLabels = (($configuration.MajorLabels | IsNotNullOrEmpty) ? $configuration.MajorLabels : $env:MajorLabels) -split ',' | ForEach-Object { $_.Trim() }
$minorLabels = (($configuration.MinorLabels | IsNotNullOrEmpty) ? $configuration.MinorLabels : $env:MinorLabels) -split ',' | ForEach-Object { $_.Trim() }
Expand All @@ -56,6 +57,7 @@ Write-Output "Create minor tag enabled: [$createMinorTag]"
Write-Output "Date-based prerelease format: [$datePrereleaseFormat]"
Write-Output "Incremental prerelease enabled: [$incrementalPrerelease]"
Write-Output "Version prefix: [$versionPrefix]"
Write-Output "What if mode: [$whatIf]"
Write-Output ''
Write-Output "Major labels: [$($majorLabels -join ', ')]"
Write-Output "Minor labels: [$($minorLabels -join ', ')]"
Expand Down Expand Up @@ -207,47 +209,71 @@ if ($createPrerelease -or $createRelease) {
$releaseExists = $releases.tagName -Contains $newVersion
if ($releaseExists -and -not $incrementalPrerelease) {
Write-Output 'Release already exists, recreating.'
gh release delete $newVersion --cleanup-tag --yes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to delete the release [$newVersion]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: gh release delete $newVersion --cleanup-tag --yes"
} else {
gh release delete $newVersion --cleanup-tag --yes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to delete the release [$newVersion]."
exit $LASTEXITCODE
}
}
}

gh release create $newVersion --title $newVersion --target $pull_request.head.ref --generate-notes --prerelease
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --target $($pull_request.head.ref) --generate-notes --prerelease"
} else {
gh release create $newVersion --title $newVersion --target $pull_request.head.ref --generate-notes --prerelease
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
}
}
} else {
gh release create $newVersion --title $newVersion --generate-notes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: gh release create $newVersion --title $newVersion --generate-notes"
} else {
gh release create $newVersion --title $newVersion --generate-notes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create the release [$newVersion]."
exit $LASTEXITCODE
}
}

if ($createMajorTag) {
$majorTag = ('{0}{1}' -f $versionPrefix, $major)
git tag -f $majorTag 'main'
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create major tag [$majorTag]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: git tag -f $majorTag 'main'"
} else {
git tag -f $majorTag 'main'
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create major tag [$majorTag]."
exit $LASTEXITCODE
}
}
}

if ($createMinorTag) {
$minorTag = ('{0}{1}.{2}' -f $versionPrefix, $major, $minor)
git tag -f $minorTag 'main'
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create minor tag [$minorTag]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: git tag -f $minorTag 'main'"
} else {
git tag -f $minorTag 'main'
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to create minor tag [$minorTag]."
exit $LASTEXITCODE
}
}
}

git push origin --tags --force
if ($LASTEXITCODE -ne 0) {
Write-Error 'Failed to push tags.'
exit $LASTEXITCODE
if ($whatIf) {
Write-Output 'WhatIf: git push origin --tags --force'
} else {
git push origin --tags --force
if ($LASTEXITCODE -ne 0) {
Write-Error 'Failed to push tags.'
exit $LASTEXITCODE
}
}
Write-Output '::endgroup::'
}
Expand All @@ -266,10 +292,14 @@ if (($closedPullRequest -or $createRelease) -and $autoCleanup) {
foreach ($rel in $prereleasesToCleanup) {
$relTagName = $rel.tagName
Write-Output "Deleting prerelease: [$relTagName]."
gh release delete $rel.tagName --cleanup-tag --yes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to delete release [$relTagName]."
exit $LASTEXITCODE
if ($whatIf) {
Write-Output "WhatIf: gh release delete $($rel.tagName) --cleanup-tag --yes"
} else {
gh release delete $rel.tagName --cleanup-tag --yes
if ($LASTEXITCODE -ne 0) {
Write-Error "Failed to delete release [$relTagName]."
exit $LASTEXITCODE
}
}
}
Write-Output '::endgroup::'
Expand Down