-
-
Notifications
You must be signed in to change notification settings - Fork 1
157 lines (140 loc) · 5.59 KB
/
Copy pathrelease.yml
File metadata and controls
157 lines (140 loc) · 5.59 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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: .NET Core Desktop Release
env:
NUGET_SERVER_URL: "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
GH_TOKEN: ${{ secrets.LATENCY_PAT }}
on:
push:
tags: 'v[0-9]+.[0-9]+.[0-9]+'
workflow_dispatch:
jobs:
pre_job:
runs-on: ubuntu-latest
outputs:
should_skip: ${{ steps.skip_check.outputs.should_skip }}
steps:
- id: skip_check
uses: fkirc/skip-duplicate-actions@v5.3.1
with:
skip_after_successful_duplicate: 'true'
release:
needs: pre_job
if: ${{ needs.pre_job.outputs.should_skip != 'true' }}
runs-on: ${{ matrix.os }}
permissions:
packages: write
contents: write # write permission is required to create a github release
pull-requests: write # write permission is required for autolabeler otherwise, read permission is required at least
strategy:
matrix:
os: [self-hosted] #, ubuntu-latest, windows-latest]
BuildConfiguration: [ Release ]
max-parallel: 2
steps:
- name: Get PROJECT_NAME
id: project-name
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
split=(${GITHUB_REPOSITORY//\// })
elif [ "$RUNNER_OS" == "Windows" ]; then
split=(${GITHUB_REPOSITORY////// })
else
echo "$RUNNER_OS not supported"
exit 1
fi
index=$((${#split[@]}-1))
project_tag=${split[$index]}
echo "$project_tag"
echo "PROJECT_NAME=$project_tag" >> $GITHUB_ENV
- name: Get README.md Description & PACKAGE_VERSION
id: readme-desc
shell: bash
run: |
if [ "$RUNNER_OS" == "Linux" ]; then
filenames=$(ls ${{ github.workspace }})
elif [ "$RUNNER_OS" == "Windows" ]; then
filenames=$(ls ${GITHUB_WORKSPACE//\//\\ })
else
echo "$RUNNER_OS not supported"
exit 1
fi
for filename in ${filenames[@]}; do
if [ -f $filename -a "$filename" = "README.md" ]; then
desc=$(sed -n '2{P;q;}' $filename | sed 's/\n$//' | sed 's/\r$//' | cut -c 5- )
echo "$desc"
echo "README_DESC=$desc" >> $GITHUB_ENV
regex='\| VERSION:.*-([0-9]+(\.[0-9]+){2,})[-a-z]*'
if [[ $(grep VERSION: $filename) =~ $regex ]]; then
package_version=${BASH_REMATCH[1]}
echo "$package_version"
echo "PACKAGE_VERSION=$package_version" >> $GITHUB_ENV
fi
break
fi
done
- name: Query Release (if exists)
shell: bash
run: |
version=v${{ env.PACKAGE_VERSION }}
cd src
array=$(gh release list -O asc | cut -f3)
cd ..
echo "FIRST_RELEASE=$(echo $array | awk '{print $1}')" >> $GITHUB_ENV
if [[ ${array[@]} =~ $version ]]; then
echo "Release '$version' was found."
echo "RELEASE_FOUND=true" >> $GITHUB_ENV
else
echo "No release exists with version '$version'."
echo "RELEASE_FOUND=false" >> $GITHUB_ENV
fi
- name: Delete Release
if: ${{ env.release_found == 'true' }}
shell: bash
run: |
echo "Deleting current release '$version'"
gh release delete $version --cleanup-tag
env:
release_found: '${{ env.RELEASE_FOUND }}'
version: 'v${{ env.PACKAGE_VERSION }}'
- name: Create Release
shell: bash
run: |
draft=false
prerelease=false
body="${{ env.README_DESC }}
${{ steps.github_release.outputs.changelog }}"
if [ "$draft" = "true" ]; then
d='-d '
fi
if [ "$prerelease" = "true" ]; then
p='-p '
fi
echo "gh release create \"v${{ env.PACKAGE_VERSION }}\" ${p}${d}--generate-notes --notes-start-tag \"${{ env.FIRST_RELEASE }}\" --title \"${{ env.PROJECT_NAME }}\" -n \"$body\""
gh release create "v${{ env.PACKAGE_VERSION }}" ${p}${d}--generate-notes --notes-start-tag "${{ env.FIRST_RELEASE }}" --title "${{ env.PROJECT_NAME }}" -n "$body"
- name: Check If NuGet Package Exists
id: locate-package
shell: bash
run: |
echo "nuget-exists=false" >> $GITHUB_OUTPUT
array=$(nuget search "${{ env.PROJECT_NAME }}" -Source "github" | grep "No results found.\|^>")
if [ "$array" != "No results found." ]; then
ary=($(echo "$array" | grep '^> ' | cut -c 3- | awk '{print $1} {print $3}'))
name=${ary[0]}
version=${ary[1]}
if [ "$name" = "${{ env.PROJECT_NAME }}" -a "$version" = "${{ env.PACKAGE_VERSION }}" ]; then
echo "Package '${{ env.PROJECT_NAME }}.${{ env.PACKAGE_VERSION }}.nupkg' was found to exist."
echo "nuget-exists=true" >> $GITHUB_OUTPUT
fi
fi
- name: Remove Existing NuGet Package
if: ${{ steps.locate-package.outputs.nuget-exists == 'true' }}
#run: dotnet nuget delete ${{ env.PROJECT_NAME }} ${{ env.PACKAGE_VERSION }} --api-key ${{ secrets.NUGET_AUTH_TOKEN }} --non-interactive
uses: actions/delete-package-versions@v5.0.0
with:
owner: ${{ github.repository_owner }}
package-name: ${{ env.PROJECT_NAME }}
package-type: 'nuget'
token: ${{ secrets.NUGET_AUTH_TOKEN }}
- name: Push package to GitHub packages
run: |
dotnet nuget push "D:\Source\Packages\${{ env.PROJECT_NAME }}.${{ env.PACKAGE_VERSION }}.nupkg" -n --skip-duplicate -k ${{ secrets.NUGET_AUTH_TOKEN }}