fix: add-vrmsreplication to pass datastore name (#635) #5
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: Release | |
on: | |
push: | |
tags: | |
- "v[0-9]+.[0-9]+.[0-9]+*" | |
permissions: | |
contents: write | |
jobs: | |
create-release: | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | |
with: | |
fetch-depth: 0 | |
- name: Check Version | |
shell: pwsh | |
if: startsWith(github.ref, 'refs/tags/v') | |
run: | | |
$tag = $env:GITHUB_REF.Replace('refs/tags/v', '') | |
$manifestName = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name | |
$moduleVersion = [regex]::Match((Get-Content -Path ./$manifestName -Raw), '(?<=ModuleVersion\s*=\s*'')[^'']+(?='')').Value | |
$version = $moduleVersion -split '\.' | Select-Object -First 3 | Join-String -Separator '.' | |
$release = ($tag -replace '^v') -split '\.' | Select-Object -First 3 | Join-String -Separator '.' | |
if ($version -ne $release) { | |
Write-Error "FAILED: Comparing module version '$version' with release tag 'v$tag'." | |
exit 1 | |
} else { | |
Write-Output "SUCCESS: Comparing module version '$version' with release tag 'v$tag'." | |
} | |
- name: Check Changelog | |
shell: pwsh | |
run: | | |
$version = $env:GITHUB_REF.Replace('refs/tags/', '') | |
$changelog = Get-Content -Path CHANGELOG.md | |
$foundVersion = $false | |
foreach ($line in $changelog) { | |
if ($line -match "^## $version$") { | |
$foundVersion = $true | |
continue | |
} | |
if ($foundVersion -and $line -match "^## ") { | |
break | |
} | |
} | |
if ($foundVersion) { | |
Write-Output "SUCCESS: Locating release in the changelog for version '$version'." | |
} else { | |
Write-Error "FAILED: Locating release in the changelog for version '$version'." | |
exit 1 | |
} | |
- name: Create Release Branch | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
$version = $env:GITHUB_REF.Replace('refs/tags/', '') | |
$releaseBranch = "release/$version" | |
$git = Get-Command git | Select-Object -ExpandProperty Definition | |
& $git config --global user.name "github-actions[bot]" | |
& $git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
& $git checkout -b $releaseBranch | |
& $git push origin $releaseBranch | |
if ($LASTEXITCODE -ne 0) { | |
Write-Error "FAILED: Creating release branch '$releaseBranch'." | |
} else { | |
Write-Output "SUCCESS: Creating release branch '$releaseBranch'." | |
} | |
- name: Rebase Main Branch | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
$version = $env:GITHUB_REF.Replace('refs/tags/', '') | |
$releaseBranch = "release/$version" | |
$git = Get-Command git | Select-Object -ExpandProperty Definition | |
& $git config --global user.name "github-actions[bot]" | |
& $git config --global user.email "41898282+github-actions[bot]@users.noreply.github.com" | |
& $git checkout $releaseBranch | |
& $git pull origin $releaseBranch | |
& $git checkout main | |
& $git pull origin main | |
& $git rebase $releaseBranch | |
& $git push origin main | |
if ($LASTEXITCODE -ne 0) { | |
Write-Error "FAILED: Rebasing main branch from release branch '$releaseBranch'." | |
} else { | |
Write-Output "SUCCESS: Rebasing main branch from release branch '$releaseBranch'." | |
} | |
- name: Install GitHub CLI | |
run: | | |
type -p curl >/dev/null || (sudo apt update && sudo apt install curl -y) | |
curl -fsSL https://cli.github.com/packages/githubcli-archive-keyring.gpg | sudo dd of=/usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
&& sudo chmod go+r /usr/share/keyrings/githubcli-archive-keyring.gpg \ | |
&& echo "deb [arch=$(dpkg --print-architecture) signed-by=/usr/share/keyrings/githubcli-archive-keyring.gpg] https://cli.github.com/packages stable main" | sudo tee /etc/apt/sources.list.d/github-cli.list > /dev/null \ | |
&& sudo apt update \ | |
&& sudo apt install gh -y | |
- name: Create Release | |
shell: pwsh | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
run: | | |
$version = $env:GITHUB_REF.Replace('refs/tags/', '') | |
$changelog = Get-Content -Path CHANGELOG.md | |
$releaseNotes = $null | |
$foundVersion = $false | |
foreach ($line in $changelog) { | |
if ($line -match "^## $version$") { | |
$foundVersion = $true | |
continue | |
} | |
if ($foundVersion -and $line -match "^## ") { | |
break | |
} | |
if ($foundVersion) { | |
$releaseNotes += $line + "`n" | |
} | |
} | |
$gh = Get-Command gh | Select-Object -ExpandProperty Definition | |
& $gh release create $version --title "$version" --notes "$releaseNotes" --target "release/$version" | |
if ($LASTEXITCODE -ne 0) { | |
Write-Error "FAILED: Creating GitHub release '$version'." | |
} else { | |
Write-Output "SUCCESS: Creating GitHub release '$version'." | |
} | |
publish-docs: | |
needs: create-release | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@3df4ab11eba7bda6032a0b82a6bb43b11571feac # v4.0.0 | |
with: | |
ref: ${{ github.event.release.tag_name }} | |
fetch-depth: 0 | |
- name: Setup Python | |
uses: actions/setup-python@82c7e631bb3cdc910f68e0081d67478d79c6982d # v5.1.0 | |
with: | |
python-version: 3.x | |
- name: Install Dependencies | |
run: | | |
pip install mkdocs-material | |
pip install --requirement docs/requirements.txt | |
- name: Publish Documentation | |
run: | | |
mkdocs gh-deploy --force | |
if: ${{ success() }} | |
publish-module: | |
needs: [create-release, publish-docs] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout Repository | |
uses: actions/checkout@8ade135a41bc03ea155e62e844d188df1ea18608 # v4.1.0 | |
with: | |
ref: ${{ github.event.release.tag_name }} | |
fetch-depth: 0 | |
- name: Publish Module to PowerShell Gallery | |
shell: pwsh | |
env: | |
PSGALLERY_API_KEY: ${{ secrets.PSGALLERY_API_KEY }} | |
run: | | |
Write-Output "INFO: Preparing Ubuntu-based GitHub runner for publishing module to the PowerShell Gallery." | |
Write-Output "INFO: Setting the PowerShell Gallery as a trusted repository." | |
Set-PSRepository psgallery -InstallationPolicy trusted | |
Write-Output "INFO: Locating module manifest in '$env:GITHUB_WORKSPACE'." | |
$moduleManifest = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name | |
if ($moduleManifest) { | |
Write-Output "SUCCESS: Manifest '$moduleManifest' found in '$env:GITHUB_WORKSPACE'." | |
} else { | |
Write-Output "FAILURE: Manifest not found in '$env:GITHUB_WORKSPACE'." | |
} | |
if ($moduleManifest -match '^(.*)\.psd1$') { | |
$moduleName = $Matches[1] | |
Write-Output "SUCCESS: Determining module name from manifest '$moduleManifest'." | |
} else { | |
Write-Error "FAILED: Determining module name from manifest '$moduleManifest'." | |
} | |
Write-Output "INFO: Reading module manifest '$moduleManifest'." | |
$moduleManifestData = Import-PowerShellDataFile -Path $moduleManifest | |
Write-Output "INFO: Determining module dependencies." | |
$requiredModules = $moduleManifestData.RequiredModules | |
if ($requiredModules) { | |
Write-Output "SUCCESS: Module dependencies were found." | |
Write-Output "INFO: Required modules are $($requiredModules.ModuleName -join ', ')." | |
Write-Output "INFO: Setting location to the PowerShell modules location on a Ubuntu-based GitHub runner." | |
Set-Location '/home/runner/.local/share/powershell/Modules/' | |
foreach ($module in $requiredModules) { | |
$requiredModuleName = $module.ModuleName | |
New-Item $requiredModuleName -ItemType Directory | |
Write-Output "INFO: Performing workaround for github.com/PowerShell/PowerShell/issues/7722." | |
Write-Output "INFO: Creating placeholder manifest for $requiredModuleName at $((Get-Location).Path)/$requiredModuleName/$requiredModuleName.psd1" | |
New-Item "./$requiredModuleName/$requiredModuleName.psd1" -ItemType File | |
} | |
} else { | |
Write-Output "INFO: No module dependencies were found." | |
} | |
Write-Output "INFO: Setting location to the GitHub workspace at '$env:GITHUB_WORKSPACE'." | |
Set-Location $env:GITHUB_WORKSPACE | |
Write-Output "INFO: Publishing module to the PowerShell Gallery." | |
$remove = @('.ci', '.dependencies', '.git', '.github', '.gitignore', '.vscode', 'docs', 'CODEOWNERS', 'CODE_OF_CONDUCT.md', 'CONTRIBUTING.md', 'Makefile', 'mkdocs.yml') | |
$random = Get-Random -Count 1 | |
$destinationPath = Join-Path -Path $env:GITHUB_WORKSPACE -ChildPath $random | |
$manifestName = (Get-ChildItem -Path $env:GITHUB_WORKSPACE -Filter *.psd1).Name | |
$moduleVersion = [regex]::Match((Get-Content -Path ./$manifestName -Raw), '(?<=ModuleVersion\s*=\s*'')[^'']+(?='')').Value | |
if ($manifestName -match '^(.*)\.psd1$') { | |
$moduleName = $Matches[1] | |
Write-Output "SUCCESS: Determining module name from manifest file name '$moduleName'." | |
} else { | |
Write-Error "FAILED: Determining module name from manifest file name '$moduleName'." | |
} | |
$modulePath = Join-Path -Path $destinationPath -ChildPath $moduleName | |
$createModulePath = New-Item -Path $modulePath -ItemType Directory -Force | |
if ($createModulePath) { | |
Write-Output "SUCCESS: Creating staging path '$modulePath'." | |
} else { | |
Write-Error "FAILED: Creating staging path '$modulePath'." | |
} | |
Get-ChildItem -Force | Where-Object { $_.Name -notin $remove -and $_.Name -ne $random } | Copy-Item -Destination $modulePath -Recurse | |
Get-ChildItem -Depth 5 -Path $modulePath | Format-Table -AutoSize | |
$moduleManifest = Join-Path -Path $modulePath -ChildPath "$moduleName.psd1" | |
if (Test-Path -Path $moduleManifest) { | |
Publish-Module -Path $modulePath -NuGetApiKey $env:PSGALLERY_API_KEY | |
Start-Sleep -Seconds 30 | |
$module = Find-Module -Name $moduleName -RequiredVersion "$moduleVersion" | |
if ($module) { | |
Write-Output "SUCCESS: Publishing module '$moduleName' version '$moduleVersion' to PowerShell Gallery." | |
} else { | |
Write-Error "FAILED: Publishing module '$moduleName' version '$moduleVersion' to PowerShell Gallery." | |
} | |
} else { | |
Write-Error "FAILED: Module manifest file not found at path '$moduleManifest'." | |
} | |