diff --git a/.github/workflows/update-cursor.yml b/.github/workflows/update-cursor.yml index 91b13d2..47c4ddb 100644 --- a/.github/workflows/update-cursor.yml +++ b/.github/workflows/update-cursor.yml @@ -12,9 +12,11 @@ concurrency: jobs: update-cursor: runs-on: ubuntu-latest + env: + CI: true permissions: contents: write - + steps: - name: Checkout repository uses: actions/checkout@v4 @@ -65,9 +67,13 @@ jobs: # Create commit message based on version info if [[ "$VERSION_INFO" == completed:* ]]; then - # Extract version from format: completed:old_version:new_version + OLD_VERSION=$(echo "$VERSION_INFO" | cut -d: -f2) NEW_VERSION=$(echo "$VERSION_INFO" | cut -d: -f3) - COMMIT_MSG="Update Cursor to version $NEW_VERSION" + if [[ "$OLD_VERSION" == "$NEW_VERSION" ]]; then + COMMIT_MSG="Refresh Cursor $NEW_VERSION AppImage hashes" + else + COMMIT_MSG="Update Cursor to version $NEW_VERSION" + fi else COMMIT_MSG="Update Cursor to latest version" fi diff --git a/update-cursor.sh b/update-cursor.sh index 9b892c5..ebaf0fc 100755 --- a/update-cursor.sh +++ b/update-cursor.sh @@ -111,6 +111,17 @@ is_pointer() { [[ "${1:-}" == "latest" || "${1:-}" =~ ^[0-9]+\.[0-9]+$ ]] } +is_ci() { + [[ -n "${CI:-}" || -n "${GITHUB_ACTIONS:-}" || -n "${GITEA_ACTIONS:-}" ]] +} + +write_version_output() { + local value="$1" + if [[ -n "${GITHUB_OUTPUT:-}" ]]; then + echo "CURSOR_VERSION_INFO=$value" >> "$GITHUB_OUTPUT" + fi +} + # Function to get current version from flake.nix managed block get_current_version() { awk -v begin="$MANAGED_BEGIN" -v end="$MANAGED_END" ' @@ -296,33 +307,43 @@ main() { echo "Resolved: latest=$v_latest pointer($current_track)=$v_current_track pointer($latest_track)=$v_latest_track -> chosen=$target_version" fi - # Check if update is needed + # Same semver but Cursor may republish the AppImage (hash/url drift). In CI, always re-prefetch. if [[ "$target_version" == "$current_version" ]]; then - echo "No update needed. Current version is up to date." - if [[ -n "${GITHUB_OUTPUT:-}" ]]; then - echo "CURSOR_VERSION_INFO=no_update" >> "$GITHUB_OUTPUT" + if is_ci; then + echo "Version unchanged ($current_version); re-prefetching URLs and hashes for upstream drift..." + update_release "$target_version" + rm -f "$FLAKE_FILE.backup" + if git diff --quiet -- "$FLAKE_FILE" 2>/dev/null; then + echo "Hashes and URLs already match upstream." + write_version_output "no_update" + exit 0 + fi + test_flake + echo "Refreshed hashes for Cursor $target_version" + write_version_output "completed:$current_version:$target_version" + exit 0 fi + echo "No update needed. Current version is up to date." + write_version_output "no_update" exit 0 fi - + echo "Update needed: $current_version -> $target_version" - - # Check if running in CI/GitHub Actions (auto-confirm) - if [[ -n "${CI:-}" ]] || [[ -n "${GITHUB_ACTIONS:-}" ]]; then + + if is_ci; then echo "Running in CI mode, auto-confirming update..." REPLY="y" else read -p "Do you want to proceed with the update? (y/N): " -n 1 -r echo fi - + if [[ $REPLY =~ ^[Yy]$ ]]; then update_release "$target_version" + rm -f "$FLAKE_FILE.backup" test_flake echo "Update completed successfully!" - if [[ -n "${GITHUB_OUTPUT:-}" ]]; then - echo "CURSOR_VERSION_INFO=completed:$current_version:$target_version" >> "$GITHUB_OUTPUT" - fi + write_version_output "completed:$current_version:$target_version" echo "You can now commit the changes:" echo " git add flake.nix" echo " git commit -m \"Update Cursor to version $target_version\""