Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add update checker #5613

Draft
wants to merge 13 commits into
base: main
Choose a base branch
from

Conversation

mildm8nnered
Copy link
Collaborator

@mildm8nnered mildm8nnered commented May 29, 2024

Adds an update check facility to SwiftLint - addresses #5551

This has been added as a --check-for-updates command line option to the version, lint, and analyze commands.

It can also be enabled via the configuration file, as check_for_updates.

Although the usefulness of an opt-in option is limited, at least this provides a good story for how users can keep their installs up to date. And it could easily be changed to opt-out either here or at some later date.

The update checker code is pretty closely based on Periphery's implementation, and should probably be credited in the source file.

The update check is performed after all other processing, so linting will never be delayed, and the code is completely synchronous, as we do not have to worry about blocking the main thread.

The messaging for a new version is: A new version of SwiftLint is available: 0.51.1

We currently do not print any messaging if the update check fails, which is probably wrong.

% swiftlint help version
OVERVIEW: Display the current version of SwiftLint

USAGE: swiftlint version [--verbose] [--check-for-updates]

OPTIONS:
  --check-for-updates     Check whether a later version of SwiftLint is available.

%
% ./swiftlint version --check-for-updates
0.55.1
Your version of SwiftLint is up to date
%
%
% swiftlint help lint
OVERVIEW: Print lint warnings and errors

USAGE: swiftlint lint [<options>] [<paths> ...]

ARGUMENTS:
  <paths>                 List of paths to the files or directories to lint.

OPTIONS:
  --check-for-updates     Check whether a later version of SwiftLint is available.

@mildm8nnered mildm8nnered changed the title Mildm8nnered check for updates Add update checker Jun 14, 2024
Source/SwiftLintCore/Models/Configuration.swift Outdated Show resolved Hide resolved
Source/SwiftLintCore/Models/Version.swift Outdated Show resolved Hide resolved
Source/swiftlint/Helpers/LintOrAnalyzeArguments.swift Outdated Show resolved Hide resolved
var request = URLRequest(url: url)
request.setValue("SwiftLint", forHTTPHeaderField: "User-Agent")
request.setValue("application/vnd.github.v3+json", forHTTPHeaderField: "Accept")
let semaphore = DispatchSemaphore(value: 0)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we go with some Swift Concurrency magic here instead? I assume the whole method chain can be async.

let minor = components.dropFirst(1).first ?? 0
let patch = components.dropFirst(2).first ?? 0
return [major, minor, patch]
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is a similar (or equal) implementation for SwiftVersion. Can we somehow reduce them to just one? Something like VersionComparable with a default implementation that only relies on the underlying version string.

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-check-for-updates branch from 5017b0f to 735f371 Compare June 24, 2024 08:44
@SwiftLintBot
Copy link

SwiftLintBot commented Jun 24, 2024

1 Error
🚫 Could not build branch
1 Warning
⚠️ If this is a user-facing change, please include a CHANGELOG entry to credit yourself!
You can find it at CHANGELOG.md.

Here's an example of your CHANGELOG entry:

* Add update checker.  
  [mildm8nnered](https://github.com/mildm8nnered)
  [#issue_number](https://github.com/realm/SwiftLint/issues/issue_number)

note: There are two invisible spaces after the entry's text.

Generated by 🚫 Danger

@mildm8nnered mildm8nnered force-pushed the mildm8nnered-check-for-updates branch 4 times, most recently from 16ea749 to e7bc567 Compare June 28, 2024 08:34
@mildm8nnered mildm8nnered force-pushed the mildm8nnered-check-for-updates branch from 6899365 to a86b335 Compare June 29, 2024 15:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants