-
-
Notifications
You must be signed in to change notification settings - Fork 66
80 lines (63 loc) · 2.74 KB
/
publish-package.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
name: Publish NuGet packages
on:
workflow_run:
branches:
- master
workflows:
- "Build .NET project"
types:
- completed
permissions:
packages: write
env:
PACKAGE_NAME: "org.miniscript.MiniScript"
jobs:
check_nuget:
name: Check what kind of NuGet release is required
runs-on: ubuntu-latest
if: ${{ github.event.workflow_run.conclusion == 'success' }}
outputs:
release: ${{ steps.compare.outputs.new-version }}
defaults:
run:
working-directory: MiniScript-cs
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
steps:
- uses: actions/checkout@v3
- name: Get latest package version from Github Packages
id: nuget-ver
run: |
export NUGET_VER=$(gh api -H "Accept: application/vnd.github+json" /users/${{ github.repository_owner }}/packages/nuget/${{ env.PACKAGE_NAME }}/versions | jq '.[0].name' | tr -d '"' | awk -F'-' '{print $1}')
echo "version=${NUGET_VER}" >> $GITHUB_OUTPUT
- name: Compare vs current version
id: compare
run: |
export CURRENT_VER=$(grep -e "Version" Miniscript.csproj | awk -F'>' '{print $2}' | awk -F'<' '{print $1}')
[[ "${{ steps.nuget-ver.outputs.version }}" != "$CURRENT_VER" ]] \
&& echo "new-version=true" >> $GITHUB_OUTPUT \
|| echo "new-version=false" >> $GITHUB_OUTPUT
nuget:
name: Release NuGet package
runs-on: ubuntu-latest
needs: check_nuget
if: ${{ github.event.workflow_run.conclusion == 'success' }}
defaults:
run:
working-directory: MiniScript-cs
steps:
- uses: actions/checkout@v3
- uses: actions/setup-dotnet@v2
with:
dotnet-version: 5.0.x
- name: Authenticate to Github Packages
run: dotnet nuget add source --username "${{ github.repository_owner }}" --password "${{ secrets.GITHUB_TOKEN }}" --store-password-in-clear-text --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Package
run: |
[[ "${{ needs.check_nuget.outputs.release }}" == "true" ]] \
&& dotnet pack -c Release -p:RepositoryBranch="master" -p:RepositoryCommit="$(git rev-parse HEAD)" \
|| dotnet pack -c Release -p:RepositoryBranch="master" -p:RepositoryCommit="$(git rev-parse HEAD)" --version-suffix "p$(git rev-parse --short HEAD)"
- name: Publish to GitHub Packages
run: dotnet nuget push "bin/Release/${{ env.PACKAGE_NAME }}.*.nupkg" --source "github" --api-key "${{ secrets.GHPR_TOKEN }}"
- name: Publish to NuGet
run: dotnet nuget push "bin/Release/${{ env.PACKAGE_NAME }}.*.nupkg" --api-key "${{ secrets.NUGET_API_KEY }}" --source https://api.nuget.org/v3/index.json