|
1 | | -name: CI (Build, Test, Alpha Publish) |
| 1 | +name: Build, Test, and Deploy to Docker Hub |
2 | 2 |
|
3 | 3 | on: |
4 | | - pull_request: |
5 | | - branches: ["**"] |
6 | 4 | push: |
7 | | - branches: ["**"] |
8 | | - tags-ignore: ["v*"] |
| 5 | + branches: [master, main] |
| 6 | + pull_request: |
| 7 | + branches: [master, main] |
9 | 8 |
|
10 | | -permissions: |
11 | | - contents: read |
12 | | - packages: write |
| 9 | +env: |
| 10 | + REGISTRY: docker.io |
| 11 | + IMAGE_NAME: ${{ github.repository }} |
13 | 12 |
|
14 | 13 | jobs: |
15 | | - build-test-pack: |
| 14 | + build-and-deploy: |
16 | 15 | runs-on: ubuntu-latest |
17 | 16 | env: |
18 | 17 | working-directory: ${{ github.workspace }} |
| 18 | + |
19 | 19 | steps: |
20 | | - - name: Checkout |
| 20 | + - name: Checkout code |
21 | 21 | uses: actions/checkout@v4 |
22 | 22 | with: |
23 | | - fetch-depth: 0 # GitVersion needs full history / tags |
24 | | - |
25 | | - - name: Setup .NET |
26 | | - uses: actions/setup-dotnet@v4 |
27 | | - with: |
28 | | - dotnet-version: 9.0.x |
29 | | - |
30 | | - - name: Install GitVersion |
31 | | - uses: gittools/actions/gitversion/setup@v0.9.15 |
32 | | - with: |
33 | | - versionSpec: 5.x |
| 23 | + fetch-depth: 0 |
| 24 | + - name: Lint Code Base |
| 25 | + uses: github/super-linter@v4 |
| 26 | + env: |
| 27 | + VALIDATE_ALL_CODEBASE: false |
| 28 | + FILTER_REGEX_INCLUDE: .*src/.* |
| 29 | + DEFAULT_BRANCH: master |
| 30 | + GITHUB_TOKEN: '${{ env.github-token }}' |
34 | 31 |
|
35 | | - - name: Determine Version |
36 | | - id: gitversion |
37 | | - uses: gittools/actions/gitversion/execute@v0.9.15 |
| 32 | + - name: Set up .NET |
| 33 | + uses: actions/setup-dotnet@v3 |
38 | 34 | with: |
39 | | - useConfigFile: true |
| 35 | + dotnet-version: '9.0.x' |
40 | 36 |
|
41 | | - - name: Display Version |
42 | | - run: | |
43 | | - echo "NuGetVersion: ${{ steps.gitversion.outputs.NuGetVersionV2 }}" |
44 | | - echo "PreReleaseTag: ${{ steps.gitversion.outputs.PreReleaseTag }}" |
45 | | -
|
46 | | - - name: Restore |
| 37 | + - name: Restore dependencies |
47 | 38 | run: dotnet restore |
48 | 39 | working-directory: '${{ env.working-directory }}' |
49 | | - |
| 40 | + |
50 | 41 | - name: Build |
51 | | - run: dotnet build --configuration Release --no-restore |
| 42 | + run: dotnet build --no-restore --configuration Release |
52 | 43 | working-directory: '${{ env.working-directory }}' |
53 | 44 |
|
54 | | - - name: Test |
55 | | - run: dotnet test --configuration Release --no-build --collect:"XPlat Code Coverage" |
| 45 | + - name: Run tests |
| 46 | + run: dotnet test --no-build --verbosity normal |
56 | 47 | working-directory: '${{ env.working-directory }}' |
| 48 | + |
| 49 | + - name: Set up Docker Buildx |
| 50 | + uses: docker/setup-buildx-action@v3 |
57 | 51 |
|
58 | | - - name: Pack (Pre-release or Alpha) |
59 | | - if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }} |
60 | | - run: | |
61 | | - dotnet pack src/eAuthor.API/eAuthor.API.csproj \ |
62 | | - -c Release -o artifacts \ |
63 | | - /p:PackageVersion=${{ steps.gitversion.outputs.NuGetVersionV2 }} |
| 52 | + - name: Login to Docker Hub |
| 53 | + uses: docker/login-action@v3 |
| 54 | + with: |
| 55 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 56 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
64 | 57 |
|
65 | | - - name: Add GitHub Packages Source |
66 | | - if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }} |
67 | | - run: | |
68 | | - dotnet nuget add source \ |
69 | | - --username $GITHUB_ACTOR \ |
70 | | - --password ${{ secrets.GITHUB_TOKEN }} \ |
71 | | - --store-password-in-clear-text \ |
72 | | - --name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json" |
| 58 | + - name: Build and push Docker image |
| 59 | + uses: docker/build-push-action@v5 |
| 60 | + with: |
| 61 | + context: . |
| 62 | + push: true |
| 63 | + tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest |
73 | 64 |
|
74 | | - - name: Publish Alpha to GitHub Packages |
75 | | - if: ${{ steps.gitversion.outputs.PreReleaseTag != '' && github.ref_type == 'branch' && github.ref != 'refs/heads/main' }} |
76 | | - run: dotnet nuget push "artifacts/*.nupkg" --api-key ${{ secrets.GITHUB_TOKEN }} --source "github" --skip-duplicate |
| 65 | + - name: Logout from Docker Hub |
| 66 | + if: always() |
| 67 | + run: docker logout |
0 commit comments