-
Notifications
You must be signed in to change notification settings - Fork 136
Expand file tree
/
Copy pathpublish-Oauth2Client-package.yml
More file actions
217 lines (186 loc) · 8.17 KB
/
Copy pathpublish-Oauth2Client-package.yml
File metadata and controls
217 lines (186 loc) · 8.17 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
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
name: Publish OAuth2Client Package
on:
workflow_dispatch:
inputs:
cab_id:
description: "CAB id for the change/release"
required: true
type: string
jobs:
check-and-publish:
runs-on: ubuntu-latest
environment: prod
outputs:
# Used to conditionally run publish steps and notifications
client_version: ${{steps.calc_version.outputs.version}}
should_publish: ${{steps.check_changes.outputs.has_changes}}
permissions:
contents: write
pull-requests: write
steps:
- name: checkout dotnet repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard
fetch-depth: 0 # Fetch all history for git diff
- name: Check for changes
id: check_changes
run: |
# Get last client tag
LAST_CLIENT_TAG=$(git tag -l 'OAuthClient-*' --sort=-v:refname | head -n 1)
echo "Found last client tag: $LAST_CLIENT_TAG"
echo "last_client_tag=$LAST_CLIENT_TAG" >> $GITHUB_OUTPUT
if [ -z "$LAST_CLIENT_TAG" ]; then
echo "No previous client tag found. Treating as changed (initial release)."
echo "has_changes=true" >> $GITHUB_OUTPUT
exit 0
fi
# Check if OAuth2Client files changed since last client tag
if git diff --name-only $LAST_CLIENT_TAG HEAD | grep -q 'Xero.NetStandard.OAuth2Client/'; then
echo "Changes detected in Xero.NetStandard.OAuth2Client/"
echo "has_changes=true" >> $GITHUB_OUTPUT
else
echo "No changes detected in Xero.NetStandard.OAuth2Client/"
echo "has_changes=false" >> $GITHUB_OUTPUT
fi
working-directory: Xero-NetStandard
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Calculate OAuth2Client version
id: calc_version
if: steps.check_changes.outputs.has_changes == 'true'
run: |
LAST_CLIENT_TAG="${{ steps.check_changes.outputs.last_client_tag }}"
if [ -z "$LAST_CLIENT_TAG" ]; then
# No previous client tag, start with version from csproj
CURRENT_VERSION=$(grep '<Version>' ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj | sed 's/.*<Version>\(.*\)<\/Version>.*/\1/')
echo "No previous client tag found, using csproj version: $CURRENT_VERSION"
echo "version=$CURRENT_VERSION" >> $GITHUB_OUTPUT
exit 0
fi
LAST_VERSION=${LAST_CLIENT_TAG#OAuthClient-v}
echo "Last OAuth2Client version: $LAST_VERSION (tag: $LAST_CLIENT_TAG)"
# Determine Bump Type from Main SDK tags
BUMP_TYPE="patch"
if [[ "$GITHUB_REF_TYPE" == "tag" ]]; then
CURRENT_MAIN_TAG=$GITHUB_REF_NAME
# Find previous main tag (exclude current)
PREV_MAIN_TAG=$(git tag -l '[0-9]*.[0-9]*.[0-9]*' --sort=-v:refname | grep -v "^$CURRENT_MAIN_TAG$" | head -n 1)
if [ ! -z "$PREV_MAIN_TAG" ]; then
echo "Main SDK Bump: $PREV_MAIN_TAG -> $CURRENT_MAIN_TAG"
IFS='.' read -r m1 m2 m3 <<< "$CURRENT_MAIN_TAG"
IFS='.' read -r p1 p2 p3 <<< "$PREV_MAIN_TAG"
if [ "$m1" != "$p1" ]; then
BUMP_TYPE="major"
elif [ "$m2" != "$p2" ]; then
BUMP_TYPE="minor"
fi
fi
fi
echo "Detected bump type: $BUMP_TYPE"
# Increment version based on bump type
IFS='.' read -r c1 c2 c3 <<< "$LAST_VERSION"
if [ "$BUMP_TYPE" == "major" ]; then
NEW_VERSION="$((c1 + 1)).0.0"
elif [ "$BUMP_TYPE" == "minor" ]; then
NEW_VERSION="${c1}.$((c2 + 1)).0"
else
NEW_VERSION="${c1}.${c2}.$((c3 + 1))"
fi
echo "Incrementing version ($BUMP_TYPE): $LAST_VERSION -> $NEW_VERSION"
echo "version=$NEW_VERSION" >> $GITHUB_OUTPUT
working-directory: Xero-NetStandard
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
- name: Update csproj version
if: steps.check_changes.outputs.has_changes == 'true'
run: |
NEW_VERSION="${{steps.calc_version.outputs.version}}"
sed -i "s/<Version>.*<\/Version>/<Version>$NEW_VERSION<\/Version>/" \
./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
echo "Updated csproj to version $NEW_VERSION"
working-directory: Xero-NetStandard
- name: Setup .NET
if: steps.check_changes.outputs.has_changes == 'true'
uses: actions/setup-dotnet@v4
with:
dotnet-version: 8.0.x
- name: Restore dependencies
if: steps.check_changes.outputs.has_changes == 'true'
run: dotnet restore
working-directory: Xero-NetStandard
- name: Build
if: steps.check_changes.outputs.has_changes == 'true'
run: dotnet build --no-restore
working-directory: Xero-NetStandard
- name: Create OAuth2Client Package for Nuget.org
if: steps.check_changes.outputs.has_changes == 'true'
run: dotnet pack ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
working-directory: Xero-NetStandard
- name: Publish OAuth2Client Package to Nuget.org
if: steps.check_changes.outputs.has_changes == 'true'
run: dotnet nuget push ./Xero.NetStandard.OAuth2Client/bin/Release/Xero.NetStandard.OAuth2Client.${{steps.calc_version.outputs.version}}.nupkg --api-key ${{ secrets.NUGET_APIKEY }} --source https://api.nuget.org/v3/index.json
working-directory: Xero-NetStandard
- name: Commit, Push and Tag
if: steps.check_changes.outputs.has_changes == 'true'
run: |
git config user.name "github-actions[bot]"
git config user.email "github-actions[bot]@users.noreply.github.com"
# Commit the version bump
git add ./Xero.NetStandard.OAuth2Client/Xero.NetStandard.OAuth2Client.csproj
git commit -m "Bump OAuth2Client version to ${{steps.calc_version.outputs.version}}"
# Push the commit to master
git push origin HEAD:master
# Create and push the tag
git tag "OAuthClient-v${{steps.calc_version.outputs.version}}"
git push origin "OAuthClient-v${{steps.calc_version.outputs.version}}"
working-directory: Xero-NetStandard
env:
GH_TOKEN: ${{secrets.GITHUB_TOKEN}}
notify-slack-on-success:
runs-on: ubuntu-latest
needs: check-and-publish
if: success() && needs.check-and-publish.outputs.should_publish == 'true'
permissions:
contents: read
steps:
- name: Checkout Xero-NetStandard repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard
- name: Send slack notification on success
uses: ./Xero-NetStandard/.github/actions/notify-slack
with:
heading_text: "OAuth2Client Package publish job has succeeded !"
alert_type: "thumbsup"
job_status: "Success"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "primary"
package_version: ${{needs.check-and-publish.outputs.client_version}}
repo_link: ${{github.server_url}}/${{github.repository}}
notify-slack-on-failure:
runs-on: ubuntu-latest
needs: check-and-publish
if: failure()
permissions:
contents: read
steps:
- name: Checkout Xero-NetStandard repo
uses: actions/checkout@v4
with:
repository: XeroAPI/Xero-NetStandard
path: Xero-NetStandard
- name: Send slack notification on failure
uses: ./Xero-NetStandard/.github/actions/notify-slack
with:
heading_text: "OAuth2Client Package publish job has failed !"
alert_type: "alert"
job_status: "Failed"
XERO_SLACK_WEBHOOK_URL: ${{secrets.XERO_SLACK_WEBHOOK_URL}}
job_url: "https://github.com/${{github.repository}}/actions/runs/${{github.run_id}}"
button_type: "danger"
package_version: ${{needs.check-and-publish.outputs.client_version}}
repo_link: ${{github.server_url}}/${{github.repository}}