mirror of
https://github.com/Empostor/Empostor.git
synced 2026-10-20 01:46:07 +00:00
71 lines
2.6 KiB
YAML
71 lines
2.6 KiB
YAML
name: nuget
|
|
|
|
on:
|
|
push:
|
|
branches: [main]
|
|
paths:
|
|
- "src/Empostor.Api/**"
|
|
workflow_dispatch:
|
|
|
|
jobs:
|
|
publish:
|
|
runs-on: ubuntu-latest
|
|
permissions:
|
|
id-token: write
|
|
contents: read
|
|
|
|
steps:
|
|
- name: Checkout
|
|
uses: actions/checkout@v4
|
|
|
|
- name: Setup .NET 8
|
|
uses: actions/setup-dotnet@v4
|
|
with:
|
|
dotnet-version: 8.0.x
|
|
|
|
# Package version = <VersionPrefix>-ci.<CI run_number + 500>, mirroring
|
|
# the nightly build numbering. The floor (max already-published ci.N + 1)
|
|
# keeps versions monotonic; push is skipped by --skip-duplicate if the
|
|
# exact version already exists.
|
|
- name: Resolve version
|
|
id: ver
|
|
run: |
|
|
set -euo pipefail
|
|
PROJ=src/Empostor.Api/Empostor.Api.csproj
|
|
BASE=$(sed -n 's/.*<VersionPrefix>\([^<]*\)<\/VersionPrefix>.*/\1/p' "$PROJ" | head -1)
|
|
CI_RUN=$(curl -sf -H "Authorization: Bearer ${{ secrets.GITHUB_TOKEN }}" \
|
|
"https://api.github.com/repos/${{ github.repository }}/actions/workflows/ci.yml/runs?per_page=1" \
|
|
| jq -r '.workflow_runs[0].run_number')
|
|
N=$(( CI_RUN + 500 ))
|
|
MAXN=$(curl -sf "https://api.nuget.org/v3-flatcontainer/empostor.api/index.json" \
|
|
| jq -r '.versions[]' | grep -oE 'ci\.[0-9]+$' | grep -oE '[0-9]+$' | sort -n | tail -1 || true)
|
|
MAXN=${MAXN:-0}
|
|
if [ "$N" -le "$MAXN" ]; then N=$((MAXN + 1)); fi
|
|
echo "suffix=ci.${N}" >> "$GITHUB_OUTPUT"
|
|
echo "version=${BASE}-ci.${N}" >> "$GITHUB_OUTPUT"
|
|
echo "Publishing version: ${BASE}-ci.${N}"
|
|
|
|
- name: Pack
|
|
run: dotnet pack src/Empostor.Api/Empostor.Api.csproj -c Release -p:VersionSuffix=${{ steps.ver.outputs.suffix }} -p:GeneratePackageOnBuild=false -o artifacts --nologo
|
|
|
|
# Trusted publishing: exchanges the GitHub OIDC token for a short-lived
|
|
# nuget.org API key tied to the policy (no secret needed).
|
|
- name: NuGet login (trusted publishing)
|
|
uses: NuGet/login@v1
|
|
id: login
|
|
with:
|
|
user: ELinmei
|
|
|
|
- name: Push to nuget.org
|
|
run: |
|
|
set -euo pipefail
|
|
ls -la artifacts
|
|
dotnet nuget push "artifacts/Empostor.Api.*.nupkg" \
|
|
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
|
|
--source https://api.nuget.org/v3/index.json \
|
|
--skip-duplicate
|
|
dotnet nuget push "artifacts/Empostor.Api.*.snupkg" \
|
|
--api-key "${{ steps.login.outputs.NUGET_API_KEY }}" \
|
|
--source https://api.nuget.org/v3/index.json \
|
|
--skip-duplicate || true
|