This file contains hidden or 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: Test PowerShell on Windows | ||
| on: | ||
| pull_request: # Only trigger the workflow if there is a pull request to the main branch | ||
| branches: [ main ] | ||
| workflow_dispatch: # Enables the possibility to trigger the workflow manually | ||
| jobs: | ||
| tests: | ||
| name: Pester test and ScriptAnalyzer | ||
| runs-on: windows-latest | ||
| steps: | ||
| - name: Check out repository code | ||
| uses: actions/checkout@v2 | ||
| - name: Install PSScriptAnalyzer module | ||
| if: success() | ||
| shell: pwsh | ||
| run: | | ||
| Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
| Install-Module PSScriptAnalyzer -ErrorAction Stop | ||
| - name: Lint with PSScriptAnalyzer | ||
| if: success() | ||
| shell: pwsh | ||
| run: | | ||
| Invoke-ScriptAnalyzer -Path .\Public\*.ps1 -Recurse -Outvariable issues -ExcludeRule PSAvoidUsingWriteHost,SUseShouldProcessForStateChangingFunctions | ||
| $errors = $issues.Where({$_.Severity -eq 'Error'}) | ||
| $warnings = $issues.Where({$_.Severity -eq 'Warning'}) | ||
| if ($errors) { | ||
| Write-Error "There were $($errors.Count) errors and $($warnings.Count) warnings total." -ErrorAction Stop | ||
| } else { | ||
| Write-Output "There were $($errors.Count) errors and $($warnings.Count) warnings total." | ||
| } | ||
| - name: Deploy docs | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| - name: Checkout main | ||
| uses: actions/checkout@v2 | ||
| - name: Deploy docs | ||
| uses: mhausenblas/mkdocs-deploy-gh-pages@master | ||
| # Or use mhausenblas/mkdocs-deploy-gh-pages@nomaterial to build without the mkdocs-material theme | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
| CONFIG_FILE: ./docs/mkdocs.yml | ||
| name: Build Module | ||
| on: | ||
| pull_request: # Only trigger the workflow if there is a pull request to the main branch | ||
| branches: [ main ] | ||
| workflow_dispatch: # Enables the possibility to trigger the workflow manually | ||
| jobs: | ||
| # 1st Job -- Building the module | ||
| build: | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Checkout the main branch | ||
| - uses: actions/checkout@main | ||
| # Setting up required powershell modules | ||
| - name: Set required PowerShell modules | ||
| id: psmodulecache | ||
| uses: potatoqualitee/psmodulecache@v1 | ||
| with: | ||
| modules-to-cache: Pester, PSScriptAnalyzer, InvokeBuild, platyPS | ||
| # Setting up the powershell module cache | ||
| - name: Setup PowerShell module cache | ||
| id: cacher | ||
| uses: actions/cache@v2 | ||
| with: | ||
| path: ${{ steps.psmodulecache.outputs.modulepath }} | ||
| key: ${{ steps.psmodulecache.outputs.keygen }} | ||
| # Installing the required powershell module, if not cached | ||
| - name: Install required PowerShell modules | ||
| if: steps.cacher.outputs.cache-hit != 'true' | ||
| shell: pwsh | ||
| run: | | ||
| Set-PSRepository PSGallery -InstallationPolicy Trusted | ||
| Install-Module ${{ steps.psmodulecache.outputs.needed }} -ErrorAction Stop | ||
| # Running the InvokeBuild Module Invoke-Build command with "Release configuration" | ||
| - name: Invoke Build | ||
| shell: pwsh | ||
| run: pwsh -command "Invoke-Build -File ./build.ps1 -Configuration 'Release' -ExportAlias" | ||
| # Pushing the changes from InvokeBuild to the main branch | ||
| - name: Push changes to Git Repository | ||
| run: | | ||
| git config --global user.name 'ScriptingChris' | ||
| git config --global user.email 'christian@scriptingchris.tech' | ||
| git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | ||
| git add . | ||
| git commit -am "Pushing Artifacts" | ||
| git push | ||
| # Uploads the build powershell module as an artifact | ||
| - name: Upload Build Artifact | ||
| uses: actions/upload-artifact@v2.2.3 | ||
| with: | ||
| name: module-artifact # Naming the powershell module artifact | ||
| path: ./Output/ # Saving the powershell module artifact to the path ./Output/ | ||
| # 2nd Job -- Releasing the module | ||
| release: | ||
| needs: build | ||
| runs-on: ubuntu-latest | ||
| steps: | ||
| # Check out the main branch | ||
| - uses: actions/checkout@main | ||
| # Downloads the powershell module build artifact made in the build step | ||
| - name: Download build artifact | ||
| uses: aochmann/actions-download-artifact@1.0.4 | ||
| with: | ||
| repo: ${{github.repository}} | ||
| name: module-artifact # Name of the powershell module artifact | ||
| path: Artifact/ # Downloads the module to the path ./Artifact/ | ||
| # Running a powershell command to save the module name as an Environment Variable | ||
| - name: Get Module Name | ||
| run: | | ||
| Write-Host $Env:GITHUB_REF | ||
| $ModuleName = (Get-ChildItem -Path ./Artifact/).Name | ||
| echo "MODULE_NAME=$ModuleName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append | ||
| shell: pwsh | ||
| # Publishing the module to powershell gallery | ||
| - name: Publish to Powershell Gallery | ||
| # You may pin to the exact commit or the version. | ||
| # uses: pcgeek86/publish-powershell-module-action@2a7837ce0746ea58c40574d8d6cbc6c44238edb7 | ||
| uses: pcgeek86/publish-powershell-module-action@v19 | ||
| with: | ||
| modulePath: ./Artifact/${{ env.MODULE_NAME }} # Using the environment variable to find the module name | ||
| NuGetApiKey: ${{ secrets.NUGETAPIKEY }} # Using the NugetAPI key set in GitHub Secrets | ||