1+ name : master
2+
3+ on :
4+ workflow_dispatch :
5+ inputs :
6+ force_version :
7+ description : " The version to use"
8+ required : true
9+ default : " 0.0.0-test"
10+ type : string
11+ push :
12+ branches :
13+ - master
14+ pull_request :
15+ branches :
16+ - master
17+ release :
18+ types :
19+ - published
20+
21+ env :
22+ # Setting these variables allows .NET CLI to use rich color codes in console output
23+ TERM : xterm
24+ DOTNET_SYSTEM_CONSOLE_ALLOW_ANSI_COLOR_REDIRECTION : true
25+ # Skip boilerplate output
26+ DOTNET_SKIP_FIRST_TIME_EXPERIENCE : true
27+ DOTNET_NOLOGO : true
28+ DOTNET_CLI_TELEMETRY_OPTOUT : true
29+
30+ jobs :
31+ # Determine version
32+ version :
33+ runs-on : ubuntu-latest
34+ permissions :
35+ contents : read
36+
37+ steps :
38+ - name : Determine stable version
39+ id : stable-version
40+ if : ${{ github.event_name == 'release' }}
41+ run : |
42+ if ! [[ "${{ github.event.release.tag_name }}" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z].*)?$ ]]; then
43+ echo "Invalid version: ${{ github.event.release.tag_name }}"
44+ exit 1
45+ fi
46+
47+ echo "version=${{ github.event.release.tag_name }}" >> $GITHUB_OUTPUT
48+
49+ - name : Determine prerelease version
50+ id : pre-version
51+ if : ${{ github.event_name != 'release' }}
52+ run : |
53+ hash="${{ github.event.pull_request.head.sha || github.sha }}"
54+ echo "version=0.0.0-ci-${hash:0:7}" >> $GITHUB_OUTPUT
55+
56+ outputs :
57+ version : ${{ github.event.inputs.force_version || steps.stable-version.outputs.version || steps.pre-version.outputs.version }}
58+
59+ # Check formatting
60+ # format:
61+ # runs-on: ubuntu-latest
62+ # permissions:
63+ # contents: read
64+
65+ # steps:
66+ # - name: Checkout
67+ # uses: actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
68+
69+ # - name: Install .NET
70+ # uses: actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
71+
72+ # - name: Validate format
73+ # run: dotnet format --verify-no-changes
74+
75+ # Run tests
76+ test :
77+ strategy :
78+ fail-fast : false
79+ matrix :
80+ os :
81+ - ubuntu-latest
82+ # Windows runners don't support Linux Docker containers (needed for tests),
83+ # so we currently cannot run tests on Windows.
84+ # - windows-latest
85+
86+ runs-on : ${{ matrix.os }}
87+ permissions :
88+ contents : read
89+
90+ steps :
91+ - name : Checkout
92+ uses : actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
93+
94+ - name : Install .NET
95+ uses : actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
96+
97+ - name : Run restore
98+ run : dotnet restore
99+
100+ - name : Run build
101+ run : >
102+ dotnet build
103+ --no-restore
104+ --configuration Release
105+
106+ - name : Run tests
107+ run : >
108+ dotnet test
109+ --no-restore
110+ --no-build
111+ --configuration Release
112+ ${{ runner.os == 'Windows' && '-p:IncludeNetCoreAppTargets=false' || '' }}
113+ --logger "trx;LogFileName=pw-test-results.trx"
114+ --
115+ RunConfiguration.CollectSourceInformation=true
116+
117+ # Pack the output into NuGet packages
118+ pack :
119+ needs : version
120+ runs-on : ubuntu-latest
121+ permissions :
122+ actions : write
123+ contents : read
124+
125+ steps :
126+ - name : Checkout
127+ uses : actions/checkout@ac593985615ec2ede58e132d2e21d2b1cbd6127c # v3.3.0
128+
129+ - name : Install .NET
130+ uses : actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
131+
132+ - name : Run restore
133+ run : dotnet restore
134+
135+ - name : Run build
136+ run : >
137+ dotnet build
138+ --no-restore
139+ --configuration Release
140+ -p:ContinuousIntegrationBuild=true
141+ -p:Version=${{ needs.version.outputs.version }}
142+
143+ - name : Run pack
144+ run : >
145+ dotnet pack
146+ -p:Version=${{ needs.version.outputs.version }}
147+ -p:ContinuousIntegrationBuild=true
148+ --no-restore
149+ --no-build
150+ --configuration Release
151+
152+ - name : Upload artifacts
153+ uses : actions/upload-artifact@a8a3f3ad30e3422c9c7b888a15615d19a852ae32 # v3.1.3
154+ with :
155+ name : packages
156+ path : " **/*.nupkg"
157+
158+ # Deploy the NuGet packages to the corresponding registries
159+ deploy :
160+ needs :
161+ # Technically, it's not required for the format job to succeed for us to push the package,
162+ # so we may consider removing it as a prerequisite here.
163+ # - format
164+ - test
165+ - pack
166+
167+ runs-on : ubuntu-latest
168+ permissions :
169+ actions : read
170+ packages : write
171+
172+ steps :
173+ - name : Download artifacts
174+ uses : actions/download-artifact@9bc31d5ccc31df68ecc42ccf4149144866c47d8a # v3.0.2
175+ with :
176+ name : packages
177+
178+ - name : Install .NET
179+ uses : actions/setup-dotnet@607fce577a46308457984d59e4954e075820f10a # v3.0.3
180+
181+ # Publish to GitHub package registry every time, whether it's a prerelease
182+ # version or a stable release version.
183+ - name : Publish packages (GitHub Registry)
184+ run : >
185+ dotnet nuget push **/*.nupkg
186+ --source https://nuget.pkg.github.com/passwordless-lib/index.json
187+ --api-key ${{ secrets.GITHUB_TOKEN }}
188+
189+ # Only publish to NuGet on stable releases
190+ # - name: Publish packages (NuGet Registry)
191+ # if: ${{ github.event_name == 'release' }}
192+ # run: >
193+ # dotnet nuget push **/*.nupkg
194+ # --source https://api.nuget.org/v3/index.json
195+ # --api-key ${{ secrets.nuget_api_key }}
0 commit comments