1- # Sample workflow for building and deploying a Web site to GitHub Pages
2- #
3- # To get started with Web see: https://nextjs.org/docs/getting-started
4- #
51name : Deploy Web site to Pages
62
73on :
4541 cache : " pnpm"
4642
4743 - name : Update data.json with latest versions and publish dates
44+ env :
45+ GH_TOKEN : ${{ secrets.GITHUB_TOKEN }}
4846 run : |
4947 set -e
5048
@@ -57,34 +55,74 @@ jobs:
5755
5856 echo "App Version: $APP_FULL_VERSION, Server Version: $SERVER_FULL_VERSION"
5957
58+ # Function to get the publish date for a given tag.
59+ # It first tries to get the date from a GitHub Release.
60+ # If that fails, it tries to get the date from the Git Tag object itself.
61+ get_date_for_tag() {
62+ local repo_slug="$1"
63+ local tag="$2"
64+ local date_val=""
65+
66+ echo " - Checking release for tag: $tag"
67+ # Attempt 1: Get date from the GitHub Release
68+ date_val=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \
69+ "https://api.github.com/repos/${repo_slug}/releases/tags/${tag}" | \
70+ jq -r '.created_at | split("T")[0]' 2>/dev/null)
71+
72+ # Attempt 2: If release not found, get date from the Git Tag object
73+ if [[ -z "$date_val" || "$date_val" == "null" ]]; then
74+ echo " - Release for tag '$tag' not found. Checking Git Tag object..."
75+ # First, get the SHA of the tag object
76+ TAG_SHA=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \
77+ "https://api.github.com/repos/${repo_slug}/git/refs/tags/${tag}" | \
78+ jq -r '.object.sha' 2>/dev/null)
79+
80+ if [[ -n "$TAG_SHA" && "$TAG_SHA" != "null" ]]; then
81+ # Then, use the SHA to get the tagger's date from the tag object
82+ date_val=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \
83+ "https://api.github.com/repos/${repo_slug}/git/tags/${TAG_SHA}" | \
84+ jq -r '.tagger.date | split("T")[0]' 2>/dev/null)
85+ echo " - Found tag date: $date_val"
86+ else
87+ echo " - Git Tag object for '$tag' not found."
88+ fi
89+ else
90+ echo " - Found release date: $date_val"
91+ fi
92+
93+ # Return the found date (which might still be empty)
94+ echo "$date_val"
95+ }
96+
6097 get_gh_publish_date() {
61- local repo_slug="$1" # e.g., infinilabs/coco-app
62- local full_ver_from_latest="$2" # e.g., 0.5.3-2323 (this is the version string from .latest)
98+ local repo_slug="$1"
99+ local full_ver_from_latest="$2"
63100 local date_val
64101
65- # Extract X.Y.Z part from the full version string
66- local xyz_part=$(echo "$full_ver_from_latest" | cut -d'-' -f1) # e.g., 0.5.3
102+ # Extract X.Y.Z part from the full version string (e.g., "0.5.3-2323" -> "0.5.3")
103+ local xyz_part=$(echo "$full_ver_from_latest" | cut -d'-' -f1)
67104
68- # Construct the X.Y.0 part
69- local xy_part=$(echo "$xyz_part" | cut -d'.' -f1,2) # e.g., 0.5
70- local xyz_zero_patch_part="${xy_part}.0" # e.g., 0.5.0
105+ # Construct the X.Y.0 part for fallback (e.g., "0.5.3" -> "0.5.0")
106+ local xy_part=$(echo "$xyz_part" | cut -d'.' -f1,2)
107+ local xyz_zero_patch_part="${xy_part}.0"
71108
72- local tag_attempt1="v${xyz_part}" # Primary attempt, e.g., v0.5.3
109+ local tag_attempt1="v${xyz_part}" # Primary attempt, e.g., v0.5.3
73110 local tag_attempt2="v${xyz_zero_patch_part}" # Fallback, e.g., v0.5.0
74111
75- sleep 10
76- # Attempt 1: X.Y.Z version tag (e.g., v0.5.3)
77- date_val=$(curl -m60 -s "https://api.github.com/repos/${repo_slug}/releases/tags/${tag_attempt1}" | \
78- jq -r '.created_at | split("T")[0 // empty]' 2>/dev/null )
79- sleep 10
80- # Attempt 2: X.Y.0 version tag (e.g., v0.5 .0)
112+ echo "Searching for publish date for version ${full_ver_from_latest} in ${repo_slug}..."
113+
114+ # Try primary tag (vX.Y.Z) first
115+ date_val=$(get_date_for_tag "$repo_slug" "$tag_attempt1" )
116+
117+ # If not found, try fallback tag (vX.Y .0)
81118 if [[ -z "$date_val" || "$date_val" == "null" ]]; then
82- date_val=$(curl -m60 -s "https://api.github.com/repos/${repo_slug}/releases/tags/${tag_attempt2}" | \
83- jq -r '.created_at | split("T")[0 // empty]' 2>/dev/null )
119+ echo " - Primary tag date not found. Trying fallback..."
120+ date_val=$(get_date_for_tag "$repo_slug" "$tag_attempt2" )
84121 fi
85122
86- # Final fallback to current date
123+ # Final fallback to current date if all else fails
87124 if [[ -z "$date_val" || "$date_val" == "null" ]]; then
125+ echo " - No release or tag date found. Using current date as a fallback."
88126 date_val=$(date +%Y-%m-%d)
89127 fi
90128 echo "$date_val"
0 commit comments