From d7404f1369f5579c70763201e9e5b472e1638c74 Mon Sep 17 00:00:00 2001 From: rlarose Date: Sat, 21 Jun 2025 14:28:13 -0400 Subject: [PATCH] Add .gitea/workflows/Publish Module.yaml --- .gitea/workflows/Publish Module.yaml | 108 +++++++++++++++++++++++++++ 1 file changed, 108 insertions(+) create mode 100644 .gitea/workflows/Publish Module.yaml diff --git a/.gitea/workflows/Publish Module.yaml b/.gitea/workflows/Publish Module.yaml new file mode 100644 index 0000000..3cea7ea --- /dev/null +++ b/.gitea/workflows/Publish Module.yaml @@ -0,0 +1,108 @@ +name: Publish Powershell Module to Gitea Repository +run-name: ${{ gitea.actor }} is publishing module ${{ gitea.repository }} to Gitea + +on: + push: + tags: + - '*.*.*' + workflow_dispatch: + +jobs: + test: + runs-on: ubuntu-22.04 + container: + image: catthehacker/ubuntu:pwsh-latest + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Run pester tests and verify all tests pass + shell: pwsh + run: | + Write-Host "Changing to repository directory: ${{ github.workspace }}" + Set-Location -Path ${{ github.workspace }} + Write-Host "Running Pester tests" + Invoke-Pester -Path . -PassThru | Select-Object -ExpandProperty FailedCount | Should -Be 0 -ErrorAction stop + + deploy: + needs: test + runs-on: ubuntu-22.04 + container: + image: catthehacker/ubuntu:pwsh-latest + + steps: + - name: Check out repository code + uses: actions/checkout@v4 + + - name: Register Gitea Repository + shell: pwsh + run: | + $creds = New-Object System.Management.Automation.PSCredential('actions', ('{{ secrets.PACKAGES_TOKEN }}' | ConvertTo-SecureString -AsPlainText -Force)) + try { + Register-PSRepository -Name 'GiteaPublic' ` + -SourceLocation 'https://gitea.norwichct.tech/api/packages/public/nuget' ` + -PublishLocation 'https://gitea.norwichct.tech/api/packages/public/nuget' ` + -installationPolicy Trusted ` + -Credential $creds + } + catch { + Write-Host "Failed to register Gitea repository" + Write-Host $_.Exception.Message + } + finally { + Write-Host "Gitea repository registered" + } + + - name: Install DotNet + run: | + echo "Installing DotNet" + curl -sSL https://dot.net/v1/dotnet-install.sh | bash /dev/stdin --channel LTS --install-dir /usr/share/dotnet + echo Adding DotNet to PATH + export DOTNET_ROOT=/usr/share/dotnet + export PATH=$PATH:/usr/share/dotnet + + - name: Publish module to Gitea + shell: pwsh + run: | + Write-Host "Adding DotNet to PATH" + $env:DOTNET_ROOT = '/usr/share/dotnet' + $env:PATH = $env:PATH + ':/usr/share/dotnet' + Write-Host "Changing to repository directory: ${{ github.workspace }}" + Set-Location -Path ${{ github.workspace }} + $moduleVersion = git describe --tags + Write-Host "Module version: $moduleVersion" + $module = get-childItem -path . -Directory -Exclude (".*", "Tests") | Select-Object -ExpandProperty Name + Write-Host "Publishing module $module to Gitea" + Publish-Module -Path $module -Repository 'GiteaPublic' -NuGetApiKey "${{ secrets.PACKAGES_TOKEN }}" + Write-Host "Module $module published to Gitea" + + - name: Create draft release + uses: akkuman/gitea-release-action@v1 + with: + token: ${{ secrets.GITEA_TOKEN }} + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + body: | + This release includes the nuget package for the ${{ github.ref_name }} version of the module. + draft: true + prerelease: ${{ contains(github.ref_name, 'rc') }} + + - name: Upload release asset + uses: akkuman/gitea-release-action@v1 + with: + token: ${{ secrets.GITEA_TOKEN }} + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + file: ${{ github.workspace }}/*.nupkg + draft: true + prerelease: ${{ contains(github.ref_name, 'rc') }} + + - name: Publish release + uses: akkuman/gitea-release-action@v1 + with: + token: ${{ secrets.GITEA_TOKEN }} + tag_name: ${{ github.ref_name }} + release_name: Release ${{ github.ref_name }} + draft: false + prerelease: ${{ contains(github.ref_name, 'rc') }} \ No newline at end of file