|
| 1 | +name: Publish to PSGallery |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + |
| 6 | +permissions: |
| 7 | + contents: read |
| 8 | + |
| 9 | +jobs: |
| 10 | + publish: |
| 11 | + name: Publish to PSGallery |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Get Latest Release |
| 16 | + id: release |
| 17 | + env: |
| 18 | + GH_TOKEN: ${{ github.token }} |
| 19 | + run: | |
| 20 | + release=$(gh api repos/${{ github.repository }}/releases/latest) |
| 21 | + tag=$(echo "$release" | jq -r '.tag_name') |
| 22 | + echo "tag=$tag" >> "$GITHUB_OUTPUT" |
| 23 | +
|
| 24 | + asset_url=$(echo "$release" | jq -r '.assets[] | select(.name | endswith(".nupkg")) | .url') |
| 25 | + if [[ -z "$asset_url" ]]; then |
| 26 | + echo "::error::No .nupkg asset found in release $tag" |
| 27 | + exit 1 |
| 28 | + fi |
| 29 | +
|
| 30 | + asset_name=$(echo "$release" | jq -r '.assets[] | select(.name | endswith(".nupkg")) | .name') |
| 31 | + echo "asset_url=$asset_url" >> "$GITHUB_OUTPUT" |
| 32 | + echo "asset_name=$asset_name" >> "$GITHUB_OUTPUT" |
| 33 | + echo "Found $asset_name in release $tag" |
| 34 | +
|
| 35 | + - name: Download Latest Module |
| 36 | + env: |
| 37 | + GH_TOKEN: ${{ github.token }} |
| 38 | + run: | |
| 39 | + curl -fSL \ |
| 40 | + -H "Accept: application/octet-stream" \ |
| 41 | + -H "Authorization: token $GH_TOKEN" \ |
| 42 | + "${{ steps.release.outputs.asset_url }}" \ |
| 43 | + -o "${{ steps.release.outputs.asset_name }}" |
| 44 | +
|
| 45 | + - name: Publish to PSGallery |
| 46 | + env: |
| 47 | + PS_GALLERY_API_KEY: ${{ secrets.PS_GALLERY_API_KEY }} |
| 48 | + run: | |
| 49 | + if [[ -z "$PS_GALLERY_API_KEY" ]]; then |
| 50 | + echo "::error::PS_GALLERY_API_KEY secret is not set at repo or org level" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | +
|
| 54 | + dotnet nuget push "${{ steps.release.outputs.asset_name }}" \ |
| 55 | + --api-key "$PS_GALLERY_API_KEY" \ |
| 56 | + --source https://www.powershellgallery.com/api/v2/package \ |
| 57 | + --dry-run |
0 commit comments