|
| 1 | +name: build-release |
| 2 | + |
| 3 | +on: |
| 4 | + workflow_dispatch: |
| 5 | + inputs: |
| 6 | + # nuget |
| 7 | + nuget-push: |
| 8 | + description: "nuget-push: true = upload nuget package. false = not upload" |
| 9 | + required: false |
| 10 | + type: boolean |
| 11 | + default: true |
| 12 | + |
| 13 | +jobs: |
| 14 | + test-dotnet: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + timeout-minutes: 10 |
| 17 | + steps: |
| 18 | + - uses: actions/checkout@v4 |
| 19 | + - uses: actions/setup-dotnet@v4 |
| 20 | + # test |
| 21 | + - run: dotnet test -c Release |
| 22 | + |
| 23 | + create-release: |
| 24 | + needs: [test-dotnet] |
| 25 | + runs-on: ubuntu-latest |
| 26 | + timeout-minutes: 10 |
| 27 | + outputs: |
| 28 | + new_release_published: ${{ steps.semantic.outputs.new_release_published }} |
| 29 | + new_release_version: ${{ steps.semantic.outputs.new_release_version }} |
| 30 | + steps: |
| 31 | + - name: Checkout |
| 32 | + uses: actions/checkout@v4 |
| 33 | + - name: Semantic Release |
| 34 | + uses: cycjimmy/semantic-release-action@v4 |
| 35 | + id: semantic |
| 36 | + env: |
| 37 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 38 | + |
| 39 | + create-nuget-package: |
| 40 | + needs: [create-release] |
| 41 | + runs-on: ubuntu-latest |
| 42 | + timeout-minutes: 10 |
| 43 | + if: needs.create-release.outputs.new_release_published == 'true' |
| 44 | + steps: |
| 45 | + - uses: actions/checkout@v4 |
| 46 | + - uses: actions/setup-dotnet@v4 |
| 47 | + # build and pack |
| 48 | + - run: dotnet build -c Release -p:Version=${{ needs.create-release.outputs.new_release_version }} |
| 49 | + - run: dotnet pack -c Release --no-build -p:Version=${{ needs.create-release.outputs.new_release_version }} -o ./publish |
| 50 | + # Store artifacts. |
| 51 | + - uses: actions/upload-artifact@v4 |
| 52 | + with: |
| 53 | + name: nuget |
| 54 | + path: ./publish/ |
| 55 | + retention-days: 1 |
| 56 | + |
| 57 | + push-nuget-package: |
| 58 | + needs: [create-nuget-package] |
| 59 | + runs-on: ubuntu-latest |
| 60 | + timeout-minutes: 10 |
| 61 | + if: needs.create-release.outputs.new_release_published == 'true' |
| 62 | + env: |
| 63 | + NUGET_PATH: | |
| 64 | + ./*.nupkg |
| 65 | + ./*.snupkg |
| 66 | + steps: |
| 67 | + - uses: actions/checkout@v4 |
| 68 | + - uses: actions/setup-dotnet@v4 |
| 69 | + |
| 70 | + # Download(All) Artifacts to current directory |
| 71 | + - uses: actions/download-artifact@v4 |
| 72 | + with: |
| 73 | + name: nuget |
| 74 | + - name: Show download aritifacts |
| 75 | + run: ls -lR |
| 76 | + - name: Validate package exists in artifact - NuGet |
| 77 | + run: | |
| 78 | + while read -r nuget_path; do |
| 79 | + if [[ "${nuget_path}" == "" ]]; then continue; fi |
| 80 | + # shellcheck disable=SC2086 |
| 81 | + if ! ls -l ${nuget_path}; then |
| 82 | + echo "Specified nuget package not found. path: $nuget_path" |
| 83 | + if [[ "${nuget_path}" == *.nupkg ]]; then |
| 84 | + echo ".nupkg must be included in the artifact." |
| 85 | + exit 1 |
| 86 | + fi |
| 87 | + fi |
| 88 | + done <<< "${NUGET_PATH}" |
| 89 | +
|
| 90 | + # Upload to NuGet |
| 91 | + - name: Upload to NuGet |
| 92 | + if: ${{ inputs.nuget-push }} |
| 93 | + run: | |
| 94 | + while read -r nuget_path; do |
| 95 | + if [[ "$nuget_path" == "" ]]; then continue; fi |
| 96 | + # shellcheck disable=SC2086 |
| 97 | + if ! ls -l ${nuget_path} >/dev/null 2>&1;then |
| 98 | + echo "skipping nuget push, $nuget_path not found." |
| 99 | + continue |
| 100 | + fi |
| 101 | +
|
| 102 | + dotnet nuget push "${nuget_path}" --skip-duplicate -s https://api.nuget.org/v3/index.json -k "${NUGET_KEY}" |
| 103 | + done <<< "${NUGET_PATH}" |
| 104 | + env: |
| 105 | + NUGET_KEY: ${{ secrets.PS_NUGET_KEY }} |
0 commit comments