|
| 1 | +# Written by DocSpring/docspring's api_clients/scripts/generate from api_clients/github_workflows/csharp/release.yml: |
| 2 | +# change it there. |
| 3 | +# |
| 4 | +# Packs the package on every push and pull request. A v* tag (pushed by the monorepo's api_clients/scripts/release) |
| 5 | +# also pushes it to NuGet with trusted publishing, in the release environment, and waits until NuGet serves it. |
| 6 | +name: Release |
| 7 | + |
| 8 | +on: |
| 9 | + push: |
| 10 | + branches: ['**'] |
| 11 | + tags: ['v*'] |
| 12 | + pull_request: |
| 13 | + |
| 14 | +permissions: |
| 15 | + contents: read |
| 16 | + |
| 17 | +jobs: |
| 18 | + build: |
| 19 | + runs-on: ubuntu-latest |
| 20 | + steps: |
| 21 | + - uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1 |
| 22 | + with: |
| 23 | + persist-credentials: false |
| 24 | + - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 |
| 25 | + with: |
| 26 | + dotnet-version: 9.0.x |
| 27 | + - name: Check the tag matches the package version |
| 28 | + if: github.ref_type == 'tag' |
| 29 | + run: | |
| 30 | + VERSION="$(sed -n 's:.*<Version>\(.*\)</Version>.*:\1:p' src/DocSpring.Client/DocSpring.Client.csproj)" |
| 31 | + if [ "v$VERSION" != "$GITHUB_REF_NAME" ]; then |
| 32 | + echo "::error::The tag is $GITHUB_REF_NAME, but the package version is $VERSION" |
| 33 | + exit 1 |
| 34 | + fi |
| 35 | + - run: dotnet pack src/DocSpring.Client/DocSpring.Client.csproj --configuration Release --output out |
| 36 | + - if: github.ref_type == 'tag' |
| 37 | + uses: actions/upload-artifact@cf430e030ddbb5b0abf93d22962f4752f3646cd9 # v7.0.2 |
| 38 | + with: |
| 39 | + name: package |
| 40 | + path: out/ |
| 41 | + if-no-files-found: error |
| 42 | + |
| 43 | + publish: |
| 44 | + needs: build |
| 45 | + if: github.ref_type == 'tag' |
| 46 | + runs-on: ubuntu-latest |
| 47 | + environment: release |
| 48 | + permissions: |
| 49 | + contents: read |
| 50 | + id-token: write |
| 51 | + steps: |
| 52 | + - uses: actions/setup-dotnet@a98b56852c35b8e3190ac28c8c2271da59106c68 # v6.0.0 |
| 53 | + with: |
| 54 | + dotnet-version: 9.0.x |
| 55 | + - uses: actions/download-artifact@9000827ccba6bdab643e8b6fd33ac0654aef8333 # v8.0.2 |
| 56 | + with: |
| 57 | + name: package |
| 58 | + path: out/ |
| 59 | + # The nuget.org account that owns DocSpring.Client and its trusted publishing policy |
| 60 | + - uses: NuGet/login@8d196754b4036150537f80ac539e15c2f1028841 # v1.2.0 |
| 61 | + id: login |
| 62 | + with: |
| 63 | + user: nathan-formapi |
| 64 | + - name: Push to NuGet |
| 65 | + env: |
| 66 | + NUGET_API_KEY: ${{ steps.login.outputs.NUGET_API_KEY }} |
| 67 | + run: | |
| 68 | + dotnet nuget push "out/DocSpring.Client.${GITHUB_REF_NAME#v}.nupkg" \ |
| 69 | + --api-key "$NUGET_API_KEY" --source https://api.nuget.org/v3/index.json |
| 70 | +
|
| 71 | + verify: |
| 72 | + needs: publish |
| 73 | + runs-on: ubuntu-latest |
| 74 | + timeout-minutes: 30 |
| 75 | + steps: |
| 76 | + # NuGet validates and indexes a package before it serves it, which can take a while |
| 77 | + - name: Wait until NuGet serves the version |
| 78 | + run: | |
| 79 | + VERSION="${GITHUB_REF_NAME#v}" |
| 80 | + for _ in $(seq 150); do |
| 81 | + if curl -fsS -o /dev/null "https://api.nuget.org/v3-flatcontainer/docspring.client/$VERSION/docspring.client.nuspec"; then |
| 82 | + echo "NuGet serves DocSpring.Client $VERSION" |
| 83 | + exit 0 |
| 84 | + fi |
| 85 | + sleep 10 |
| 86 | + done |
| 87 | + echo "::error::NuGet doesn't serve DocSpring.Client $VERSION after 25 minutes" |
| 88 | + exit 1 |
0 commit comments