|
1 | | -name: Action to build and publish the project as a nuget package to github package registry |
| 1 | +name: Build and push |
2 | 2 |
|
3 | 3 | on: |
4 | 4 | push: |
5 | | - branches: |
6 | | - - main |
| 5 | + branches: [main] |
7 | 6 | paths: |
8 | 7 | - "Sources/EasyVault.SDK/**" |
| 8 | + - "Sources/easyvault.client/**" |
| 9 | + - "Sources/EasyVault.Server/**" |
9 | 10 | - ".github/workflows/publish-release.yaml" |
| 11 | + workflow_dispatch: |
| 12 | + |
| 13 | +env: |
| 14 | + CONTEXT_DIR: Sources |
| 15 | + DOCKERFILE: Dockerfile |
| 16 | + DOCKER_NAMESPACE: bvdcode |
| 17 | + DOCKER_IMAGE_NAME: easyvault |
10 | 18 |
|
11 | 19 | jobs: |
12 | 20 | build: |
| 21 | + name: Build Docker image |
13 | 22 | runs-on: ubuntu-latest |
14 | | - outputs: |
15 | | - Version: ${{ steps.gitversion.outputs.SemVer }} |
16 | | - CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }} |
| 23 | + permissions: |
| 24 | + contents: write |
| 25 | + packages: write |
17 | 26 |
|
18 | 27 | steps: |
19 | | - - uses: actions/checkout@v2 |
| 28 | + - name: Checkout (full history + tags) |
| 29 | + uses: actions/checkout@v4 |
20 | 30 | with: |
21 | | - fetch-depth: 0 #fetch-depth is needed for GitVersion |
| 31 | + lfs: true |
| 32 | + fetch-depth: 0 |
| 33 | + fetch-tags: true |
22 | 34 |
|
23 | | - #Install and calculate the new version with GitVersion |
24 | 35 | - name: Install GitVersion |
25 | 36 | uses: gittools/actions/gitversion/setup@v3.1.11 |
26 | 37 | with: |
27 | 38 | versionSpec: 5.x |
| 39 | + |
28 | 40 | - name: Determine Version |
| 41 | + id: gitversion |
29 | 42 | uses: gittools/actions/gitversion/execute@v3.1.11 |
30 | | - id: gitversion # step id used as reference for output values |
| 43 | + |
31 | 44 | - name: Display GitVersion outputs |
32 | 45 | run: | |
33 | | - echo "Version: ${{ steps.gitversion.outputs.SemVer }}" |
| 46 | + echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}" |
34 | 47 | echo "CommitsSinceVersionSource: ${{ steps.gitversion.outputs.CommitsSinceVersionSource }}" |
| 48 | + echo "Major.Minor: v${{ steps.gitversion.outputs.Major }}.${{ steps.gitversion.outputs.Minor }}" |
| 49 | +
|
| 50 | + - name: Compose tags |
| 51 | + id: tags |
| 52 | + shell: bash |
| 53 | + run: | |
| 54 | + V_MINOR="v${{ steps.gitversion.outputs.Major }}.${{ steps.gitversion.outputs.Minor }}" |
| 55 | + echo "minor_tag=$V_MINOR" >> "$GITHUB_OUTPUT" |
| 56 | + echo "docker_tag=${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:$V_MINOR" >> "$GITHUB_OUTPUT" |
| 57 | + echo "docker_tag_latest=${{ env.DOCKER_NAMESPACE }}/${{ env.DOCKER_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" |
| 58 | + echo "ghcr_tag=ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:$V_MINOR" >> "$GITHUB_OUTPUT" |
| 59 | + echo "ghcr_tag_latest=ghcr.io/${{ github.repository_owner }}/${{ env.DOCKER_IMAGE_NAME }}:latest" >> "$GITHUB_OUTPUT" |
| 60 | +
|
| 61 | + - name: Login to Docker Hub |
| 62 | + uses: docker/login-action@v3 |
| 63 | + with: |
| 64 | + username: ${{ secrets.DOCKERHUB_USERNAME }} |
| 65 | + password: ${{ secrets.DOCKERHUB_TOKEN }} |
| 66 | + |
| 67 | + - name: Build & push to Docker Hub (vX.Y + latest) |
| 68 | + uses: docker/build-push-action@v6 |
| 69 | + with: |
| 70 | + context: ${{ env.CONTEXT_DIR }} |
| 71 | + file: ${{ env.CONTEXT_DIR }}/${{ env.DOCKERFILE }} |
| 72 | + push: true |
| 73 | + tags: | |
| 74 | + ${{ steps.tags.outputs.docker_tag }} |
| 75 | + ${{ steps.tags.outputs.docker_tag_latest }} |
| 76 | +
|
| 77 | + - name: Login to GHCR |
| 78 | + uses: docker/login-action@v3 |
| 79 | + with: |
| 80 | + registry: ghcr.io |
| 81 | + username: ${{ github.actor }} |
| 82 | + password: ${{ secrets.GITHUB_TOKEN }} |
| 83 | + |
| 84 | + - name: Build & push to GHCR (vX.Y + latest) |
| 85 | + uses: docker/build-push-action@v6 |
| 86 | + with: |
| 87 | + context: ${{ env.CONTEXT_DIR }} |
| 88 | + file: ${{ env.CONTEXT_DIR }}/${{ env.DOCKERFILE }} |
| 89 | + push: true |
| 90 | + tags: | |
| 91 | + ${{ steps.tags.outputs.ghcr_tag }} |
| 92 | + ${{ steps.tags.outputs.ghcr_tag_latest }} |
35 | 93 |
|
36 | 94 | #Build/pack the project |
37 | 95 | - name: Setup .NET |
@@ -69,19 +127,12 @@ jobs: |
69 | 127 | dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json |
70 | 128 |
|
71 | 129 | #Create release |
72 | | - - name: Create Release |
73 | | - if: 1 == 0 #needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change |
74 | | - uses: actions/create-release@v1 |
75 | | - env: |
76 | | - GITHUB_TOKEN: ${{ secrets.DEPLOY_GITHUB_TOKEN }} |
77 | | - with: |
78 | | - tag_name: ${{ needs.build.outputs.Version }} |
79 | | - release_name: Release ${{ needs.build.outputs.Version }} |
80 | | - - name: Create Release |
81 | | - if: needs.build.outputs.CommitsSinceVersionSource > 0 #Only release if there has been a commit/version change |
| 130 | + - name: Create GitHub Release (only if version advanced) |
| 131 | + if: ${{ steps.gitversion.outputs.CommitsSinceVersionSource > 0 }} |
82 | 132 | uses: ncipollo/release-action@v1 |
83 | 133 | with: |
84 | | - tag: ${{ needs.build.outputs.Version }} |
85 | | - name: Release ${{ needs.build.outputs.Version }} |
86 | | - artifacts: "nupkg/*" |
87 | | - token: ${{ secrets.DEPLOY_GITHUB_TOKEN }} |
| 134 | + tag: ${{ steps.tags.outputs.minor_tag }} |
| 135 | + name: Release ${{ steps.tags.outputs.minor_tag }} |
| 136 | + draft: false |
| 137 | + prerelease: false |
| 138 | + token: ${{ github.token }} |
0 commit comments