@@ -21,40 +21,33 @@ runs:
2121 set -euo pipefail
2222
2323 PROJECT=${{ github.event.repository.name }}
24+ NEW_VERSION=${{ inputs.newVersion }}
2425 GITHUB_USER=$(gh api /user --jq '.login')
2526
2627 # Check if project exists on Spring website
27- HTTP_CODE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" \
28- -H "Content-Type: application/json" \
29- -o /dev/null -w '%{http_code}' \
30- "https://api.spring.io/projects/$PROJECT")
28+ HTTP_CODE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json" -o /dev/null -w '%{http_code}' "https://api.spring.io/projects/$PROJECT")
3129
32- if [ " $HTTP_CODE" != " 200" ]
30+ if [ $HTTP_CODE != 200 ]
3331 then
34- echo "::notice title=Nothing to update on Spring website::No versions update for $PROJECT project which is not listed on Spring website."
35- exit 0
32+ echo "::notice title=Nothing to update on Spring website::No versions update for $PROJECT project which is not listed on Spring website."
33+ exit 0
3634 fi
3735
38- VERSIONS_TO_UPDATE=${{ inputs.newVersion }}
39-
40- MAJOR_MINOR=$(echo ${{ inputs.newVersion }} | cut -d '.' -f1-2)
36+ MAJOR_MINOR=$(echo $NEW_VERSION | cut -d '.' -f1-2)
4137
4238 # Fetch OSS support end date
43- OSS_SUPPORT_END_DATE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" \
44- -H "Content-Type: application/json" \
45- "https://api.spring.io/projects/$PROJECT/generations/${MAJOR_MINOR}.x" | \
46- jq -r '.ossSupportEndDate // empty')
39+ OSS_SUPPORT_END_DATE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json" "https://api.spring.io/projects/$PROJECT/generations/${MAJOR_MINOR}.x" | jq -r '.ossSupportEndDate // empty')
40+
41+ VERSIONS_TO_UPDATE=$NEW_VERSION
4742
4843 # Add next SNAPSHOT version if OSS support is still active
4944 if [[ -n "$OSS_SUPPORT_END_DATE" && "$OSS_SUPPORT_END_DATE" > "$(date '+%F')" ]]
5045 then
51- NEXT_SNAPSHOT=${{ inputs.newVersion }}
52-
53- if [[ $NEXT_SNAPSHOT == *"-"* ]]
46+ if [[ $NEW_VERSION == *"-"* ]]
5447 then
55- NEXT_SNAPSHOT=${NEXT_SNAPSHOT /-*}
48+ NEXT_SNAPSHOT=${NEW_VERSION /-*}
5649 else
57- PATCH=$(echo $NEXT_SNAPSHOT | cut -d '.' -f3)
50+ PATCH=$(echo $NEW_VERSION | cut -d '.' -f3)
5851 PATCH=$((PATCH+1))
5952 NEXT_SNAPSHOT=$MAJOR_MINOR.$PATCH
6053 fi
@@ -64,38 +57,37 @@ runs:
6457 fi
6558
6659 # Fetch versions to remove
67- VERSIONS_TO_REMOVE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" \
68- -H "Content-Type: application/json" \
69- "https://api.spring.io/projects/$PROJECT/releases" | \
70- jq -r "._embedded.releases[].version | select(startswith(\"$MAJOR_MINOR\"))")
60+ VERSIONS_TO_REMOVE=$(curl -s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json" "https://api.spring.io/projects/$PROJECT/releases" | jq -r "._embedded.releases[].version | select(startswith(\"$MAJOR_MINOR\"))")
7161
72- # Remove old versions
62+ # Remove old versions if they are not in the list of versions to update
7363 for VERSION_TO_REMOVE in $VERSIONS_TO_REMOVE
7464 do
75- echo "Removing version: $VERSION_TO_REMOVE"
76-
77- curl -s -u "$GITHUB_USER:$GH_TOKEN" \
78- -H "Content-Type: application/json" \
79- -X DELETE \
80- --fail --show-error \
81- "https://api.spring.io/projects/$PROJECT/releases/$VERSION_TO_REMOVE"
65+ if ! echo "$VERSIONS_TO_UPDATE" | grep -qw "$VERSION_TO_REMOVE"
66+ then
67+ curl -s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json" -X DELETE --fail --show-error "https://api.spring.io/projects/$PROJECT/releases/$VERSION_TO_REMOVE"
68+ fi
8269 done
8370
84- # sleep 1
85-
8671 # Add new versions
8772 for VERSION in $VERSIONS_TO_UPDATE
8873 do
89- echo "Adding version : $VERSION"
90-
74+ SKIP_VERSION=false
75+ for VERSION_TO_REMOVE in $VERSIONS_TO_REMOVE
76+ do
77+ if [ $VERSION_TO_REMOVE = $VERSION ]
78+ then
79+ SKIP_VERSION=true
80+ break
81+ fi
82+ done
83+
84+ if [ $SKIP_VERSION = false ]
85+ then
9186 VERSION_JSON=$(jq -n \
92- --arg version "$VERSION" \
93- --arg project "$PROJECT" \
94- ' {version: $version, referenceDocUrl: "https://docs.spring.io/\($project)/reference/{version}", apiDocUrl: "https://docs.spring.io/\($project)/docs/\($version)/api", isAntora: true}' )
87+ --arg version "$VERSION" \
88+ --arg project "$PROJECT" \
89+ '{version: $version, referenceDocUrl: "https://docs.spring.io/\($project)/reference/{version}", apiDocUrl: "https://docs.spring.io/\($project)/docs/\($version)/api", isAntora: true}')
9590
96- curl -s -u "$GITHUB_USER:$GH_TOKEN" \
97- -H "Content-Type : application/json" \
98- -d "$VERSION_JSON" \
99- --fail --show-error \
100- " https://api.spring.io/projects/$PROJECT/releases"
91+ curl -s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json" -d "$VERSION_JSON" --fail --show-error "https://api.spring.io/projects/$PROJECT/releases"
92+ fi
10193 done
0 commit comments