CD #117
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: CD | |
on: workflow_dispatch | |
jobs: | |
deployment: | |
runs-on: ubuntu-latest | |
env: | |
module_name: VenafiPS | |
steps: | |
- uses: actions/checkout@main | |
with: | |
token: ${{ secrets.CD_TOKEN }} | |
- name: Update psd and psm version | |
shell: pwsh | |
run: | | |
$manifestPath = '${{ github.workspace }}/${{ env.module_name }}/${{ env.module_name }}.psd1' | |
$modulePath = $manifestPath.Replace('.psd1', '.psm1') | |
$manifest = Import-PowerShellDataFile '${{ github.workspace }}/${{ env.module_name }}/${{ env.module_name }}.psd1' | |
[version]$version = $manifest.ModuleVersion | |
[version]$newVersion = "{0}.{1}.{2}" -f $Version.Major, $Version.Minor, ($Version.Build + 1) | |
Update-ModuleManifest -Path $manifestPath -ModuleVersion $newVersion | |
# update-modulemanifest introduces whitepsace so get rid of it | |
(Get-Content $manifestPath).TrimEnd() | Set-Content $manifestPath | |
# ((Get-Content -Path $modulePath -Raw).Replace('((NEW_VERSION))', $newVersion)) | Set-Content -Path $modulePath | |
"New version: $newVersion" | |
# set version to be used in later steps | |
"venafips_new_version=$newVersion" | Out-File -FilePath $env:GITHUB_ENV -Append | |
- name: Update changelog | |
shell: pwsh | |
run: | | |
$newVersionString = '## ${{ env.venafips_new_version }}' | |
$releaseNotes = Get-Content -Path '${{ github.workspace }}/RELEASE.md' -Raw | |
$changelog = Get-Content -Path '${{ github.workspace }}/CHANGELOG.md' -Raw | |
Set-Content -Path '${{ github.workspace }}/CHANGELOG.md' -Value ($newVersionString + "`r`n" + $releaseNotes + "`r`n`r`n" + $changelog) | |
- name: Install platyPS module | |
shell: pwsh | |
run: | | |
Set-PSRepository PSGallery -InstallationPolicy Trusted | |
Install-Module platyPS -ErrorAction Stop | |
- name: Update docs | |
shell: pwsh | |
run: | | |
Remove-Module '${{ env.module_name }}' -Force -ea SilentlyContinue -Verbose | |
Import-Module '${{ github.workspace }}/${{ env.module_name }}/${{ env.module_name }}.psd1' -Force -Verbose | |
#Build YAMLText starting with the header | |
$YMLtext = (Get-Content "${{ github.workspace }}/header-mkdocs.yml") -join "`n" | |
$YMLtext = "$YMLtext`n" | |
$parameters = @{ | |
Path = '${{ github.workspace }}/CHANGELOG.md' | |
ErrorAction = 'SilentlyContinue' | |
} | |
$changeLogText = (Get-Content @parameters) -join "`n" | |
if ($changeLogText) { | |
$changeLogText | Set-Content "${{ github.workspace }}/docs/changelog.md" | |
$YMLText = "$YMLtext - Changelog: changelog.md`n" | |
} | |
$YMLText = "$YMLtext - Functions:`n" | |
# Drain the swamp | |
$parameters = @{ | |
Recurse = $true | |
Force = $true | |
Path = "${{ github.workspace }}/docs/functions" | |
ErrorAction = 'SilentlyContinue' | |
} | |
$null = Remove-Item @parameters | |
$Params = @{ | |
Path = "${{ github.workspace }}/docs/functions" | |
type = 'directory' | |
ErrorAction = 'SilentlyContinue' | |
} | |
$null = New-Item @Params | |
$Params = @{ | |
Module = '${{ env.module_name }}' | |
Force = $true | |
OutputFolder = '${{ github.workspace }}/docs/functions' | |
NoMetadata = $true | |
} | |
New-MarkdownHelp @Params | ForEach-Object { | |
$Function = $_.Name -replace '\.md', '' | |
$Part = " - {0}: functions/{1}" -f $Function, $_.Name | |
$YMLText = "{0}{1}`n" -f $YMLText, $Part | |
$Part | |
} | |
$YMLtext | Set-Content -Path '${{ github.workspace }}/mkdocs.yml' | |
- name: Update repo | |
run: | | |
git config --global user.name 'Greg Brownstein' | |
git config --global user.email 'greg@jagtechnical.com' | |
git add VenafiPS/VenafiPS.psd1 | |
git add docs | |
git add mkdocs.yml | |
git add CHANGELOG.md | |
git status | |
git commit -m "Update manifest and docs to ${{ env.venafips_new_version }}" | |
git push | |
# - name: Generate file hash | |
# shell: pwsh | |
# run: | | |
# $fullPath = Resolve-Path ./${{ env.module_name }} | Select-Object -ExpandProperty Path | |
# Get-ChildItem -Path ./${{ env.module_name }} -File -Recurse | Get-FileHash -Algorithm SHA256 | Select-Object Hash, | |
# @{ | |
# 'n' = 'File' | |
# 'e' = { | |
# $_.Path.Replace("$fullPath/", '') | |
# } | |
# } | ConvertTo-Json | Out-File -FilePath ${{ github.workspace }}/hash.json | |
# - name: Upload hash.json artifact | |
# uses: actions/upload-artifact@v3 | |
# with: | |
# name: hash.json | |
# path: ${{ github.workspace }}/hash.json | |
# - name: Create GitHub release | |
# if: github.ref == 'refs/heads/main' | |
# uses: softprops/action-gh-release@v1 | |
# with: | |
# files: ${{ github.workspace }}/hash.json | |
# tag_name: v${{ env.venafips_new_version }} | |
# body_path: ${{ github.workspace }}/RELEASE.md | |
# - name: Publish | |
# if: github.ref == 'refs/heads/main' | |
# shell: pwsh | |
# run: | | |
# Publish-Module -Path "${{ github.workspace }}/${{ env.module_name }}" -NuGetApiKey ${{ secrets.NUGET_KEY }} -Verbose | |
# - name: Login to dockerhub | |
# uses: docker/login-action@v2 | |
# with: | |
# username: ${{ secrets.DOCKER_USERNAME }} | |
# password: ${{ secrets.DOCKER_PASSWORD }} | |
# - name: Build image | |
# run: > | |
# docker build | |
# --pull | |
# -t venafi/venafips-module:latest | |
# -t venafi/venafips-module:${{ env.venafips_new_version }} | |
# . | |
# - name: Publish image and tags | |
# run: docker push --all-tags venafi/venafips-module |