fix: installs field may be empty. (#81) #116
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Deploy Web site to Pages | |
| on: | |
| # Runs on pushes targeting the default branch | |
| push: | |
| branches: ["main"] | |
| tags: | |
| - "v*" | |
| # Allows you to run this workflow manually from the Actions tab | |
| workflow_dispatch: | |
| # Sets permissions of the GITHUB_TOKEN to allow deployment to GitHub Pages | |
| permissions: | |
| contents: read | |
| pages: write | |
| id-token: write | |
| # Allow only one concurrent deployment, skipping runs queued between the run in-progress and latest queued. | |
| # However, do NOT cancel in-progress runs as we want to allow these production deployments to complete. | |
| concurrency: | |
| group: "pages" | |
| cancel-in-progress: false | |
| jobs: | |
| # Build job | |
| build: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout | |
| uses: actions/checkout@v4 | |
| - uses: pnpm/action-setup@v4 | |
| with: | |
| package_json_file: "package.json" | |
| - name: Setup Node | |
| uses: actions/setup-node@v4 | |
| with: | |
| node-version: "20" | |
| cache: "pnpm" | |
| - name: Update data.json with latest versions and publish dates | |
| env: | |
| GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| run: | | |
| set -e | |
| # Define a logging function that prints to stderr | |
| log() { | |
| echo "$@" >&2 | |
| } | |
| DATA_JSON_PATH="public/data.json" | |
| log "Fetching latest version info..." | |
| VERSION_INFO=$(curl -s --fail --max-time 10 https://release.infinilabs.com/.latest) | |
| APP_FULL_VERSION=$(echo "$VERSION_INFO" | jq -r '.["coco-app"]') | |
| SERVER_FULL_VERSION=$(echo "$VERSION_INFO" | jq -r '.["coco-server"]') | |
| log "App Version: $APP_FULL_VERSION, Server Version: $SERVER_FULL_VERSION" | |
| # Function to get the publish date for a given tag. | |
| get_date_for_tag() { | |
| local repo_slug="$1" | |
| local tag="$2" | |
| local date_val="" | |
| log " - Checking release for tag: $tag" | |
| # Attempt 1: Get date from the GitHub Release | |
| date_val=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \ | |
| "https://api.github.com/repos/${repo_slug}/releases/tags/${tag}" | \ | |
| jq -r '.created_at | split("T")[0]' 2>/dev/null) | |
| # Attempt 2: If release not found, get date from the Git Tag object | |
| if [[ -z "$date_val" || "$date_val" == "null" ]]; then | |
| log " - Release for tag '$tag' not found. Checking Git Tag object..." | |
| TAG_SHA=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \ | |
| "https://api.github.com/repos/${repo_slug}/git/refs/tags/${tag}" | \ | |
| jq -r '.object.sha' 2>/dev/null) | |
| if [[ -n "$TAG_SHA" && "$TAG_SHA" != "null" ]]; then | |
| date_val=$(curl -m60 -s -H "Authorization: Bearer $GH_TOKEN" \ | |
| "https://api.github.com/repos/${repo_slug}/git/tags/${TAG_SHA}" | \ | |
| jq -r '.tagger.date | split("T")[0]' 2>/dev/null) | |
| log " - Found tag date: $date_val" | |
| else | |
| log " - Git Tag object for '$tag' not found." | |
| fi | |
| else | |
| log " - Found release date: $date_val" | |
| fi | |
| # This echo to stdout is the function's return value | |
| echo "$date_val" | |
| } | |
| get_gh_publish_date() { | |
| local repo_slug="$1" | |
| local full_ver_from_latest="$2" | |
| local date_val | |
| local xyz_part=$(echo "$full_ver_from_latest" | cut -d'-' -f1) | |
| local xy_part=$(echo "$xyz_part" | cut -d'.' -f1,2) | |
| local xyz_zero_patch_part="${xy_part}.0" | |
| local tag_attempt1="v${xyz_part}" | |
| local tag_attempt2="v${xyz_zero_patch_part}" | |
| log "Searching for publish date for version ${full_ver_from_latest} in ${repo_slug}..." | |
| date_val=$(get_date_for_tag "$repo_slug" "$tag_attempt1") | |
| if [[ -z "$date_val" || "$date_val" == "null" ]]; then | |
| log " - Primary tag date not found. Trying fallback..." | |
| date_val=$(get_date_for_tag "$repo_slug" "$tag_attempt2") | |
| fi | |
| if [[ -z "$date_val" || "$date_val" == "null" ]]; then | |
| log " - No release or tag date found. Using current date as a fallback." | |
| date_val=$(date +%Y-%m-%d) | |
| fi | |
| # This echo to stdout is the function's return value | |
| echo "$date_val" | |
| } | |
| APP_PUBLISH_DATE=$(get_gh_publish_date "infinilabs/coco-app" "$APP_FULL_VERSION") | |
| SERVER_PUBLISH_DATE=$(get_gh_publish_date "infinilabs/coco-server" "$SERVER_FULL_VERSION") | |
| echo "App Publish Date: $APP_PUBLISH_DATE" | |
| echo "Server Publish Date: $SERVER_PUBLISH_DATE" | |
| jq \ | |
| --arg app_ver "$APP_FULL_VERSION" \ | |
| --arg server_ver "$SERVER_FULL_VERSION" \ | |
| --arg app_date "$APP_PUBLISH_DATE" \ | |
| --arg server_date "$SERVER_PUBLISH_DATE" \ | |
| '.app = $app_ver | .server = $server_ver | .app_publish = $app_date | .server_publish = $server_date' \ | |
| "$DATA_JSON_PATH" > tmp_data.json && mv tmp_data.json "$DATA_JSON_PATH" | |
| echo "Updated $DATA_JSON_PATH" | |
| echo | |
| cat "$DATA_JSON_PATH" | |
| - name: Setup Pages | |
| uses: actions/configure-pages@v5 | |
| with: | |
| static_site_generator: next | |
| - name: Restore cache | |
| uses: actions/cache@v4 | |
| with: | |
| path: | | |
| .next/cache | |
| key: ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }}-${{ hashFiles('**.[jt]s', '**.[jt]sx', '**/data.json') }} | |
| restore-keys: | | |
| ${{ runner.os }}-nextjs-${{ hashFiles('**/package-lock.json', '**/yarn.lock', '**/pnpm-lock.yaml') }} | |
| - name: Install dependencies | |
| run: pnpm install --registry=https://registry.npmjs.org --quiet | |
| - name: Build with Web | |
| env: | |
| NODE_ENV: production | |
| run: pnpm build | |
| - name: Add CNAME file | |
| run: echo "coco.rs" > ./docs/CNAME | |
| - name: Disable Jekyll | |
| run: touch docs/.nojekyll | |
| - name: Upload artifact | |
| uses: actions/upload-pages-artifact@v3 | |
| with: | |
| path: ./docs | |
| # Deployment job | |
| deploy: | |
| environment: | |
| name: github-pages | |
| url: ${{ steps.deployment.outputs.page_url }} | |
| runs-on: ubuntu-latest | |
| needs: build | |
| steps: | |
| - name: Deploy to GitHub Pages | |
| id: deployment | |
| uses: actions/deploy-pages@v4 |