Skip to content

Commit 8cdc37d

Browse files
author
Vadim Belov
committed
Refactor publish-release workflow to enhance Docker image build and push steps
1 parent 20862cf commit 8cdc37d

2 files changed

Lines changed: 76 additions & 78 deletions

File tree

.github/workflows/docker-image.yml

Lines changed: 0 additions & 53 deletions
This file was deleted.

.github/workflows/publish-release.yml

Lines changed: 76 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,95 @@
1-
name: Action to build and publish the project as a nuget package to github package registry
1+
name: Build and push
22

33
on:
44
push:
5-
branches:
6-
- main
5+
branches: [main]
76
paths:
87
- "Sources/EasyVault.SDK/**"
8+
- "Sources/easyvault.client/**"
9+
- "Sources/EasyVault.Server/**"
910
- ".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
1018

1119
jobs:
1220
build:
21+
name: Build Docker image
1322
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
1726

1827
steps:
19-
- uses: actions/checkout@v2
28+
- name: Checkout (full history + tags)
29+
uses: actions/checkout@v4
2030
with:
21-
fetch-depth: 0 #fetch-depth is needed for GitVersion
31+
lfs: true
32+
fetch-depth: 0
33+
fetch-tags: true
2234

23-
#Install and calculate the new version with GitVersion
2435
- name: Install GitVersion
2536
uses: gittools/actions/gitversion/setup@v3.1.11
2637
with:
2738
versionSpec: 5.x
39+
2840
- name: Determine Version
41+
id: gitversion
2942
uses: gittools/actions/gitversion/execute@v3.1.11
30-
id: gitversion # step id used as reference for output values
43+
3144
- name: Display GitVersion outputs
3245
run: |
33-
echo "Version: ${{ steps.gitversion.outputs.SemVer }}"
46+
echo "SemVer: ${{ steps.gitversion.outputs.SemVer }}"
3447
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 }}
3593
3694
#Build/pack the project
3795
- name: Setup .NET
@@ -69,19 +127,12 @@ jobs:
69127
dotnet nuget push *.nupkg --skip-duplicate --api-key ${{ secrets.NUGET_KEY }} --source https://api.nuget.org/v3/index.json
70128
71129
#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 }}
82132
uses: ncipollo/release-action@v1
83133
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

Comments
 (0)