|
| 1 | +name: Build |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - main |
| 7 | + - develop |
| 8 | + tags: |
| 9 | + - '*.*.*' |
| 10 | + pull_request: |
| 11 | + branches: |
| 12 | + - main |
| 13 | + - develop |
| 14 | + workflow_dispatch: |
| 15 | + |
| 16 | +permissions: |
| 17 | + checks: write |
| 18 | + statuses: write |
| 19 | + contents: write |
| 20 | + |
| 21 | +jobs: |
| 22 | + build: |
| 23 | + |
| 24 | + env: |
| 25 | + BUILD_CONFIG: 'Release' |
| 26 | + SOLUTION: '*.sln' |
| 27 | + |
| 28 | + runs-on: ubuntu-latest |
| 29 | + |
| 30 | + steps: |
| 31 | + - uses: actions/checkout@v4 |
| 32 | + |
| 33 | + - name: Setup .NET |
| 34 | + uses: actions/setup-dotnet@v4 |
| 35 | + with: |
| 36 | + dotnet-version: '9.0.x' |
| 37 | + |
| 38 | + - name: Get tag for current commit |
| 39 | + id: get_tag |
| 40 | + # Check for tags when triggered by main branch push (with tag) or direct tag push |
| 41 | + # Can't use github.ref_name because it's "main" when pushing branch+tag together |
| 42 | + if: github.ref == 'refs/heads/main' || startsWith(github.ref, 'refs/tags/') |
| 43 | + uses: olegtarasov/[email protected] |
| 44 | + |
| 45 | + - name: Set Version Profile |
| 46 | + run: | |
| 47 | + if [[ "${{ steps.get_tag.outputs.tag }}" != "" ]]; then |
| 48 | + echo "VERSION_PROFILE=release" >> $GITHUB_ENV |
| 49 | + else |
| 50 | + echo "VERSION_PROFILE=ci" >> $GITHUB_ENV |
| 51 | + fi |
| 52 | + |
| 53 | + - name: Restore dependencies |
| 54 | + run: dotnet restore $SOLUTION |
| 55 | + |
| 56 | + - name: Build |
| 57 | + run: dotnet build $SOLUTION --configuration $BUILD_CONFIG --no-restore -p:GeneratePackageOnBuild=false -p:VersionProfile=${{ env.VERSION_PROFILE }} |
| 58 | + |
| 59 | + - name: Run tests |
| 60 | + run: dotnet test --configuration $BUILD_CONFIG --no-restore --no-build --verbosity normal -p:VersionProfile=${{ env.VERSION_PROFILE }} |
| 61 | + |
| 62 | + - name: Pack NuGet packages |
| 63 | + run: | |
| 64 | + dotnet pack $SOLUTION --configuration $BUILD_CONFIG --no-build --output ./artifacts -p:VersionProfile=${{ env.VERSION_PROFILE }} |
| 65 | + echo "=== Packages created ===" |
| 66 | + ls -la ./artifacts/ |
| 67 | +
|
| 68 | + - name: Extract release notes from CHANGELOG.md |
| 69 | + if: steps.get_tag.outputs.tag != '' |
| 70 | + id: extract_notes |
| 71 | + uses: mindsers/changelog-reader-action@v2 |
| 72 | + with: |
| 73 | + version: ${{ steps.get_tag.outputs.tag }} |
| 74 | + path: ./CHANGELOG.md |
| 75 | + |
| 76 | + - name: Create GitHub Release |
| 77 | + if: steps.get_tag.outputs.tag != '' |
| 78 | + uses: softprops/action-gh-release@v1 |
| 79 | + with: |
| 80 | + tag_name: ${{ steps.get_tag.outputs.tag }} |
| 81 | + body: ${{ steps.extract_notes.outputs.changes }} |
| 82 | + env: |
| 83 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
0 commit comments