-
Notifications
You must be signed in to change notification settings - Fork 24
89 lines (83 loc) · 3.17 KB
/
ci-cd.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
name: CI/CD Pipeline for Auto Versioning, Building, and Publishing on Release Branch
on:
workflow_dispatch: # Manual trigger
jobs:
get_version:
runs-on: ubuntu-latest
outputs:
version: ${{ steps.get_version.outputs.version }}
steps:
- uses: actions/[email protected]
with:
fetch-depth: 0 # Fetch all history and tags
- name: Debug - List tags
run: git tag -l
- name: Debug - Show commits
run: git log --oneline
- name: Get latest tag
id: get_version
run: |
tag=$(git describe --tags $(git rev-list --tags --max-count=1) 2>/dev/null || echo "v0.0.1")
version=${tag#v} # Remove leading 'v' if present
echo "version=$version" >> $GITHUB_ENV
echo "::set-output name=version::$version"
echo "Resolved version: $version"
build:
needs: get_version
runs-on: ubuntu-latest
steps:
- uses: actions/[email protected]
- name: Setup .NET
uses: actions/[email protected]
with:
dotnet-version: '8.0'
- name: Restore dependencies
run: dotnet restore
- name: Build
run: dotnet build --no-restore -c Release
- name: Test
run: dotnet test --no-build -c Release --verbosity normal
- name: Pack
run: dotnet pack --no-build -c Release -o nupkg /p:PackageVersion=${{ needs.get_version.outputs.version }}
- name: Upload NuGet packages as artifacts
uses: actions/[email protected]
with:
name: nuget-packages
path: nupkg/*.nupkg
publish:
needs: build
if: startsWith(github.ref, 'refs/heads/release/')
runs-on: ubuntu-latest
steps:
- name: Download NuGet packages artifacts
uses: actions/[email protected]
with:
name: nuget-packages
path: nupkg
- name: Push to NuGet.org
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.NUGET_API_KEY }} -s https://api.nuget.org/v3/index.json --skip-duplicate
- name: Push to GitHub Packages
run: dotnet nuget push "**/*.nupkg" -k ${{ secrets.GITHUB_TOKEN }} -s https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json --skip-duplicate
merge_to_master:
needs: publish
runs-on: ubuntu-latest
steps:
- name: Checkout master branch
uses: actions/[email protected]
with:
ref: master
fetch-depth: 0 # Fetch all history to avoid shallow clone issues
- name: Checkout release branch
uses: actions/[email protected]
with:
ref: ${{ github.ref }} # Checkout the release branch that triggered the workflow
path: release_branch
- name: Merge release branch into master
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git remote set-url origin https://x-access-token:${{ secrets.GITHUB_TOKEN }}@github.com/${{ github.repository_owner }}/{{ github.repository_name }}.git
git fetch origin master
git checkout master
git merge --no-ff --no-edit release_branch
git push origin master