Repository navigation
84 lines (71 loc) · 3.01 KB
/
Copy pathpublish.yml
File metadata and controls
84 lines (71 loc) · 3.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
# Publishes FSharp.SystemCommandLine to nuget.org using Trusted Publishing (OIDC).
# No stored API key: NuGet/login exchanges a GitHub-issued OIDC token for a
# short-lived (1 hour) API key, validated against the trusted publishing policy
# configured on nuget.org for this repository + workflow file.
#
# To release: push a version tag, e.g.
# git tag v2.3.0 && git push origin v2.3.0
# The tag (minus the leading "v") is the published version; a suffix such as
# v2.4.0-alpha.1 publishes a prerelease. The <Version> in the fsproj is only
# used for local builds.
#
# Fallback: Actions -> "Publish to NuGet" -> Run workflow, entering an existing tag
# (useful for re-running a failed release; already-published versions are skipped).
name: Publish to NuGet
on:
push:
tags: [ "v*" ]
workflow_dispatch:
inputs:
tag:
description: "Existing tag to publish (e.g. v2.3.0)"
required: true
jobs:
publish:
runs-on: windows-2022
permissions:
id-token: write # required for GitHub OIDC token issuance (Trusted Publishing)
contents: write # required to create the GitHub Release
env:
TAG: ${{ github.event_name == 'push' && github.ref_name || inputs.tag }}
steps:
- uses: actions/checkout@v7
with:
ref: ${{ env.TAG }}
- name: Get version from tag
run: |
$version = "$env:TAG" -replace '^v', ''
if ($version -notmatch '^\d+\.\d+\.\d+(-[0-9A-Za-z.-]+)?$') {
throw "Tag '$env:TAG' is not a version tag like v2.3.0 or v2.4.0-alpha.1"
}
"VERSION=$version" >> $env:GITHUB_ENV
Write-Host "Publishing version $version"
- name: Setup .NET
uses: actions/setup-dotnet@v6
with:
dotnet-version: 6.0.x
- name: Test
run: dotnet test src/Tests/Tests.fsproj --configuration Release
- name: Pack
run: dotnet pack src/FSharp.SystemCommandLine/FSharp.SystemCommandLine.fsproj --configuration Release --output artifacts -p:Version=${{ env.VERSION }}
- name: NuGet login (OIDC -> temp API key)
uses: NuGet/login@v1
id: login
with:
user: "jordan marr" # nuget.org profile name (not email)
- name: Push
# Backslash separator is required: on Windows, dotnet nuget push only expands wildcards in paths using '\'
run: dotnet nuget push artifacts\*.nupkg --api-key ${{ steps.login.outputs.NUGET_API_KEY }} --source https://api.nuget.org/v3/index.json --skip-duplicate
- name: Create GitHub Release
env:
GH_TOKEN: ${{ github.token }}
run: |
gh release view "$env:TAG" *> $null
if ($LASTEXITCODE -eq 0) {
Write-Host "Release $env:TAG already exists; skipping."
$global:LASTEXITCODE = 0
} else {
$releaseArgs = @('release', 'create', $env:TAG, '--verify-tag', '--generate-notes', '--title', $env:TAG)
if ($env:VERSION -like '*-*') { $releaseArgs += '--prerelease' }
gh @releaseArgs
}