-
Notifications
You must be signed in to change notification settings - Fork 7
154 lines (136 loc) · 5.94 KB
/
cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
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