-
Notifications
You must be signed in to change notification settings - Fork 1
157 lines (129 loc) · 4.76 KB
/
Copy pathrelease_bugfix.yml
File metadata and controls
157 lines (129 loc) · 4.76 KB
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
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
name: Release Bugfix
on:
workflow_dispatch:
jobs:
run-tests:
name: Run Tests
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup .NET
uses: actions/setup-dotnet@v4
with:
dotnet-version: 9.0.x
- name: Authenticate with GitHub Packages
run: |
dotnet nuget add source \
--username ${{ github.actor }} \
--password ${{ secrets.GITHUB_TOKEN }} \
--store-password-in-clear-text \
--name github "https://nuget.pkg.github.com/${{ github.repository_owner }}/index.json"
- name: Restore dependencies
run: |
dotnet restore
- name: Build
run: dotnet build --no-restore
- name: Test
run: dotnet test --no-build --verbosity normal
create-tag:
name: Create Tag
needs: run-tests
runs-on: ubuntu-latest
permissions:
contents: write
outputs:
version: ${{ steps.extract_version.outputs.version }}
tag: ${{ steps.extract_version.outputs.tag }}
is_latest: ${{ steps.check_latest.outputs.is_latest }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate bugfix branch
run: |
current_branch="${{ github.ref_name }}"
if [[ ! "$current_branch" =~ ^bugfix/ ]]; then
echo "Error: This workflow must be run from a bugfix/* branch"
echo "Current branch: $current_branch"
exit 1
fi
echo "Running on bugfix branch: $current_branch"
- name: Extract version from branch name
id: extract_version
run: |
current_branch="${{ github.ref_name }}"
# Extract version from bugfix/X.Y.Z format
version="${current_branch#bugfix/}"
# Validate semver format
if ! echo "$version" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-[a-zA-Z0-9.-]+)?$'; then
echo "Error: Invalid version format in branch name. Expected bugfix/X.Y.Z"
exit 1
fi
tag="v${version}"
echo "version=$version" >> $GITHUB_OUTPUT
echo "tag=$tag" >> $GITHUB_OUTPUT
echo "Extracted version: $version"
- name: Check if this should be latest release
id: check_latest
run: |
current_version="${{ steps.extract_version.outputs.version }}"
# Get all tags and find the highest version
highest_version=$(git tag -l 'v*' | sed 's/^v//' | sort -V | tail -n 1)
if [ -z "$highest_version" ]; then
echo "No existing tags found, this will be latest"
echo "is_latest=true" >> $GITHUB_OUTPUT
else
echo "Current version: $current_version"
echo "Highest existing version: $highest_version"
# Compare versions using sort -V
highest=$(printf "%s\n%s" "$current_version" "$highest_version" | sort -V | tail -n 1)
if [ "$highest" = "$current_version" ]; then
echo "This version is higher than or equal to existing versions, marking as latest"
echo "is_latest=true" >> $GITHUB_OUTPUT
else
echo "This version is lower than existing versions, not marking as latest"
echo "is_latest=false" >> $GITHUB_OUTPUT
fi
fi
- name: Bump version in .csproj files
uses: ./.github/actions/bump-version
with:
version: ${{ steps.extract_version.outputs.version }}
- name: Create and push tag
uses: ./.github/actions/create-tag
with:
tag: ${{ steps.extract_version.outputs.tag }}
publish-nuget:
name: Publish NuGet Packages
needs: create-tag
uses: ./.github/workflows/publish_nuget.yml
with:
version: ${{ needs.create-tag.outputs.version }}
permissions:
packages: write
contents: read
create-release:
name: Create GitHub Release
needs: [ create-tag, publish-nuget ]
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Create GitHub Release
uses: ncipollo/release-action@v1
with:
tag: ${{ needs.create-tag.outputs.tag }}
name: Release ${{ needs.create-tag.outputs.tag }}
generateReleaseNotes: true
makeLatest: ${{ needs.create-tag.outputs.is_latest == 'true' }}
body: |
NuGet packages published to GitHub Packages.
### Installation
```bash
dotnet add package DataPlane.Sdk.Core --version ${{ needs.create-tag.outputs.version }}
dotnet add package DataPlane.Sdk.Api --version ${{ needs.create-tag.outputs.version }}
```
draft: false
prerelease: false