-
Notifications
You must be signed in to change notification settings - Fork 1
126 lines (113 loc) · 5.01 KB
/
nuget-linklib.yml
File metadata and controls
126 lines (113 loc) · 5.01 KB
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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
name: NuGet ThreeByte.LinkLib.Shared
on:
pull_request:
branches:
- main
paths:
- "ThreeByte.LinkLib/ThreeByte.LinkLib.Shared/**"
types:
- closed
env:
GITHUB_REPO: "three-byte.link-lib"
GITHUB_USER_TOKEN: ${{ secrets.GHPAT }}
PROJECT_PATH: "ThreeByte.LinkLib"
PROJECT_NAME: "ThreeByte.LinkLib.Shared"
INITIAL_PACKAGE_VERSION: "1.0.0"
NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }}
jobs:
variables:
name: Build and push Nuget package
if: github.event.pull_request.merged == true
runs-on: ubuntu-latest
outputs:
package_new_version: ${{ steps.package_new_version.outputs.package_new_version }}
package_version: ${{ steps.package_version.outputs.package_version }}
first_deploy: ${{ steps.package_version.outputs.first_deploy }}
steps:
- name: GitHub actions Workspace Cleaner
uses: jstone28/runner-workspace-cleaner@v1.0.0
- name: Check labels
uses: docker://agilepathway/pull-request-label-checker:latest
id: check_label
with:
one_of: major,minor,patch
repo_token: ${{ secrets.GHPAT }}
- name: Checkout
uses: actions/checkout@v4
- name: Setup .NET Core
uses: actions/setup-dotnet@v4
with:
dotnet-version: "9.0.x"
- name: Restore dependencies
run: dotnet restore
working-directory: ./${{ env.PROJECT_PATH }}
- name: Build the project
run: dotnet build --configuration Release --no-restore
working-directory: ./${{ env.PROJECT_PATH }}
- name: Get package version
id: package_version
run: |
package_name_lower_case=$(echo ${{ env.PROJECT_NAME }} | tr '[:upper:]' '[:lower:]' )
status_code=$(curl -o /dev/null -s -w "%{http_code}" "https://api.nuget.org/v3-flatcontainer/$package_name_lower_case/index.json")
if [ "$status_code" -eq 200 ]; then
echo "Package '$package_name_lower_case' exists on NuGet.org."
first_deploy="false"
package_version=$(curl -s https://api.nuget.org/v3-flatcontainer/$package_name_lower_case/index.json | grep -o '"[0-9]\+\(\.[0-9]\+\)*"' | tail -n 1 | tr -d '"')
else
echo "Package '$package_name_lower_case' does NOT exist on NuGet.org."
package_version=${{ env.INITIAL_PACKAGE_VERSION }}
first_deploy="true"
fi
echo -e "package_version\t= $package_version"
echo -e "first_deploy\t= $first_deploy"
echo "package_version=$package_version" >> $GITHUB_OUTPUT
echo "first_deploy=$first_deploy" >> $GITHUB_OUTPUT
- name: Get labels for closed PR
if: github.event_name != 'workflow_dispatch'
run: |
PR_NUMBER=${{ github.event.pull_request.number }}
REPO="${{ github.repository }}"
label=$(curl -s -H "Authorization: token ${{ env.GITHUB_USER_TOKEN }}" \
"https://api.github.com/repos/$REPO/issues/$PR_NUMBER/labels" | jq -r '.[].name')
echo "Label for PR #$PR_NUMBER: $label"
echo "label=$label" >> $GITHUB_ENV
- name: Get new version
id: package_new_version
run: |
label_name=${{ env.label }}
echo -e "Label name:\t\t $label_name"
major=$(echo ${{ steps.package_version.outputs.package_version }} | cut -d "." -f1)
minor=$(echo ${{ steps.package_version.outputs.package_version }} | cut -d "." -f2)
patch=$(echo ${{ steps.package_version.outputs.package_version }} | cut -d "." -f3)
echo -e "Current version:\t $major.$minor.$patch"
if [[ $label_name == 'major' ]]; then
major=$((major+1))
if [[ $minor -ne 0 ]]; then
minor=0
fi
if [[ $patch -ne 0 ]]; then
patch=0
fi
elif [[ $label_name == 'minor' ]]; then
minor=$((minor+1))
if [[ $patch -ne 0 ]]; then
patch=0
fi
elif [[ $label_name == 'patch' ]]; then
patch=$((patch+1))
fi
if [ ${{ steps.package_version.outputs.first_deploy }} == "true" ]; then
package_new_version=${{ env.INITIAL_PACKAGE_VERSION }}
else
package_new_version=$major"."$minor"."$patch
fi
echo -e "Package new version:\t\t $package_new_version"
echo "package_new_version=$package_new_version" >> $GITHUB_OUTPUT
- name: Create NuGet Package
run: dotnet pack --configuration Release --no-build --output nupkg --property:Version=${{ steps.package_new_version.outputs.package_new_version }}
working-directory: ./${{ env.PROJECT_PATH }}/${{ env.PROJECT_NAME }}
- name: Publish Nuget Package
run: |
dotnet nuget push ./${{ env.PROJECT_PATH }}/${{ env.PROJECT_NAME }}/nupkg/${{ env.PROJECT_NAME }}.${{ steps.package_new_version.outputs.package_new_version }}.nupkg \
--api-key ${{ secrets.NUGET_API_KEY }} \
--source https://api.nuget.org/v3/index.json --skip-duplicate