|
| 1 | +# Publishes the ARCP.FSharp and ARCP.FSharp.Cli NuGet packages to nuget.org. |
| 2 | +# |
| 3 | +# Triggers: |
| 4 | +# - push of a tag matching `v*` (version is derived from the tag, minus the `v`) |
| 5 | +# - workflow_dispatch (version supplied as input) |
| 6 | +# |
| 7 | +# Required repository secret: |
| 8 | +# - NUGET_API_KEY — an API key from https://www.nuget.org/account/apikeys |
| 9 | +# |
| 10 | +# Action pinning policy: |
| 11 | +# - First-party `actions/*` actions are pinned to a major version tag (e.g. @v4). |
| 12 | +# - Any third-party action must be pinned to a full commit SHA with a |
| 13 | +# version comment. (None are currently used.) |
| 14 | +name: publish |
| 15 | + |
| 16 | +on: |
| 17 | + push: |
| 18 | + tags: ["v*"] |
| 19 | + workflow_dispatch: |
| 20 | + inputs: |
| 21 | + version: |
| 22 | + description: "Package version (e.g. 0.1.0). Required for manual runs." |
| 23 | + required: true |
| 24 | + type: string |
| 25 | + |
| 26 | +concurrency: |
| 27 | + group: publish-${{ github.ref }} |
| 28 | + cancel-in-progress: false |
| 29 | + |
| 30 | +permissions: |
| 31 | + contents: read |
| 32 | + |
| 33 | +jobs: |
| 34 | + publish: |
| 35 | + runs-on: ubuntu-latest |
| 36 | + env: |
| 37 | + DOTNET_NOLOGO: "true" |
| 38 | + DOTNET_CLI_TELEMETRY_OPTOUT: "true" |
| 39 | + DOTNET_SKIP_FIRST_TIME_EXPERIENCE: "true" |
| 40 | + NUGET_XMLDOC_MODE: skip |
| 41 | + |
| 42 | + steps: |
| 43 | + - name: Checkout |
| 44 | + uses: actions/checkout@v4 |
| 45 | + with: |
| 46 | + # Sourcelink embeds the commit; full history isn't required but |
| 47 | + # fetch-depth: 0 makes git describe usable if we want it later. |
| 48 | + fetch-depth: 0 |
| 49 | + |
| 50 | + - name: Setup .NET (from global.json) |
| 51 | + uses: actions/setup-dotnet@v4 |
| 52 | + with: |
| 53 | + global-json-file: global.json |
| 54 | + |
| 55 | + - name: Resolve version |
| 56 | + id: version |
| 57 | + run: | |
| 58 | + if [ "${{ github.event_name }}" = "workflow_dispatch" ]; then |
| 59 | + VERSION="${{ inputs.version }}" |
| 60 | + else |
| 61 | + VERSION="${GITHUB_REF_NAME#v}" |
| 62 | + fi |
| 63 | + if ! printf '%s' "$VERSION" | grep -Eq '^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z.-]+)?$'; then |
| 64 | + echo "Invalid version: '$VERSION'" >&2 |
| 65 | + exit 1 |
| 66 | + fi |
| 67 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 68 | + echo "Publishing version: $VERSION" |
| 69 | +
|
| 70 | + - name: Cache NuGet packages |
| 71 | + uses: actions/cache@v4 |
| 72 | + with: |
| 73 | + path: ~/.nuget/packages |
| 74 | + key: ${{ runner.os }}-nuget-${{ hashFiles('**/*.fsproj', '**/Directory.Packages.props', '**/global.json', '**/nuget.config') }} |
| 75 | + restore-keys: | |
| 76 | + ${{ runner.os }}-nuget- |
| 77 | +
|
| 78 | + - name: Restore |
| 79 | + run: | |
| 80 | + dotnet restore src/ARCP/ARCP.fsproj |
| 81 | + dotnet restore src/ARCP.Cli/ARCP.Cli.fsproj |
| 82 | +
|
| 83 | + - name: Build |
| 84 | + run: | |
| 85 | + dotnet build src/ARCP/ARCP.fsproj \ |
| 86 | + --configuration Release --no-restore \ |
| 87 | + -p:Version=${{ steps.version.outputs.version }} |
| 88 | + dotnet build src/ARCP.Cli/ARCP.Cli.fsproj \ |
| 89 | + --configuration Release --no-restore \ |
| 90 | + -p:Version=${{ steps.version.outputs.version }} |
| 91 | +
|
| 92 | + - name: Pack |
| 93 | + run: | |
| 94 | + dotnet pack src/ARCP/ARCP.fsproj \ |
| 95 | + --configuration Release --no-build \ |
| 96 | + --output "${{ github.workspace }}/artifacts" \ |
| 97 | + -p:Version=${{ steps.version.outputs.version }} \ |
| 98 | + -p:ContinuousIntegrationBuild=true |
| 99 | + dotnet pack src/ARCP.Cli/ARCP.Cli.fsproj \ |
| 100 | + --configuration Release --no-build \ |
| 101 | + --output "${{ github.workspace }}/artifacts" \ |
| 102 | + -p:Version=${{ steps.version.outputs.version }} \ |
| 103 | + -p:ContinuousIntegrationBuild=true |
| 104 | +
|
| 105 | + - name: Upload packages |
| 106 | + uses: actions/upload-artifact@v4 |
| 107 | + with: |
| 108 | + name: nuget-packages-${{ steps.version.outputs.version }} |
| 109 | + path: ${{ github.workspace }}/artifacts/*.*nupkg |
| 110 | + if-no-files-found: error |
| 111 | + retention-days: 30 |
| 112 | + |
| 113 | + - name: Push to nuget.org |
| 114 | + env: |
| 115 | + NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 116 | + run: > |
| 117 | + dotnet nuget push "${{ github.workspace }}/artifacts/*.nupkg" |
| 118 | + --source https://api.nuget.org/v3/index.json |
| 119 | + --api-key "$NUGET_API_KEY" |
| 120 | + --skip-duplicate |
0 commit comments