-
Notifications
You must be signed in to change notification settings - Fork 0
121 lines (100 loc) · 3.74 KB
/
Copy pathpublish.yml
File metadata and controls
121 lines (100 loc) · 3.74 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
name: Publish NuGet Package
on:
workflow_dispatch:
inputs:
version:
description: Release version without the v prefix, for example 1.0.7
required: true
type: string
permissions:
contents: write
packages: write
jobs:
publish:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 10.0.x
- name: Resolve package version
id: version
shell: bash
run: |
PACKAGE_VERSION="${{ inputs.version }}"
PACKAGE_VERSION="${PACKAGE_VERSION#v}"
if [[ ! "${PACKAGE_VERSION}" =~ ^[0-9]+\.[0-9]+\.[0-9]+([-.][0-9A-Za-z.-]+)?$ ]]; then
echo "Version must be a semantic version such as 1.0.7 or 1.0.7-rc.1." >&2
exit 1
fi
TAG_NAME="v${PACKAGE_VERSION}"
CORE_VERSION="${PACKAGE_VERSION%%-*}"
IFS='.' read -r major minor patch <<< "${CORE_VERSION}"
FILE_VERSION="${major}.${minor}.${patch}.0"
git fetch --tags --force
if git rev-parse -q --verify "refs/tags/${TAG_NAME}" >/dev/null; then
echo "Tag ${TAG_NAME} already exists." >&2
exit 1
fi
echo "tag_name=${TAG_NAME}" >> "${GITHUB_OUTPUT}"
echo "package_version=${PACKAGE_VERSION}" >> "${GITHUB_OUTPUT}"
echo "file_version=${FILE_VERSION}" >> "${GITHUB_OUTPUT}"
- name: Restore
run: dotnet restore YCode.CLI/YCode.CLI.csproj
- name: Pack
run: >
dotnet pack YCode.CLI/YCode.CLI.csproj
--configuration Release
--no-restore
-p:ContinuousIntegrationBuild=true
-p:Version=${{ steps.version.outputs.package_version }}
-p:PackageVersion=${{ steps.version.outputs.package_version }}
-p:AssemblyVersion=${{ steps.version.outputs.file_version }}
-p:FileVersion=${{ steps.version.outputs.file_version }}
-p:InformationalVersion=${{ steps.version.outputs.package_version }}
--output ${{ github.workspace }}/artifacts
- name: Publish to NuGet.org
shell: bash
run: |
shopt -s nullglob
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
if (( ${#packages[@]} == 0 )); then
echo "No .nupkg files were generated." >&2
exit 1
fi
dotnet nuget push "${packages[@]}" \
--api-key "${{ secrets.NUGET_API_KEY }}" \
--source "https://api.nuget.org/v3/index.json" \
--skip-duplicate
- name: Configure GitHub Packages source
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: Publish to GitHub Packages
shell: bash
run: |
shopt -s nullglob
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
dotnet nuget push "${packages[@]}" \
--source github \
--api-key "${{ secrets.GITHUB_TOKEN }}" \
--skip-duplicate
- name: Create GitHub Release
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}
shell: bash
run: |
shopt -s nullglob
packages=("${{ github.workspace }}/artifacts/"*.nupkg)
gh release create "${{ steps.version.outputs.tag_name }}" "${packages[@]}" \
--target "${GITHUB_SHA}" \
--title "${{ steps.version.outputs.tag_name }}" \
--generate-notes