👷 Disable re-generation of docs every time #99
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: Build and Publish Module | |
on: | |
push: # Only trigger the workflow if there is a push | |
branches: [ | |
main, # This will build as well as release (Ideally this should only happen as soon as a PR from develop branch is merged.) | |
develop, # This will only build but not release - see the if condition inside the "release" job below. | |
] | |
workflow_dispatch: #Enables the possibility to trigger the workflow manually from GitHub Actions in the repository | |
jobs: | |
# Configure skip-duplicate actions | |
pre_job: | |
# continue-on-error: true # Uncomment once integration is finished | |
runs-on: ubuntu-latest | |
# Map a step output to a job output | |
outputs: | |
should_skip: ${{ steps.skip_check.outputs.should_skip }} | |
steps: | |
- id: skip_check | |
uses: fkirc/skip-duplicate-actions@master | |
with: | |
# All of these options are optional, so you can remove them if you are happy with the defaults | |
concurrent_skipping: "never" | |
skip_after_successful_duplicate: "false" | |
paths_ignore: '["**.md", ".gitignore", ".prettierrc", "**/Docs/**", "assets/**", "**.yml"]' | |
do_not_skip: '["workflow_dispatch", "schedule"]' | |
# 1st Job -- Building the module, skip job if should_skip is true | |
build: | |
needs: pre_job | |
if: ${{ needs.pre_job.outputs.should_skip != 'true' }} | |
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, PSReadLine | |
# 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 | |
#! Hardcoded module name here and stored as env variable, used by this job only. This step is duplicated in the next job. | |
# Running a powershell command to save the module name as an Environment Variable | |
- name: 🔧 Set Module Name | |
id: set_module_name | |
shell: pwsh | |
run: | | |
Write-Host $Env:GITHUB_REF | |
$ModuleName="PoshCodex" | |
echo "MODULE_NAME=$ModuleName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append | |
# Running the InvokeBuild Module Invoke-Build command | |
# WITH BUMP VERSION, FOR BOTH BRANCHES. | |
# Version is bumped regardless of branch, but publish to gallery will only happen if the commit reaches the main branch. | |
# And if it does reach the main branch, it means builds have passed anyway. | |
# So this workflow should be fine. | |
- name: ⚒️ Invoke Build, bump versions and set env.MODULE_VERSION variable | |
shell: pwsh | |
run: | | |
Invoke-Build -File ./${{ env.MODULE_NAME }}/build.ps1 -BumpVersion -Verbose | |
$moduleversion=(Test-ModuleManifest -Path ".\${{ env.MODULE_NAME }}\Source\${{ env.MODULE_NAME }}.psd1").Version.toString() | |
echo "Setting Module version environment variable: $moduleversion" | |
echo "MODULE_VERSION=$moduleversion" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append | |
echo "Bumping Scoop manifest version to $moduleversion" | |
(Get-Content .\poshcodex.json) -replace '"version": "([0-9.]{5,})"', "`"version`": `"$moduleversion`"" | Out-File .\poshcodex.json | |
# Pushing the changes from InvokeBuild to the main branch | |
# DON'T COMMIT THE VERSION BUMP IF IT'S DEVELOP BRANCH. | |
- name: 📌 Push changes to Git Repository | |
if: github.ref == 'refs/heads/main' | |
run: | | |
git config --global user.name 'rishi255' | |
git config --global user.email 'rishikeshrachchh@gmail.com' | |
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository }} | |
git add . | |
if [ $(git status --porcelain | wc -l) -ge 0 ]; then | |
echo "Working tree not clean! Displaying git status:" | |
git status | |
echo "Committing new version bump to v${{ env.MODULE_VERSION }}!" | |
git commit -am "💎 Bump to v${{ env.MODULE_VERSION }}" | |
git push | |
fi | |
echo "Getting module number from GitHub env variables: " | |
echo "MODULE_VERSION = ${{ env.MODULE_VERSION }}" | |
# DON'T PUSH THE TAG IF IT'S DEVELOP BRANCH. | |
- name: 🔖 Tag version | |
id: tag | |
if: github.ref == 'refs/heads/main' | |
uses: anothrNick/github-tag-action@master | |
env: | |
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
CUSTOM_TAG: v${{ env.MODULE_VERSION }} | |
- name: ⚙️ Check created tag | |
id: check_tagged | |
run: | | |
echo "Github ref: ${{ github.ref }}, New tag: '${{ steps.tag.outputs.new_tag }}', tag: '${{ steps.tag.outputs.tag }}'" | |
echo "::set-output name=tagged::${{ (steps.tag.outputs.new_tag == steps.tag.outputs.tag) }}" | |
echo "tagged = ${{ (steps.tag.outputs.new_tag == steps.tag.outputs.tag) }}" | |
tag_with_v=${{ steps.tag.outputs.new_tag }} | |
echo "::set-output name=tag_without_v::${tag_with_v:1}" | |
echo "Tag without v: ${tag_with_v:1}" | |
# Uploads the build powershell module as an artifact | |
- name: 📌 Upload Build Artifact | |
uses: actions/upload-artifact@v4 | |
with: | |
name: module-artifact # Naming the powershell module artifact | |
path: ./${{ env.MODULE_NAME }}/Output/ # Saving the powershell module artifact to the path ./PoshCodex/Output/ | |
- name: debug | |
working-directory: ./${{ env.MODULE_NAME }}/Output/ | |
run: | | |
echo "Current directory:" | |
pwd | |
echo "Stuff in curr dir:" | |
ls | |
echo "Stuff in 2 directories up:" | |
ls ../.. | |
outputs: | |
tagged: ${{ steps.check_tagged.outputs.tagged }} | |
tag_without_v: ${{ steps.check_tagged.outputs.tag_without_v }} | |
tag: ${{ steps.tag.outputs.tag }} | |
# 2nd Job -- Releasing the module, skip job if should_skip is true | |
release: | |
needs: [pre_job, build] | |
# Only run the "release" job if current branch is main, AND should_skip is NOT 'true' | |
# This will break if 'pull_request' is added to the workflow triggers, since PRs don't have a current branch before they are merged. | |
if: github.ref == 'refs/heads/main' && needs.pre_job.outputs.should_skip != 'true' | |
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: actions/download-artifact@v4 | |
with: | |
name: module-artifact # Name of the powershell module artifact | |
path: ./Artifact/ # Downloads the module to the path ./Artifact/ | |
#! Hardcoded module name here as can't use env variable from previous job without complicating code | |
# Running a powershell command to save the module name as an Environment Variable | |
- name: 🔧 Set Module Name | |
run: | | |
Write-Host $Env:GITHUB_REF | |
$ModuleName="PoshCodex" | |
echo "MODULE_NAME=$ModuleName" | Out-File -FilePath $Env:GITHUB_ENV -Encoding utf-8 -Append | |
echo "needs.build.outputs.tagged = ${{ needs.build.outputs.tagged }}" | |
shell: pwsh | |
# Publishing the module to powershell gallery | |
- name: ⬆️ Publish to Powershell Gallery | |
uses: pcgeek86/publish-powershell-module-action@v20 | |
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 | |
- name: ⛓️ Make tarball and zipball for GitHub Release | |
working-directory: ./Artifact/${{ env.MODULE_NAME }}/${{ needs.build.outputs.tag_without_v }} | |
run: | | |
tar -cvf PoshCodex.tar . | |
zip -r PoshCodex.zip . -x *.tar | |
mv PoshCodex.tar ../../../PoshCodex.tar | |
mv PoshCodex.zip ../../../PoshCodex.zip | |
# Since this only runs on the main branch, it means that a tag was created right after commit in the build step. | |
# That tag is published as a release on GitHub. | |
# Release name defaults to tag name. | |
- name: 🛎️ Create GitHub Release | |
if: ${{ needs.build.outputs.tagged == 'true' }} | |
uses: ncipollo/release-action@v1 | |
with: | |
artifacts: "PoshCodex.zip,PoshCodex.tar" | |
token: ${{ secrets.GITHUB_TOKEN }} | |
tag: ${{ needs.build.outputs.tag }} |