Skip to content

Commit 3f0fb33

Browse files
Add GitHub Actions workflow for module deployment
This commit introduces a new GitHub Actions workflow to automate the deployment of the module to the PowerShell Gallery. It includes steps for packaging the module, publishing it, and creating a changelog pull request. This enhancement aims to streamline the release process and ensure consistency in deployments for Pester Help Tests. Thank you!
1 parent 0ac280c commit 3f0fb33

2 files changed

Lines changed: 98 additions & 10 deletions

File tree

Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
on:
2+
push:
3+
branches:
4+
- main
5+
paths-ignore:
6+
- CHANGELOG.md
7+
- .vscode/**
8+
- .github/**
9+
- images/**
10+
- tests/**
11+
- '**.md'
12+
- '**.yml'
13+
tags:
14+
- '**'
15+
- '!*preview*'
16+
env:
17+
buildFolderName: output
18+
buildArtifactName: output
19+
20+
21+
name: Deploy Module
22+
# This workflow is triggered on push to the main branch and deploys the module to the PowerShell Gallery and creates a GitHub Release.
23+
jobs:
24+
Build_Stage_Package_Module:
25+
name: Package Module
26+
runs-on: ubuntu-latest
27+
steps:
28+
- name: Checkout Code
29+
uses: actions/checkout@v3
30+
with:
31+
ref: ${{ github.head_ref }} # checkout the correct branch name
32+
fetch-depth: 0
33+
- name: Install GitVersion
34+
uses: gittools/actions/gitversion/setup@v0.9.15
35+
with:
36+
versionSpec: 5.x
37+
- name: Evaluate Next Version
38+
uses: gittools/actions/gitversion/execute@v0.9.15
39+
with:
40+
configFilePath: GitVersion.yml
41+
- name: Build & Package Module
42+
shell: pwsh
43+
run: ./build.ps1 -ResolveDependency -tasks pack
44+
env:
45+
ModuleVersion: ${{ env.gitVersion.MajorMinorPatch }}
46+
- name: Publish Build Artifact
47+
uses: actions/upload-artifact@v4
48+
with:
49+
name: ${{ env.buildArtifactName }}
50+
path: ${{ env.buildFolderName }}/
51+
52+
Deploy_Stage_Deploy_Module:
53+
name: Deploy Module
54+
runs-on: ubuntu-latest
55+
needs:
56+
- Build_Stage_Package_Module
57+
if: ${{ success() && (github.ref == 'refs/heads/develop' || startsWith(github.ref, 'refs/tags/')) }}
58+
steps:
59+
- name: Checkout Code
60+
uses: actions/checkout@v3
61+
with:
62+
ref: ${{ github.head_ref }} # checkout the correct branch name
63+
fetch-depth: 0
64+
- name: Download Build Artifact
65+
uses: actions/download-artifact@v4
66+
with:
67+
name: ${{ env.buildArtifactName }}
68+
path: ${{ env.buildFolderName }}
69+
- name: Publish Release
70+
shell: pwsh
71+
run: ./build.ps1 -tasks publish
72+
env:
73+
GitHubToken: ${{ secrets.GitHubToken }}
74+
GalleryApiToken: ${{ secrets.GalleryApiToken }}
75+
- name: Send Changelog PR
76+
shell: pwsh
77+
run: ./build.ps1 -tasks Create_ChangeLog_GitHub_PR
78+
env:
79+
GitHubToken: ${{ secrets.GitHubToken }}
80+
GalleryApiToken: ${{ secrets.GalleryApiToken }}
81+
ReleaseBranch: main
82+
MainGitBranch: main

build.yaml

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -75,10 +75,11 @@ BuildWorkflow:
7575
#- Merge_CodeCoverage_Files
7676

7777
publish:
78+
- Create_Release_Git_Tag
7879
- Publish_Release_To_GitHub # Runs first, if token is expired it will fail early
7980
# - Publish_GitHub_Wiki_Content
80-
8181
- publish_module_to_gallery
82+
- Create_Changelog_Branch
8283

8384
####################################################
8485
# PESTER Configuration #
@@ -120,15 +121,6 @@ Pester:
120121
#CodeCoverageFilePattern: JaCoCo_Merge.xml # the pattern used to search all pipeline test job artifacts
121122
#CodeCoverageMergedOutputFile: JaCoCo_coverage.xml # the file that is created for the merged code coverage
122123

123-
DscTest:
124-
ExcludeTag:
125-
- "Common Tests - New Error-Level Script Analyzer Rules"
126-
Tag:
127-
ExcludeSourceFile:
128-
- output
129-
ExcludeModuleFile:
130-
- Modules/DscResource.Common
131-
# - Templates
132124

133125
# Import ModuleBuilder tasks from a specific PowerShell module using the build
134126
# task's alias. Wildcard * can be used to specify all tasks that has a similar
@@ -152,3 +144,17 @@ TaskHeader: |
152144
Write-Build DarkGray " $Path"
153145
Write-Build DarkGray " $($Task.InvocationInfo.ScriptName):$($Task.InvocationInfo.ScriptLineNumber)"
154146
""
147+
####################################################
148+
# Changelog Configuration #
149+
####################################################
150+
ChangelogConfig:
151+
FilesToAdd:
152+
- 'CHANGELOG.md'
153+
UpdateChangelogOnPrerelease: false
154+
155+
####################################################
156+
# Git Configuration #
157+
####################################################
158+
GitConfig:
159+
UserName: Automation Bot
160+
UserEmail: automation_bot@fabrictools.io

0 commit comments

Comments
 (0)