|
| 1 | +name: Update the Spring website project page for new version |
| 2 | + |
| 3 | +description: 'Update the Spring website project page for new version. The SNAPSHOT version is also added if generation permits. Supports only Antora docs.' |
| 4 | + |
| 5 | +inputs: |
| 6 | + newVersion: |
| 7 | + description: 'The version to add to project page' |
| 8 | + required: true |
| 9 | + token: |
| 10 | + description: 'A GitHub token for REST api calls' |
| 11 | + required: true |
| 12 | + |
| 13 | +runs: |
| 14 | + using: composite |
| 15 | + steps: |
| 16 | + - name: Update project page for new version |
| 17 | + shell: bash |
| 18 | + env: |
| 19 | + GH_TOKEN: ${{ inputs.token }} |
| 20 | + run: | |
| 21 | + set -euo pipefail |
| 22 | +
|
| 23 | + PROJECT=${{ github.event.repository.name }} |
| 24 | + NEW_VERSION=${{ inputs.newVersion }} |
| 25 | + GITHUB_USER=$(gh api /user --jq '.login') |
| 26 | + BASE_URL="https://api.spring.io/projects/$PROJECT" |
| 27 | + declare -a CURL_OPTS=(-s -u "$GITHUB_USER:$GH_TOKEN" -H "Content-Type: application/json") |
| 28 | + |
| 29 | + # Check if project exists on Spring website |
| 30 | + HTTP_CODE=$(curl "${CURL_OPTS[@]}" -o /dev/null -w '%{http_code}' "$BASE_URL") |
| 31 | + |
| 32 | + if [ "$HTTP_CODE" != "200" ] |
| 33 | + 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 |
| 36 | + fi |
| 37 | + |
| 38 | + MAJOR_MINOR=$(echo "$NEW_VERSION" | cut -d '.' -f1-2) |
| 39 | + |
| 40 | + # Fetch OSS support end date |
| 41 | + OSS_SUPPORT_END_DATE=$(curl "${CURL_OPTS[@]}" "$BASE_URL/generations/${MAJOR_MINOR}.x" \ |
| 42 | + | jq -r '.ossSupportEndDate // empty') |
| 43 | + |
| 44 | + VERSIONS_TO_UPDATE=$NEW_VERSION |
| 45 | + |
| 46 | + # Add next SNAPSHOT version if OSS support is still active |
| 47 | + if [[ -n "$OSS_SUPPORT_END_DATE" && "$OSS_SUPPORT_END_DATE" > "$(date '+%F')" ]] |
| 48 | + then |
| 49 | + if [[ "$NEW_VERSION" == *"-"* ]] |
| 50 | + then |
| 51 | + NEXT_SNAPSHOT=${NEW_VERSION/-*} |
| 52 | + else |
| 53 | + PATCH=$(echo "$NEW_VERSION" | cut -d '.' -f3) |
| 54 | + PATCH=$((PATCH+1)) |
| 55 | + NEXT_SNAPSHOT=$MAJOR_MINOR.$PATCH |
| 56 | + fi |
| 57 | + |
| 58 | + NEXT_SNAPSHOT+='-SNAPSHOT' |
| 59 | + VERSIONS_TO_UPDATE+=" $NEXT_SNAPSHOT" |
| 60 | + fi |
| 61 | + |
| 62 | + # Fetch versions to remove |
| 63 | + VERSIONS_TO_REMOVE=$(curl "${CURL_OPTS[@]}" "$BASE_URL/releases" \ |
| 64 | + | jq -r --arg major_minor "$MAJOR_MINOR" '._embedded.releases[].version | select(startswith($major_minor))') |
| 65 | + |
| 66 | + # Delete old versions and filter out existing from VERSIONS_TO_UPDATE |
| 67 | + for VERSION_TO_REMOVE in $VERSIONS_TO_REMOVE |
| 68 | + do |
| 69 | + if echo "$VERSIONS_TO_UPDATE" | grep -qw "$VERSION_TO_REMOVE" |
| 70 | + then |
| 71 | + # Version exists in update list, remove it from update list |
| 72 | + VERSIONS_TO_UPDATE=$(echo ${VERSIONS_TO_UPDATE//$VERSION_TO_REMOVE/}) |
| 73 | + else |
| 74 | + # Version not in update list, delete it |
| 75 | + curl "${CURL_OPTS[@]}" -X DELETE --fail --show-error "$BASE_URL/releases/$VERSION_TO_REMOVE" |
| 76 | + fi |
| 77 | + done |
| 78 | + |
| 79 | + # Add new versions (only the ones remaining in VERSIONS_TO_UPDATE) |
| 80 | + if [ -n "$VERSIONS_TO_UPDATE" ] |
| 81 | + then |
| 82 | + for VERSION in $VERSIONS_TO_UPDATE |
| 83 | + do |
| 84 | + VERSION_JSON=$(jq -n \ |
| 85 | + --arg version "$VERSION" \ |
| 86 | + --arg project "$PROJECT" \ |
| 87 | + '{version: $version, |
| 88 | + referenceDocUrl: "https://docs.spring.io/\($project)/reference/{version}", |
| 89 | + apiDocUrl: "https://docs.spring.io/\($project)/docs/\($version)/api", |
| 90 | + isAntora: true}') |
| 91 | + |
| 92 | + curl "${CURL_OPTS[@]}" -d "$VERSION_JSON" --fail --show-error "$BASE_URL/releases" |
| 93 | + done |
| 94 | + fi |
0 commit comments