Skip to content

Commit

Permalink
fea: add release workflow (#18)
Browse files Browse the repository at this point in the history
* Remove load message

* bug: as we are callling  Write-AssertionDot

* fea: add testing workflow

* fea: add release workflow

* fea: add release script
  • Loading branch information
rulasg authored Jul 31, 2023
1 parent 2deec8e commit ac18df2
Show file tree
Hide file tree
Showing 2 changed files with 117 additions and 0 deletions.
48 changes: 48 additions & 0 deletions .github/workflows/deploy_module_on_release.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
name: Deploy on Release Published

on:
workflow_dispatch:
release:
types: [published]

permissions:
contents: read

jobs:
deploy_to_powershellgallery:
runs-on: ubuntu-latest
environment: powershellgallery # Specify the name of the environment on the repo
steps:
- uses: actions/checkout@v3
- env:
EVENT_CONTEXT: ${{ toJSON(github.event) }}
run: |
echo $EVENT_CONTEXT
- name: deploy_ps1
shell: pwsh
env:
NUGETAPIKEY: ${{ secrets.NUGETAPIKEY }} # Configure this secret on the environment
EVENT_REF: ${{ github.event.ref }}
RELEASE_TAG: ${{ github.event.release.tag_name }}
RELEASE_NAME: ${{ github.event.release.name }}
run: |
$env:EVENT_REF = $env:REF
If ([string]::IsNullOrEmpty($env:EVENT_REF)) {
# Release published trigger
$tag = $env:RELEASE_TAG
write-host -message "Release [$env:RELEASE_NAME] on tag [$tag]"
} else {
# Read Tag o Branch name
$tag = $env:EVENT_REF.Split('/')[2]
write-host "workflow_dispatch triggered on ref leaf [$tag]"
}
If([string]::IsNullorwhitespace($tag)) {
# Tag name is empty, exit
write-error "Tag name is empty"
exit 1
}
./deploy.ps1 -VersionTag $tag -NugetApiKey $env:NUGETAPIKEY
69 changes: 69 additions & 0 deletions release.ps1
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<#
.SYNOPSIS
Create a tag and release on GitHub
.DESCRIPTION
Create a tag on the repo and a release to that tag on GitHub remote repo.
This script works very well with GitHub Actions workflow that run on release creation.
Check the following workflow as an example:
https://raw.githubusercontent.com/rulasg/DemoPsModule/main/.github/workflows/deploy_module_on_release.yml
.PARAMETER VersionTag
Tag to create (Sample: v10.0.01-alpha). This is the same tag that will be used for the release.
.PARAMETER Force
Force the script to run without confirmation.
.PARAMETER CreateTag
Create the tag on the repo. If not specified, the script will only create the release.
.EXAMPLE
.\release.ps1 -VersionTag v10.0.01-alpha
Create a release on the existing tag v10.0.01-alpha.
.EXAMPLE
.\release.ps1 -VersionTag v10.0.01-alpha -CreateTag
Create a release on the existing tag v10.0.01-alpha and create the tag on the repo.
.EXAMPLE
.\release.ps1 -VersionTag v10.0.01-alpha -CreateTag -Force
Create tag and create release without confirmation.
.LINK
https://raw.githubusercontent.com/rulasg/DemoPsModule/main/release.ps1
#>

[cmdletbinding(SupportsShouldProcess, ConfirmImpact='High')]
param(
# Update the module manifest with the version tag (Sample: v10.0.01-alpha)
[Parameter(Mandatory)] [string]$VersionTag,
[Parameter()] [switch]$Force,
[Parameter()] [switch]$CreateTag,
[Parameter()] [switch]$NotPreRelease
)

# Confirm if not forced
if ($Force -and -not $Confirm){
$ConfirmPreference = 'None'
}

if ($CreateTag) {
if ($PSCmdlet.ShouldProcess($VersionTag, "git tag creation")) {
git tag -a $VersionTag -m "Release tag" -s ; git push --tags
}
}

if ($PSCmdlet.ShouldProcess($VersionTag, "gh release create")) {

if ($NotPreRelease) {
gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag"

} else {
gh release create $VersionTag --generate-notes --verify-tag --title "Release $VersionTag (PreRelease)" --prerelease
}
}

0 comments on commit ac18df2

Please sign in to comment.