Skip to content

Commit ba8548b

Browse files
authored
Updated Readme.md with Azure Pipelines and GitHub Actions examples (#39)
- Updated the Readme.md with instructions (along with an example) in using Azure Pipelines and GitHub Actions.
1 parent 7617fe9 commit ba8548b

1 file changed

Lines changed: 106 additions & 0 deletions

File tree

README.md

Lines changed: 106 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -162,6 +162,111 @@ i.e. `templates/storage/v1/template.json`.
162162
The example finds all the Azure template files and outputs a markdown file for each in `out/docs/`.
163163
An example of the generated markdown is available [here](templates/storage/v1/README.md)
164164

165+
### Using with Azure Pipelines
166+
167+
The following example shows how to setup Azure Pipelines to generate ARM template documentation in the markdown format.
168+
This example copies the generated markdown files to a designated blob storage.
169+
170+
- Create a new YAML pipeline with the Starter pipeline template.
171+
- Add a PowerShell task to:
172+
- Install [PSDocs.Azure][module] module.
173+
- Scan for Azure template file recursively in the templates/ directory.
174+
- Generate a standard name of the markdown file. i.e. `<name>_<version>`.md
175+
- Generate the markdown to a specific directory.
176+
- Add an [AzureFileCopy task](https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/deploy/azure-file-copy?view=azure-devops) to copy the generated markdown to an Azure Storage Blob container.
177+
178+
For example:
179+
180+
```yaml
181+
# Example: .azure-pipelines/psdocs-blobstorage.yaml
182+
183+
jobs:
184+
- job: 'generate_arm_template_documentation'
185+
displayName: 'Generate ARM template docs'
186+
pool:
187+
vmImage: 'windows-2019'
188+
steps:
189+
# STEP 1: Generate Markdowns using PSDocs
190+
- powershell: |
191+
Install-Module -Name 'PSDocs.Azure' -Repository PSGallery -force;
192+
# Scan for Azure template file recursively in the templates/ directory
193+
Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
194+
# Generate a standard name of the markdown file. i.e. <name>_<version>.md
195+
$template = Get-Item -Path $_.TemplateFile;
196+
$templateName = $template.Directory.Parent.Name;
197+
$version = $template.Directory.Name;
198+
$docName = "$($templateName)_$version";
199+
# Generate markdown
200+
Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
201+
}
202+
displayName: 'Export template data'
203+
204+
# STEP 2: Copy files to a storage account
205+
- task: AzureFileCopy@4
206+
displayName: 'Copy files to a storage account blob container'
207+
inputs:
208+
SourcePath: 'out/docs/*'
209+
azureSubscription: 'psdocstest'
210+
Destination: 'AzureBlob'
211+
storage: '<storageaccountname>'
212+
ContainerName: 'ps-docs'
213+
```
214+
215+
### Using with GitHub Actions
216+
217+
The following example shows how to setup GitHub Actions to copy generated markdown files to an Azure blob storage account.
218+
219+
- See [Creating a workflow file][create-workflow] to create an empty workflow file.
220+
- Add a PowerShell step to:
221+
- Install [PSDocs.Azure][module] module.
222+
- Scan for Azure template file recursively in the templates/ directory.
223+
- Generate a standard name of the markdown file. i.e. `<name>_<version>`.md
224+
- Generate the markdown to a specific directory.
225+
- Set the `STORAGEACCOUNTSECRET` action secret.
226+
- Use an [Azure Blob Storage Upload action](https://github.com/marketplace/actions/azure-blob-storage-upload) to copy the generated markdown to an Azure Storage Blob container.
227+
228+
For example:
229+
230+
```yaml
231+
# Example: .github/workflows/arm-docs.yaml
232+
233+
name: Generate ARM templates docs
234+
on:
235+
push:
236+
branches: [ main ]
237+
jobs:
238+
arm_docs:
239+
name: Generate ARM template docs
240+
runs-on: ubuntu-latest
241+
steps:
242+
- name: Checkout
243+
uses: actions/checkout@v2
244+
# STEP 1: Generate Markdowns using PSDocs
245+
- name: Generate ARM markdowns
246+
run: |
247+
Install-Module -Name 'PSDocs.Azure' -Repository PSGallery -force;
248+
# Scan for Azure template file recursively in the templates/ directory
249+
Get-AzDocTemplateFile -Path templates/ | ForEach-Object {
250+
# Generate a standard name of the markdown file. i.e. <name>_<version>.md
251+
$template = Get-Item -Path $_.TemplateFile;
252+
$templateName = $template.Directory.Parent.Name;
253+
$version = $template.Directory.Name;
254+
$docName = "$($templateName)_$version";
255+
# Generate markdown
256+
Invoke-PSDocument -Module PSDocs.Azure -OutputPath out/docs/ -InputObject $template.FullName -InstanceName $docName;
257+
}
258+
shell: pwsh
259+
260+
# STEP 2: Copy files to a storage account
261+
- name: Copy files to a storage account
262+
uses: bacongobbler/azure-blob-storage-upload@v1.1.1
263+
with:
264+
connection_string: ${{ secrets.STORAGEACCOUNTSECRET }}
265+
container_name: ps-docs
266+
source_dir: 'out/docs/*'
267+
```
268+
269+
165270
## Changes and versioning
166271

167272
Modules in this repository will use the [semantic versioning](http://semver.org/) model to declare breaking changes from v1.0.0.
@@ -198,3 +303,4 @@ This project is [licensed under the MIT License](LICENSE).
198303
[ci-badge]: https://dev.azure.com/PSDocs/PSDocs.Azure/_apis/build/status/PSDocs.Azure-CI?branchName=main
199304
[module]: https://www.powershellgallery.com/packages/PSDocs.Azure
200305
[engine]: https://github.com/BernieWhite/PSDocs
306+
[create-workflow]: https://help.github.com/en/articles/configuring-a-workflow#creating-a-workflow-file

0 commit comments

Comments
 (0)