Repository navigation
218 lines (199 loc) · 8.13 KB
/
Copy pathdotnet-version.yml
File metadata and controls
218 lines (199 loc) · 8.13 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
218
--- # Create a new branch for the latest (released) dotnet version if there's an update
# Maintain in repo: funfair-server-template
name: "Repo: Update Dotnet Version to latest released version"
on:
push:
branches:
- "main"
paths:
- ".github/workflows/dotnet-version.yml"
- ".github/actions/dotnet-install/**"
- ".github/actions/nuget/**"
schedule:
- cron: "0 1 * * *"
concurrency:
group: "${{github.workflow}}-${{github.ref}}"
cancel-in-progress: false
jobs:
repo-info:
runs-on: &maintenance-runner >-
${{startsWith(vars.MAINTENANCE_ENVIRONMENT, '[')
&& fromJSON(vars.MAINTENANCE_ENVIRONMENT)
|| vars.MAINTENANCE_ENVIRONMENT
|| 'ubuntu-latest'}}
permissions:
contents: read
outputs:
is_template: "${{steps.visibility.outputs.is-template}}"
steps:
- name: "Initialise Workspace"
if: runner.environment == 'self-hosted'
shell: bash
run: sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE"
- name: "Set Active Environment"
shell: bash
run: |
{
echo "ACTIVE_RUNNER_NAME=$RUNNER_NAME"
echo "ACTIVE_HOSTNAME=$HOSTNAME"
echo "ACTIVE_USER=$USER"
} >> "$GITHUB_ENV"
- name: "Checkout Source"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
clean: true
fetch-depth: 1
- name: "Check repo visibility"
id: visibility
uses: ./.github/actions/check-repo-visibility
bump-dotnet-sdk-version:
needs: [repo-info]
if: needs.repo-info.outputs.is_template == 'true'
runs-on: *maintenance-runner
permissions:
contents: write
steps:
- name: "Check Required Secrets"
shell: bash
run: |
if [ -z "${SOURCE_PUSH_TOKEN}" ]; then
echo "::error::SOURCE_PUSH_TOKEN is required but not set"
exit 1
fi
env:
SOURCE_PUSH_TOKEN: "${{secrets.SOURCE_PUSH_TOKEN}}"
- name: "Initialise Workspace"
if: runner.environment == 'self-hosted'
shell: bash
run: sudo chown -R "$USER:$USER" "$GITHUB_WORKSPACE"
- name: "Set Active Environment"
shell: bash
run: |
{
echo "ACTIVE_RUNNER_NAME=$RUNNER_NAME"
echo "ACTIVE_HOSTNAME=$HOSTNAME"
echo "ACTIVE_USER=$USER"
} >> "$GITHUB_ENV"
- name: "Checkout Source"
uses: actions/checkout@3d3c42e5aac5ba805825da76410c181273ba90b1 # v7.0.1
with:
clean: true
fetch-depth: 0
token: "${{secrets.SOURCE_PUSH_TOKEN}}"
persist-credentials: true
- name: "Install dotnet"
uses: ./.github/actions/dotnet-install
with:
github-token: "${{secrets.SOURCE_PUSH_TOKEN}}"
nuget-public-restore-feed-cache: "${{vars.NUGET_BAGET_CACHE}}"
nuget-public-restore-feed: "${{vars.NUGET_PUBLIC_RESTORE_FEED || 'https://api.nuget.org/v3/index.json'}}"
nuget-additional-restore-feed-release-cache: ""
nuget-additional-restore-feed-prerelease-cache: ""
nuget-additional-restore-feed-release: ""
nuget-additional-restore-feed-prerelease: ""
- name: "Get latest available dotnet version"
id: latest-dotnet-version
shell: bash
run: |
LATEST=$(curl \
--max-time 120 \
--retry 5 \
--retry-delay 0 \
--retry-max-time 600 \
-sS \
-L \
-f \
https://dotnetcli.blob.core.windows.net/dotnet/release-metadata/releases-index.json |
jq -re '
."releases-index"
| map(select(."support-phase" == "active"))
| sort_by(."channel-version" | split(".") | map(tonumber))
| last
| ."latest-sdk"
') || {
echo "::error::Failed to download releases-index.json or read the latest active .NET SDK version from it"
exit 1
}
if [[ -z "$LATEST" || "$LATEST" == "null" ]]; then
echo "::error::Failed to determine latest active .NET SDK version from releases-index.json"
exit 1
fi
CURRENT_VER=$(jq -re '.sdk.version' src/global.json) || {
echo "::error::Failed to read sdk.version from src/global.json (file missing, invalid JSON, or sdk.version missing or null)"
exit 1
}
case "$CURRENT_VER" in
*$'\n'*|*$'\r'*) echo "::error::src/global.json sdk.version must not contain newlines"; exit 1;;
esac
echo "Latest available SDK: ${LATEST//[$'\r\n']/ } (current: $CURRENT_VER)"
if [[ ! "$LATEST" =~ ^[0-9]+\.[0-9]+\.[0-9]+(-[0-9A-Za-z]+([.-][0-9A-Za-z]+)*)?$ ]]; then
echo "::error::Latest SDK version from releases-index.json must be MAJOR.MINOR.PATCH[-PRERELEASE]"
exit 1
fi
{
echo "LATEST_RELEASE_VERSION=$LATEST"
echo "CURRENT_VERSION=$CURRENT_VER"
} >> "$GITHUB_OUTPUT"
- name: "Check if Latest is newer than the current defined"
id: upgrade_check
shell: bash
run: |
export LC_ALL=C
# semver precedence: sort -V ranks a prerelease (11.0.100-rc.3) above its release (11.0.100)
semver_gt() {
local a="$1" b="$2" a_core b_core a_pre="" b_pre="" x y i
local -a ap bp
a_core="${a%%-*}"
b_core="${b%%-*}"
[[ "$a" == *-* ]] && a_pre="${a#*-}"
[[ "$b" == *-* ]] && b_pre="${b#*-}"
if [[ "$a_core" != "$b_core" ]]; then
[[ "$(printf '%s\n' "$a_core" "$b_core" | sort -V | tail -1)" == "$a_core" ]]
return
fi
[[ "$a_pre" == "$b_pre" ]] && return 1
[[ -z "$a_pre" ]] && return 0
[[ -z "$b_pre" ]] && return 1
IFS='.' read -ra ap <<< "$a_pre"
IFS='.' read -ra bp <<< "$b_pre"
for ((i = 0; i < ${#ap[@]} && i < ${#bp[@]}; i++)); do
x="${ap[i]}"
y="${bp[i]}"
[[ "$x" == "$y" ]] && continue
if [[ "$x" =~ ^[0-9]+$ && "$y" =~ ^[0-9]+$ ]]; then
if ((10#$x > 10#$y)); then return 0; else return 1; fi
fi
[[ "$x" =~ ^[0-9]+$ ]] && return 1
[[ "$y" =~ ^[0-9]+$ ]] && return 0
if [[ "$x" > "$y" ]]; then return 0; else return 1; fi
done
if ((${#ap[@]} > ${#bp[@]})); then return 0; else return 1; fi
}
echo "Current: $CURRENT_VERSION, Latest: $LATEST_RELEASE_VERSION"
if semver_gt "$LATEST_RELEASE_VERSION" "$CURRENT_VERSION"; then
echo "NEW_VERSION=true" >> "$GITHUB_OUTPUT"
else
echo "NEW_VERSION=false" >> "$GITHUB_OUTPUT"
fi
env:
CURRENT_VERSION: "${{steps.latest-dotnet-version.outputs.CURRENT_VERSION}}"
LATEST_RELEASE_VERSION: "${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}"
- name: "Update global.json"
if: steps.upgrade_check.outputs.NEW_VERSION == 'true'
shell: bash
run: |
jq --arg ver "$LATEST_RELEASE_VERSION" '.sdk.version = $ver' src/global.json > src/global.json.tmp && mv src/global.json.tmp src/global.json
env:
LATEST_RELEASE_VERSION: "${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}"
- name: "Commit changes to new branch"
if: steps.upgrade_check.outputs.NEW_VERSION == 'true'
uses: stefanzweifel/git-auto-commit-action@d0b01107b5db882071f96de5dd4b54961ea93f4c # v7.2.1
with:
commit_message: "SDK - Update DotNet SDK to ${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}"
branch: "depends/dotnet/${{steps.latest-dotnet-version.outputs.LATEST_RELEASE_VERSION}}"
file_pattern: "src/global.json"
commit_user_name: "fun-version[bot]"
commit_user_email: "credfeto@users.noreply.github.com"
commit_author: "fun-version[bot] <credfeto@users.noreply.github.com>"
skip_dirty_check: false
create_branch: true