-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathaction.yml
More file actions
93 lines (78 loc) · 3.57 KB
/
action.yml
File metadata and controls
93 lines (78 loc) · 3.57 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
name: Update the Spring website project page for new version
description: 'Update the Spring website project page for new version. The SNAPSHOT version is also added if generation permits. Supports only Antora docs.'
inputs:
newVersion:
description: 'The version to add to project page'
required: true
token:
description: 'A GitHub token for REST api calls'
required: true
runs:
using: composite
steps:
- name: Update project page for new version
shell: bash
env:
GH_TOKEN: ${{ inputs.token }}
run: |
set -euo pipefail
PROJECT=${{ github.event.repository.name }}
NEW_VERSION=${{ inputs.newVersion }}
GITHUB_USER=$(gh api /user --jq '.login')
BASE_URL="https://api.spring.io/projects/$PROJECT"
declare -a CURL_OPTS=(-s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json")
# Check if project exists on Spring website
HTTP_CODE=$(curl "${CURL_OPTS[@]}" -o /dev/null -w '%{http_code}' "$BASE_URL")
if [ "$HTTP_CODE" != "200" ]
then
echo "::notice title=Nothing to update on Spring website:: No versions update for $PROJECT project which is not listed on Spring website."
exit 0
fi
MAJOR_MINOR=$(echo "$NEW_VERSION" | cut -d '.' -f1-2)
# Fetch OSS support end date
OSS_SUPPORT_END_DATE=$(curl "${CURL_OPTS[@]}" "$BASE_URL/generations/${MAJOR_MINOR}.x" | jq -r '.ossSupportEndDate // empty')
VERSIONS_TO_UPDATE=$NEW_VERSION
# Add next SNAPSHOT version if OSS support is still active
if [[ -n "$OSS_SUPPORT_END_DATE" && "$OSS_SUPPORT_END_DATE" > "$(date '+%F')" ]]
then
if [[ "$NEW_VERSION" == *"-"* ]]
then
NEXT_SNAPSHOT=${NEW_VERSION/-*}
else
PATCH=$(echo "$NEW_VERSION" | cut -d '.' -f3)
PATCH=$((PATCH+1))
NEXT_SNAPSHOT=$MAJOR_MINOR.$PATCH
fi
NEXT_SNAPSHOT+='-SNAPSHOT'
VERSIONS_TO_UPDATE+=" $NEXT_SNAPSHOT"
fi
# Fetch versions to remove
VERSIONS_TO_REMOVE=$(curl "${CURL_OPTS[@]}" "$BASE_URL/releases" \
| jq -r --arg major_minor "$MAJOR_MINOR" '._embedded.releases[].version | select(startswith($major_minor))')
# Delete old versions and filter out existing from VERSIONS_TO_UPDATE
for VERSION_TO_REMOVE in $VERSIONS_TO_REMOVE
do
if echo "$VERSIONS_TO_UPDATE" | grep -qw "$VERSION_TO_REMOVE"
then
# Version exists in update list, remove it from update list
VERSIONS_TO_UPDATE=$(echo ${VERSIONS_TO_UPDATE//$VERSION_TO_REMOVE/})
else
# Version not in update list, delete it
curl "${CURL_OPTS[@]}" -X DELETE --fail --show-error "$BASE_URL/releases/$VERSION_TO_REMOVE"
fi
done
# Add new versions (only the ones remaining in VERSIONS_TO_UPDATE)
if [ -n "$VERSIONS_TO_UPDATE" ]
then
for VERSION in $VERSIONS_TO_UPDATE
do
VERSION_JSON=$(jq -n \
--arg version "$VERSION" \
--arg project "$PROJECT" \
'{version: $version,
referenceDocUrl: "https://docs.spring.io/\($project)/reference/{version}",
apiDocUrl: "https://docs.spring.io/\($project)/docs/\($version)/api",
isAntora: true}')
curl "${CURL_OPTS[@]}" -d "$VERSION_JSON" --fail --show-error "$BASE_URL/releases"
done
fi