|
| 1 | +name: Pipeline |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + branches: |
| 6 | + - "**" # Matches all branches |
| 7 | + pull_request: |
| 8 | + branches: |
| 9 | + - "**" # Matches all branches |
| 10 | + |
| 11 | + workflow_dispatch: |
| 12 | + inputs: |
| 13 | + force_build: |
| 14 | + description: "Forces a build even if no changes are detected" |
| 15 | + required: true |
| 16 | + default: "false" |
| 17 | + force_release: |
| 18 | + description: "Forces a release even if no changes are detected" |
| 19 | + required: true |
| 20 | + default: "false" |
| 21 | + |
| 22 | +concurrency: |
| 23 | + group: pipeline-${{ github.ref_name }} |
| 24 | + cancel-in-progress: true |
| 25 | + |
| 26 | +env: |
| 27 | + container_image: "github-actions-runner" |
| 28 | + container_image_build_context: "." |
| 29 | + container_image_build_platforms: "linux/amd64,linux/arm64" |
| 30 | + container_image_build_dockerfile: "src/Dockerfile" |
| 31 | + container_image_repository_dockerhub: "emberstack" |
| 32 | + container_image_repository_ghcr: "ghcr.io/emberstack" |
| 33 | + |
| 34 | +jobs: |
| 35 | + discovery: |
| 36 | + runs-on: ubuntu-latest |
| 37 | + permissions: |
| 38 | + contents: read |
| 39 | + pull-requests: read |
| 40 | + outputs: |
| 41 | + pathsFilter_src: ${{ steps.pathsFilter.outputs.src }} |
| 42 | + gitVersion_SemVer: ${{ steps.gitversion.outputs.GitVersion_SemVer }} |
| 43 | + gitVersion_AssemblySemFileVer: ${{ steps.gitversion.outputs.GitVersion_AssemblySemFileVer }} |
| 44 | + build: ${{ steps.evaluate_build.outputs.result }} |
| 45 | + build_push: ${{ steps.evaluate_build_push.outputs.result }} |
| 46 | + build_configuration: ${{ steps.evaluate_build_configuration.outputs.result }} |
| 47 | + release: ${{ steps.evaluate_release.outputs.result }} |
| 48 | + steps: |
| 49 | + - name: checkout |
| 50 | + uses: actions/checkout@v4 |
| 51 | + with: |
| 52 | + fetch-depth: 0 |
| 53 | + |
| 54 | + - name: tools - dotnet - install |
| 55 | + uses: actions/setup-dotnet@v4 |
| 56 | + with: |
| 57 | + dotnet-version: "9.x" |
| 58 | + |
| 59 | + - name: tools - gitversion - install |
| 60 | + uses: gittools/actions/gitversion/[email protected] |
| 61 | + with: |
| 62 | + versionSpec: "6.x" |
| 63 | + preferLatestVersion: true |
| 64 | + |
| 65 | + - name: gitversion - execute |
| 66 | + id: gitversion |
| 67 | + uses: gittools/actions/gitversion/[email protected] |
| 68 | + with: |
| 69 | + configFilePath: GitVersion.yaml |
| 70 | + |
| 71 | + - name: tools - detect changes |
| 72 | + id: pathsFilter |
| 73 | + uses: dorny/paths-filter@v3 |
| 74 | + with: |
| 75 | + base: ${{ github.ref }} |
| 76 | + filters: | |
| 77 | + src: |
| 78 | + - '*.sln' |
| 79 | + - '*.slnx' |
| 80 | + - '*.props' |
| 81 | + - 'src/**' |
| 82 | + build: |
| 83 | + - '*.sln' |
| 84 | + - '*.slnx' |
| 85 | + - '*.props' |
| 86 | + - 'src/**' |
| 87 | + - 'tests/**' |
| 88 | + - 'playground/**' |
| 89 | +
|
| 90 | + - name: evaluate - build |
| 91 | + id: evaluate_build |
| 92 | + env: |
| 93 | + RESULT: ${{ steps.pathsFilter.outputs.build == 'true' || github.event.inputs.force_build == 'true' || github.event.inputs.force_release == 'true' }} |
| 94 | + run: echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 95 | + |
| 96 | + - name: evaluate - build_push |
| 97 | + id: evaluate_build_push |
| 98 | + env: |
| 99 | + RESULT: ${{ github.actor != 'dependabot[bot]' && github.event_name != 'pull_request' && (steps.pathsFilter.outputs.src == 'true' || github.event.inputs.force_build == 'true') }} |
| 100 | + run: echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 101 | + |
| 102 | + - name: evaluate - build_configuration |
| 103 | + id: evaluate_build_configuration |
| 104 | + env: |
| 105 | + RESULT: ${{ github.ref == 'refs/heads/main' && 'Release' || 'Debug' }} |
| 106 | + run: echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 107 | + |
| 108 | + - name: evaluate - release |
| 109 | + id: evaluate_release |
| 110 | + env: |
| 111 | + RESULT: ${{ github.ref == 'refs/heads/main' || github.event.inputs.force_release == 'true' }} |
| 112 | + run: echo "result=$RESULT" >> $GITHUB_OUTPUT |
| 113 | + |
| 114 | + |
| 115 | + build: |
| 116 | + name: build |
| 117 | + if: ${{ needs.discovery.outputs.build == 'true' }} |
| 118 | + needs: [discovery] |
| 119 | + runs-on: ubuntu-latest |
| 120 | + env: |
| 121 | + build: ${{ needs.discovery.outputs.build }} |
| 122 | + build_push: ${{ needs.discovery.outputs.build_push }} |
| 123 | + build_configuration: ${{ needs.discovery.outputs.build_configuration }} |
| 124 | + gitVersion_SemVer: ${{ needs.discovery.outputs.gitVersion_SemVer }} |
| 125 | + gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }} |
| 126 | + steps: |
| 127 | + - name: checkout |
| 128 | + uses: actions/checkout@v4 |
| 129 | + |
| 130 | + - name: tools - docker - login ghcr.io |
| 131 | + if: ${{ env.build_push == 'true' }} |
| 132 | + uses: docker/login-action@v3 |
| 133 | + with: |
| 134 | + registry: ghcr.io |
| 135 | + username: ${{ github.actor }} |
| 136 | + password: ${{ secrets.ES_GITHUB_PAT }} |
| 137 | + |
| 138 | + - name: tools - docker - login docker.io |
| 139 | + if: ${{ env.build_push == 'true' }} |
| 140 | + uses: docker/login-action@v3 |
| 141 | + with: |
| 142 | + registry: docker.io |
| 143 | + username: ${{ secrets.ES_DOCKERHUB_USERNAME }} |
| 144 | + password: ${{ secrets.ES_DOCKERHUB_PAT }} |
| 145 | + |
| 146 | + - name: tools - docker - register QEMU |
| 147 | + run: | |
| 148 | + docker run --rm --privileged multiarch/qemu-user-static --reset -p yes |
| 149 | +
|
| 150 | + - name: tools - docker - setup buildx |
| 151 | + uses: docker/setup-buildx-action@v3 |
| 152 | + with: |
| 153 | + driver: docker-container # REQUIRED for multi-platform builds |
| 154 | + |
| 155 | + - name: docker - build and push |
| 156 | + uses: docker/build-push-action@v6 |
| 157 | + with: |
| 158 | + context: ${{ env.container_image_build_context }} |
| 159 | + file: ${{ env.container_image_build_dockerfile }} |
| 160 | + build-args: | |
| 161 | + BUILD_CONFIGURATION=${{ env.build_configuration }} |
| 162 | + push: ${{ env.build_push == 'true' }} |
| 163 | + provenance: false |
| 164 | + platforms: ${{ env.container_image_build_platforms }} |
| 165 | + labels: | |
| 166 | + org.opencontainers.image.source=https://github.com/${{ github.repository }} |
| 167 | + org.opencontainers.image.url=https://github.com/${{ github.repository }} |
| 168 | + org.opencontainers.image.vendor=https://github.com/${{ github.repository_owner }} |
| 169 | + org.opencontainers.image.version=${{ env.gitVersion_SemVer }} |
| 170 | + org.opencontainers.image.revision=${{ github.sha }} |
| 171 | + tags: | |
| 172 | + ${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} |
| 173 | + ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} |
| 174 | +
|
| 175 | + release: |
| 176 | + name: release |
| 177 | + if: ${{ needs.discovery.outputs.release == 'true' && github.ref == 'refs/heads/main' }} |
| 178 | + needs: [discovery, build] |
| 179 | + runs-on: ubuntu-latest |
| 180 | + env: |
| 181 | + gitVersion_SemVer: ${{ needs.discovery.outputs.gitVersion_SemVer }} |
| 182 | + gitVersion_AssemblySemFileVer: ${{ needs.discovery.outputs.gitVersion_AssemblySemFileVer }} |
| 183 | + steps: |
| 184 | + - name: tools - docker - login ghcr.io |
| 185 | + uses: docker/login-action@v3 |
| 186 | + with: |
| 187 | + registry: ghcr.io |
| 188 | + username: ${{ github.actor }} |
| 189 | + password: ${{ secrets.ES_GITHUB_PAT }} |
| 190 | + |
| 191 | + - name: tools - docker - login docker.io |
| 192 | + uses: docker/login-action@v3 |
| 193 | + with: |
| 194 | + registry: docker.io |
| 195 | + username: ${{ secrets.ES_DOCKERHUB_USERNAME }} |
| 196 | + password: ${{ secrets.ES_DOCKERHUB_PAT }} |
| 197 | + |
| 198 | + - name: tools - docker - setup buildx |
| 199 | + uses: docker/setup-buildx-action@v3 |
| 200 | + |
| 201 | + - name: docker - tag and push - latest |
| 202 | + run: | |
| 203 | + docker buildx imagetools create \ |
| 204 | + --tag ${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:latest \ |
| 205 | + --tag ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:latest \ |
| 206 | + --tag ${{ env.container_image_repository_dockerhub }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} \ |
| 207 | + --tag ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} \ |
| 208 | + ${{ env.container_image_repository_ghcr }}/${{ env.container_image }}:${{ env.gitVersion_SemVer }} |
| 209 | +
|
| 210 | + - name: github - release - create |
| 211 | + uses: softprops/action-gh-release@v2 |
| 212 | + with: |
| 213 | + repository: ${{ github.repository }} |
| 214 | + name: v${{ env.gitVersion_SemVer }} |
| 215 | + tag_name: v${{ env.gitVersion_SemVer }} |
| 216 | + body: The release process is automated. |
| 217 | + generate_release_notes: true |
| 218 | + token: ${{ secrets.ES_GITHUB_PAT }} |
| 219 | + |
| 220 | + |
| 221 | + |
| 222 | + |
0 commit comments