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