|
1 | | -# This workflow will build a .NET project |
2 | | -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-net |
| 1 | +# This workflow builds, tests, and releases the Resgrid solution. |
| 2 | +# - PRs on any branch: build + test |
| 3 | +# - Merged PRs into master: build + test + Docker Hub publish + GitHub Release |
3 | 4 |
|
4 | 5 | name: .NET |
5 | 6 |
|
6 | 7 | on: |
7 | 8 | pull_request: |
8 | | - branches: [ "master", "develop" ] |
| 9 | + types: [opened, synchronize, reopened] |
| 10 | + push: |
| 11 | + branches: [ "master" ] |
9 | 12 |
|
10 | | -jobs: |
11 | | - build: |
| 13 | +permissions: |
| 14 | + contents: read |
| 15 | + |
| 16 | +env: |
| 17 | + DOTNET_VERSION: '9.0.x' |
12 | 18 |
|
| 19 | +jobs: |
| 20 | + # ─────────────────────────────────────────────── |
| 21 | + # Build & Test – runs on every PR and push to master |
| 22 | + # ─────────────────────────────────────────────── |
| 23 | + build-and-test: |
13 | 24 | runs-on: ubuntu-latest |
14 | 25 |
|
15 | 26 | steps: |
16 | 27 | - uses: actions/checkout@v4 |
| 28 | + |
17 | 29 | - name: Setup .NET |
18 | 30 | uses: actions/setup-dotnet@v4 |
19 | 31 | with: |
20 | | - dotnet-version: 9.0.x |
| 32 | + dotnet-version: ${{ env.DOTNET_VERSION }} |
| 33 | + |
21 | 34 | - name: Restore dependencies |
22 | 35 | run: dotnet restore |
| 36 | + |
23 | 37 | - name: Build |
24 | | - run: dotnet build --no-restore |
| 38 | + run: dotnet build --no-restore --configuration Release |
| 39 | + |
25 | 40 | - name: Test |
26 | | - run: dotnet test --no-build --verbosity normal |
| 41 | + run: dotnet test --no-build --configuration Release --verbosity normal |
| 42 | + |
| 43 | + # ─────────────────────────────────────────────── |
| 44 | + # Docker Build & Push – only on merged PRs to master |
| 45 | + # Uses a matrix to build each project's Dockerfile |
| 46 | + # ─────────────────────────────────────────────── |
| 47 | + docker-build-and-push: |
| 48 | + needs: build-and-test |
| 49 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 50 | + runs-on: ubuntu-latest |
| 51 | + |
| 52 | + strategy: |
| 53 | + fail-fast: false |
| 54 | + matrix: |
| 55 | + include: |
| 56 | + - image: resgridllc/resgridwebcore |
| 57 | + dockerfile: Web/Resgrid.Web/Dockerfile |
| 58 | + - image: resgridllc/resgridwebservices |
| 59 | + dockerfile: Web/Resgrid.Web.Services/Dockerfile |
| 60 | + - image: resgridllc/resgridwebevents |
| 61 | + dockerfile: Web/Resgrid.Web.Eventing/Dockerfile |
| 62 | + - image: resgridllc/resgridwebmcp |
| 63 | + dockerfile: Web/Resgrid.Web.Mcp/Dockerfile |
| 64 | + - image: resgridllc/resgridworkersconsole |
| 65 | + dockerfile: Workers/Resgrid.Workers.Console/Dockerfile |
| 66 | + |
| 67 | + steps: |
| 68 | + - uses: actions/checkout@v4 |
| 69 | + |
| 70 | + - name: Set up Docker Buildx |
| 71 | + uses: docker/setup-buildx-action@v3 |
| 72 | + |
| 73 | + - name: Login to Docker Hub |
| 74 | + uses: docker/login-action@v3 |
| 75 | + with: |
| 76 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 77 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 78 | + |
| 79 | + - name: Extract version |
| 80 | + id: version |
| 81 | + run: | |
| 82 | + VERSION="4.${{ github.run_number }}.0" |
| 83 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 84 | +
|
| 85 | + - name: Docker meta |
| 86 | + id: meta |
| 87 | + uses: docker/metadata-action@v5 |
| 88 | + with: |
| 89 | + images: ${{ matrix.image }} |
| 90 | + tags: | |
| 91 | + type=raw,value=${{ steps.version.outputs.version }} |
| 92 | + type=raw,value=latest |
| 93 | + type=sha,prefix= |
| 94 | +
|
| 95 | + - name: Build and push Docker image |
| 96 | + uses: docker/build-push-action@v6 |
| 97 | + with: |
| 98 | + context: . |
| 99 | + file: ${{ matrix.dockerfile }} |
| 100 | + push: true |
| 101 | + build-args: BUILD_VERSION=${{ steps.version.outputs.version }} |
| 102 | + tags: ${{ steps.meta.outputs.tags }} |
| 103 | + labels: ${{ steps.meta.outputs.labels }} |
| 104 | + cache-from: type=gha |
| 105 | + cache-to: type=gha,mode=max |
| 106 | + |
| 107 | + # ─────────────────────────────────────────────── |
| 108 | + # GitHub Release – created after all Docker images are pushed |
| 109 | + # Uses the body of the merged PR as release notes |
| 110 | + # ─────────────────────────────────────────────── |
| 111 | + github-release: |
| 112 | + needs: docker-build-and-push |
| 113 | + if: github.event_name == 'push' && github.ref == 'refs/heads/master' |
| 114 | + runs-on: ubuntu-latest |
| 115 | + |
| 116 | + permissions: |
| 117 | + contents: write |
| 118 | + |
| 119 | + steps: |
| 120 | + - uses: actions/checkout@v4 |
| 121 | + |
| 122 | + - name: Extract version |
| 123 | + id: version |
| 124 | + run: | |
| 125 | + VERSION="4.${{ github.run_number }}.0" |
| 126 | + echo "version=$VERSION" >> "$GITHUB_OUTPUT" |
| 127 | +
|
| 128 | + - name: Get merged PR info |
| 129 | + id: pr-info |
| 130 | + uses: actions/github-script@v7 |
| 131 | + with: |
| 132 | + script: | |
| 133 | + const prs = await github.rest.repos.listPullRequestsAssociatedWithCommit({ |
| 134 | + owner: context.repo.owner, |
| 135 | + repo: context.repo.repo, |
| 136 | + commit_sha: context.sha, |
| 137 | + }); |
| 138 | + const pr = prs.data.find(p => p.merged_at); |
| 139 | + const fs = require('fs'); |
| 140 | + if (pr) { |
| 141 | + fs.writeFileSync('release_notes.md', pr.body || 'No release notes provided.'); |
| 142 | + } else { |
| 143 | + fs.writeFileSync('release_notes.md', 'No release notes provided.'); |
| 144 | + } |
| 145 | +
|
| 146 | + - name: Create GitHub Release |
| 147 | + uses: softprops/action-gh-release@v2 |
| 148 | + with: |
| 149 | + tag_name: v${{ steps.version.outputs.version }} |
| 150 | + name: Release v${{ steps.version.outputs.version }} |
| 151 | + body_path: release_notes.md |
| 152 | + draft: false |
| 153 | + prerelease: false |
| 154 | + make_latest: true |
| 155 | + fail_on_unmatched_files: false |
0 commit comments