|
| 1 | +name: Build, Test, Publish NuGet |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + # tags: |
| 8 | + # - "v*" |
| 9 | + |
| 10 | +jobs: |
| 11 | + build-test-publish: |
| 12 | + runs-on: ubuntu-latest |
| 13 | + |
| 14 | + steps: |
| 15 | + - name: Checkout code |
| 16 | + uses: actions/checkout@v3 |
| 17 | + |
| 18 | + - name: Setup .NET |
| 19 | + uses: actions/setup-dotnet@v3 |
| 20 | + with: |
| 21 | + dotnet-version: '8.0.x' |
| 22 | + |
| 23 | + - name: Detect version tag |
| 24 | + id: detect-version |
| 25 | + run: | |
| 26 | + if [[ "${GITHUB_REF}" == refs/tags/v* ]]; then |
| 27 | + echo "IS_TAG=true" >> $GITHUB_ENV |
| 28 | + echo "VERSION=${GITHUB_REF#refs/tags/v}" >> $GITHUB_ENV |
| 29 | + else |
| 30 | + echo "IS_TAG=false" >> $GITHUB_ENV |
| 31 | + fi |
| 32 | +
|
| 33 | + - name: Check for release notes |
| 34 | + id: check-release-notes |
| 35 | + run: | |
| 36 | + if [ -f release-notes.txt ]; then |
| 37 | + echo "RELEASE_NOTES_EXISTS=true" >> $GITHUB_ENV |
| 38 | + RELEASE_NOTES=$(sed ':a;N;$!ba;s/\n/\\n/g' release-notes.txt) |
| 39 | + echo "RELEASE_NOTES=$RELEASE_NOTES" >> $GITHUB_ENV |
| 40 | + else |
| 41 | + echo "RELEASE_NOTES_EXISTS=false" >> $GITHUB_ENV |
| 42 | + fi |
| 43 | +
|
| 44 | + - name: Update version and release notes in .csproj (only on tag) |
| 45 | + if: env.IS_TAG == 'true' |
| 46 | + run: | |
| 47 | + sed -i "s|<Version>.*</Version>|<Version>${VERSION}</Version>|" CQRSMediatr/CQRSMediatr.csproj |
| 48 | +
|
| 49 | + if [ "$RELEASE_NOTES_EXISTS" = "true" ]; then |
| 50 | + RELEASE_NOTES_ESCAPED=$(printf '%s\n' "$RELEASE_NOTES" | sed 's/[&/\]/\\&/g') |
| 51 | + sed -i "s|<PackageReleaseNotes>.*</PackageReleaseNotes>|<PackageReleaseNotes>${RELEASE_NOTES_ESCAPED}</PackageReleaseNotes>|" CQRSMediatr/CQRSMediatr.csproj |
| 52 | + fi |
| 53 | +
|
| 54 | + - name: Restore dependencies |
| 55 | + run: dotnet restore |
| 56 | + |
| 57 | + - name: Build library |
| 58 | + run: dotnet build DynamicCode/DynamicCode.csproj --configuration Release --no-restore |
| 59 | + |
| 60 | + - name: Build test project |
| 61 | + run: dotnet build DynamicCode.Test/DynamicCode.Test.csproj --configuration Release |
| 62 | + |
| 63 | + - name: Run tests |
| 64 | + run: dotnet test DynamicCode.Test/DynamicCode.Test.csproj --configuration Release --no-build --verbosity normal |
| 65 | + |
| 66 | + # - name: Pack NuGet package (only on tag) |
| 67 | + # if: env.IS_TAG == 'true' |
| 68 | + # run: | |
| 69 | + # if [ "$RELEASE_NOTES_EXISTS" = "true" ]; then |
| 70 | + # dotnet pack CQRSMediatr/CQRSMediatr.csproj --configuration Release --no-build \ |
| 71 | + # -p:PackageVersion=$VERSION \ |
| 72 | + # -p:PackageReleaseNotes="$RELEASE_NOTES" |
| 73 | + # else |
| 74 | + # dotnet pack CQRSMediatr/CQRSMediatr.csproj --configuration Release --no-build \ |
| 75 | + # -p:PackageVersion=$VERSION |
| 76 | + # fi |
| 77 | + |
| 78 | + # - name: Publish to NuGet (only on tag) |
| 79 | + # if: env.IS_TAG == 'true' |
| 80 | + # env: |
| 81 | + # NUGET_API_KEY: ${{ secrets.NUGET_API_KEY }} |
| 82 | + # run: | |
| 83 | + # dotnet nuget push CQRSMediatr/bin/Release/*.nupkg \ |
| 84 | + # --api-key $NUGET_API_KEY \ |
| 85 | + # --source https://api.nuget.org/v3/index.json |
0 commit comments