From bba0a9d4f1ceb448ea4513eac9fbf4d31e9f5904 Mon Sep 17 00:00:00 2001 From: Raymond LaRose Date: Wed, 12 Mar 2025 12:15:57 -0400 Subject: [PATCH] Add GitHub Actions workflow for publishing PowerShell module to Gitea --- .../.gitea/workflows/Publish Module.yaml | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) create mode 100644 PS-GiteaUtilities/.gitea/workflows/Publish Module.yaml diff --git a/PS-GiteaUtilities/.gitea/workflows/Publish Module.yaml b/PS-GiteaUtilities/.gitea/workflows/Publish Module.yaml new file mode 100644 index 0000000..46c63ee --- /dev/null +++ b/PS-GiteaUtilities/.gitea/workflows/Publish Module.yaml @@ -0,0 +1,90 @@ +name: Publish Powershell Module to Gitea Repository +run-name: ${{ gitea.actor }} is publishing module ${{ gitea.repository }} to Gitea + +on: + push: + tags: + - '*.*.*' + workflow_dispatch: + +jobs: + deploy: + 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 'GiteaPrivate' ` + -SourceLocation 'https://gitea.norwichct.tech/api/packages/cityofnorwich/nuget' ` + -PublishLocation 'https://gitea.norwichct.tech/api/packages/cityofnorwich/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 ".*" | Select-Object -ExpandProperty Name + Write-Host "Publishing module $module to Gitea" + Publish-Module -Path $module -Repository 'GiteaPrivate' -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