-
Notifications
You must be signed in to change notification settings - Fork 86
feat: Automatic sqlite-database-integration upgrade #136
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
Merged
Merged
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
2e25c86
feat: Download latest sqlite-databse-integration release tag
dcalhoun 3b20384
feat: Starting the app updates sqlite-database-integration installation
dcalhoun 847e40a
feat: Starting a site updates an outdated sqlite-integration-plugin
dcalhoun 8afbeb0
fix: Avoid unnecessary sqlite-database-integration upgrades
dcalhoun f0aa6f2
feat: Cache sqlite-database-integration versions for app session
dcalhoun b0861b3
refactor: Remove unused import
dcalhoun a73fe82
refactor: Remove unused references to specific past release versions
dcalhoun f1d2dae
refactor: Remove `-main` branch suffix from SQLite install
dcalhoun File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
feat: Starting the app updates sqlite-database-integration installation
Ensure new sites receive the latest sqlite-database-integration fixes and improvements.
- Loading branch information
commit 3b203847094de9d7b0008561d6c03e2c0824aa25
There are no files selected for viewing
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,52 @@ | ||
| import path from 'path'; | ||
| import fs from 'fs-extra'; | ||
| import semver from 'semver'; | ||
| import { downloadSqliteIntegrationPlugin } from '../../vendor/wp-now/src/download'; | ||
| import getSqlitePath from '../../vendor/wp-now/src/get-sqlite-path'; | ||
|
|
||
| export async function updateLatestSqliteVersion() { | ||
| let shouldOverwrite = false; | ||
| const installedPath = getSqlitePath(); | ||
| const installedFiles = ( await fs.pathExists( installedPath ) ) | ||
| ? await fs.readdir( installedPath ) | ||
| : []; | ||
| const latestVersion = await getLatestSqliteVersion(); | ||
| if ( installedFiles.length !== 0 ) { | ||
| const installedVersion = getSqliteVersionFromInstallation( installedPath ); | ||
| shouldOverwrite = !! installedVersion && !! latestVersion && installedVersion !== latestVersion; | ||
| } | ||
|
|
||
| await downloadSqliteIntegrationPlugin( latestVersion, { overwrite: shouldOverwrite } ); | ||
| } | ||
|
|
||
| function getSqliteVersionFromInstallation( installationPath: string ): string { | ||
| let versionFileContent = ''; | ||
| try { | ||
| versionFileContent = fs.readFileSync( path.join( installationPath, 'load.php' ), 'utf8' ); | ||
| } catch ( err ) { | ||
| return ''; | ||
| } | ||
| const matches = versionFileContent.match( /\s\*\sVersion:\s*([0-9a-zA-Z.-]+)/ ); | ||
| return matches?.[ 1 ] || ''; | ||
| } | ||
|
|
||
| async function getLatestSqliteVersion() { | ||
| const sqliteVersions = await fetchSqliteVersions(); | ||
| return sqliteVersions.latest; | ||
| } | ||
|
|
||
| async function fetchSqliteVersions() { | ||
| try { | ||
| const response = await fetch( | ||
| 'https://api.github.com/repos/WordPress/sqlite-database-integration/releases' | ||
|
dcalhoun marked this conversation as resolved.
Outdated
|
||
| ); | ||
| const data: Record< string, string >[] = await response.json(); | ||
| const versions = data.map( ( release ) => semver.coerce( release.tag_name ) ); | ||
| return { | ||
| versions, | ||
| latest: versions[ 0 ]?.version || '', | ||
| }; | ||
| } catch ( _error ) { | ||
| return { versions: [], latest: '' }; | ||
| } | ||
| } | ||
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
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general, we try to avoid using the sync version of FS functions to prevent blocking the main thread. I wonder if we could use the asynchronous one.