Skip to content

Commit

Permalink
rebuild js
Browse files Browse the repository at this point in the history
  • Loading branch information
Kudo committed Sep 18, 2023
1 parent b25c6b8 commit 700c651
Show file tree
Hide file tree
Showing 6 changed files with 181 additions and 10 deletions.
22 changes: 22 additions & 0 deletions build/command/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20526,6 +20526,9 @@ async function easBuild(cmd) {
}
return JSON.parse(stdout);
}
/**
* Create an new EAS build using the user-provided command.
*/
async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
let stdout = '';
let cmd = command;
Expand All @@ -20548,6 +20551,9 @@ async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
}
return JSON.parse(stdout);
}
/**
* Cancel an EAS build.
*/
async function cancelEasBuildAsync(cwd, buildId) {
try {
await getExecOutput(await which('eas', true), ['build:cancel', buildId], { cwd });
Expand All @@ -20556,6 +20562,22 @@ async function cancelEasBuildAsync(cwd, buildId) {
info(`Failed to cancel build ${buildId}: ${errorMessage(e)}`);
}
}
/**
* Query the EAS BuildInfo from given buildId.
*/
async function queryEasBuildInfoAsync(cwd, buildId) {
try {
const { stdout } = await getExecOutput(await which('eas', true), ['build:view', buildId, '--json'], {
cwd,
silent: true,
});
return JSON.parse(stdout);
}
catch (e) {
info(`Failed to query eas build ${buildId}: ${errorMessage(e)}`);
}
return null;
}
/**
* Try to resolve the project info, by running 'expo config --type prebuild'.
*/
Expand Down
33 changes: 29 additions & 4 deletions build/fingerprint-post/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75829,6 +75829,9 @@ class FingerprintDbManager_FingerprintDbManager {
for (const index of FingerprintDbManager_FingerprintDbManager.INDEXES) {
await db.runAsync(index);
}
for (const extraStatement of FingerprintDbManager_FingerprintDbManager.EXTRA_CREATE_DB_STATEMENTS) {
await db.runAsync(extraStatement);
}
await db.runAsync(`PRAGMA fingerprint_schema_version = ${FingerprintDbManager_FingerprintDbManager.SCHEMA_VERSION}`);
this.db = db;
return db;
Expand All @@ -75849,6 +75852,18 @@ class FingerprintDbManager_FingerprintDbManager {
const rows = await this.db.allAsync(`SELECT eas_build_id FROM ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash);
return rows.map(row => row['eas_build_id']);
}
/**
* Get the latest entity from the fingerprint hash where the eas_build_id is not null.
*/
async getLatestEasEntityFromFingerprintAsync(fingerprintHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
}
const row = await this.db.getAsync(`SELECT * FROM ${FingerprintDbManager_FingerprintDbManager.TABLE_NAME}
WHERE eas_build_id IS NOT NULL AND eas_build_id != "" AND fingerprint_hash = ?
ORDER BY updated_at DESC LIMIT 1`, fingerprintHash);
return row ? FingerprintDbManager_FingerprintDbManager.serialize(row) : null;
}
async getEntityFromGitCommitHashAsync(gitCommitHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
Expand Down Expand Up @@ -75893,11 +75908,19 @@ class FingerprintDbManager_FingerprintDbManager {
'git_commit_hash TEXT NOT NULL',
'fingerprint_hash TEXT NOT NULL',
'fingerprint TEXT NOT NULL',
"created_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
"updated_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
]));
static INDEXES = (/* unused pure expression or super */ null && ([
'CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON fingerprint (git_commit_hash)',
'CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON fingerprint (fingerprint_hash)',
]));
static INDEXES = [
`CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON ${this.TABLE_NAME} (git_commit_hash)`,
`CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON ${this.TABLE_NAME} (fingerprint_hash)`,
];
static EXTRA_CREATE_DB_STATEMENTS = [
`CREATE TRIGGER IF NOT EXISTS update_fingerprint_updated_at AFTER UPDATE ON ${this.TABLE_NAME}
BEGIN
UPDATE ${this.TABLE_NAME} SET updated_at = DATETIME('now', 'utc') WHERE id = NEW.id;
END`,
];
db = null;
static serialize(rawEntity) {
return {
Expand All @@ -75906,6 +75929,8 @@ class FingerprintDbManager_FingerprintDbManager {
gitCommitHash: rawEntity.git_commit_hash,
fingerprintHash: rawEntity.fingerprint_hash,
fingerprint: JSON.parse(rawEntity.fingerprint),
createdAt: rawEntity.created_at,
updatedAt: rawEntity.updated_at,
};
}
}
Expand Down
29 changes: 27 additions & 2 deletions build/fingerprint/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75852,6 +75852,9 @@ class FingerprintDbManager {
for (const index of FingerprintDbManager.INDEXES) {
await db.runAsync(index);
}
for (const extraStatement of FingerprintDbManager.EXTRA_CREATE_DB_STATEMENTS) {
await db.runAsync(extraStatement);
}
await db.runAsync(`PRAGMA fingerprint_schema_version = ${FingerprintDbManager.SCHEMA_VERSION}`);
this.db = db;
return db;
Expand All @@ -75872,6 +75875,18 @@ class FingerprintDbManager {
const rows = await this.db.allAsync(`SELECT eas_build_id FROM ${FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash);
return rows.map(row => row['eas_build_id']);
}
/**
* Get the latest entity from the fingerprint hash where the eas_build_id is not null.
*/
async getLatestEasEntityFromFingerprintAsync(fingerprintHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
}
const row = await this.db.getAsync(`SELECT * FROM ${FingerprintDbManager.TABLE_NAME}
WHERE eas_build_id IS NOT NULL AND eas_build_id != "" AND fingerprint_hash = ?
ORDER BY updated_at DESC LIMIT 1`, fingerprintHash);
return row ? FingerprintDbManager.serialize(row) : null;
}
async getEntityFromGitCommitHashAsync(gitCommitHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
Expand Down Expand Up @@ -75916,10 +75931,18 @@ class FingerprintDbManager {
'git_commit_hash TEXT NOT NULL',
'fingerprint_hash TEXT NOT NULL',
'fingerprint TEXT NOT NULL',
"created_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
"updated_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
];
static INDEXES = [
'CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON fingerprint (git_commit_hash)',
'CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON fingerprint (fingerprint_hash)',
`CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON ${this.TABLE_NAME} (git_commit_hash)`,
`CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON ${this.TABLE_NAME} (fingerprint_hash)`,
];
static EXTRA_CREATE_DB_STATEMENTS = [
`CREATE TRIGGER IF NOT EXISTS update_fingerprint_updated_at AFTER UPDATE ON ${this.TABLE_NAME}
BEGIN
UPDATE ${this.TABLE_NAME} SET updated_at = DATETIME('now', 'utc') WHERE id = NEW.id;
END`,
];
db = null;
static serialize(rawEntity) {
Expand All @@ -75929,6 +75952,8 @@ class FingerprintDbManager {
gitCommitHash: rawEntity.git_commit_hash,
fingerprintHash: rawEntity.fingerprint_hash,
fingerprint: JSON.parse(rawEntity.fingerprint),
createdAt: rawEntity.created_at,
updatedAt: rawEntity.updated_at,
};
}
}
Expand Down
63 changes: 59 additions & 4 deletions build/preview-build/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75851,6 +75851,9 @@ async function easBuild(cmd) {
}
return JSON.parse(stdout);
}
/**
* Create an new EAS build using the user-provided command.
*/
async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
let stdout = '';
let cmd = command;
Expand All @@ -75873,6 +75876,9 @@ async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
}
return JSON.parse(stdout);
}
/**
* Cancel an EAS build.
*/
async function cancelEasBuildAsync(cwd, buildId) {
try {
await (0,lib_exec.getExecOutput)(await (0,io.which)('eas', true), ['build:cancel', buildId], { cwd });
Expand All @@ -75881,6 +75887,22 @@ async function cancelEasBuildAsync(cwd, buildId) {
(0,core.info)(`Failed to cancel build ${buildId}: ${utils_errorMessage(e)}`);
}
}
/**
* Query the EAS BuildInfo from given buildId.
*/
async function queryEasBuildInfoAsync(cwd, buildId) {
try {
const { stdout } = await (0,lib_exec.getExecOutput)(await (0,io.which)('eas', true), ['build:view', buildId, '--json'], {
cwd,
silent: true,
});
return JSON.parse(stdout);
}
catch (e) {
(0,core.info)(`Failed to query eas build ${buildId}: ${utils_errorMessage(e)}`);
}
return null;
}
/**
* Try to resolve the project info, by running 'expo config --type prebuild'.
*/
Expand Down Expand Up @@ -76060,6 +76082,9 @@ class FingerprintDbManager {
for (const index of FingerprintDbManager.INDEXES) {
await db.runAsync(index);
}
for (const extraStatement of FingerprintDbManager.EXTRA_CREATE_DB_STATEMENTS) {
await db.runAsync(extraStatement);
}
await db.runAsync(`PRAGMA fingerprint_schema_version = ${FingerprintDbManager.SCHEMA_VERSION}`);
this.db = db;
return db;
Expand All @@ -76080,6 +76105,18 @@ class FingerprintDbManager {
const rows = await this.db.allAsync(`SELECT eas_build_id FROM ${FingerprintDbManager.TABLE_NAME} WHERE fingerprint_hash = ?`, fingerprintHash);
return rows.map(row => row['eas_build_id']);
}
/**
* Get the latest entity from the fingerprint hash where the eas_build_id is not null.
*/
async getLatestEasEntityFromFingerprintAsync(fingerprintHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
}
const row = await this.db.getAsync(`SELECT * FROM ${FingerprintDbManager.TABLE_NAME}
WHERE eas_build_id IS NOT NULL AND eas_build_id != "" AND fingerprint_hash = ?
ORDER BY updated_at DESC LIMIT 1`, fingerprintHash);
return row ? FingerprintDbManager.serialize(row) : null;
}
async getEntityFromGitCommitHashAsync(gitCommitHash) {
if (!this.db) {
throw new Error('Database not initialized. Call initAsync() first.');
Expand Down Expand Up @@ -76124,10 +76161,18 @@ class FingerprintDbManager {
'git_commit_hash TEXT NOT NULL',
'fingerprint_hash TEXT NOT NULL',
'fingerprint TEXT NOT NULL',
"created_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
"updated_at TEXT NOT NULL DEFAULT (DATETIME('now', 'utc'))",
];
static INDEXES = [
'CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON fingerprint (git_commit_hash)',
'CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON fingerprint (fingerprint_hash)',
`CREATE UNIQUE INDEX IF NOT EXISTS idx_git_commit_hash ON ${this.TABLE_NAME} (git_commit_hash)`,
`CREATE INDEX IF NOT EXISTS idx_fingerprint_hash ON ${this.TABLE_NAME} (fingerprint_hash)`,
];
static EXTRA_CREATE_DB_STATEMENTS = [
`CREATE TRIGGER IF NOT EXISTS update_fingerprint_updated_at AFTER UPDATE ON ${this.TABLE_NAME}
BEGIN
UPDATE ${this.TABLE_NAME} SET updated_at = DATETIME('now', 'utc') WHERE id = NEW.id;
END`,
];
db = null;
static serialize(rawEntity) {
Expand All @@ -76137,6 +76182,8 @@ class FingerprintDbManager {
gitCommitHash: rawEntity.git_commit_hash,
fingerprintHash: rawEntity.fingerprint_hash,
fingerprint: JSON.parse(rawEntity.fingerprint),
createdAt: rawEntity.created_at,
updatedAt: rawEntity.updated_at,
};
}
}
Expand Down Expand Up @@ -76330,7 +76377,11 @@ async function previewAction(input = collectPreviewBuildActionInput()) {
await maybeCancelPreviousBuildsAsync(config, input);
const variables = getVariables(config, []);
const messageId = template(input.commentId, variables);
const messageBody = createMessageBodyFingerprintCompatible();
const latestEasEntity = await dbManager.getLatestEasEntityFromFingerprintAsync(currentFingerprint.hash);
const latestEasBuildInfo = latestEasEntity?.easBuildId
? await queryEasBuildInfoAsync(input.workingDirectory, latestEasEntity.easBuildId)
: null;
const messageBody = createMessageBodyFingerprintCompatible(latestEasBuildInfo);
await maybeCreateCommentAsync(input, messageId, messageBody);
setOutputs(variables, messageId, messageBody);
return;
Expand Down Expand Up @@ -76481,9 +76532,13 @@ function createMessageBodyInBuilding(builds, fingerprintDiff, input) {
`> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview-build#example-workflows)`,
].join('\n');
}
function createMessageBodyFingerprintCompatible() {
function createMessageBodyFingerprintCompatible(latestEasBuildInfo) {
const easBuildMessage = latestEasBuildInfo != null
? `Latest compatible build on EAS found. You can download the build from the [EAS build page](${getBuildLogsUrl(latestEasBuildInfo)}).`
: '';
return [
`Fingerprint is compatible, no new builds are required.`,
easBuildMessage,
'',
`> Learn more about [𝝠 Expo Github Action](https://github.com/expo/expo-github-action/tree/main/preview-build#example-workflows)`,
].join('\n');
Expand Down
22 changes: 22 additions & 0 deletions build/preview-comment/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -20527,6 +20527,9 @@ async function easBuild(cmd) {
}
return JSON.parse(stdout);
}
/**
* Create an new EAS build using the user-provided command.
*/
async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
let stdout = '';
let cmd = command;
Expand All @@ -20549,6 +20552,9 @@ async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
}
return JSON.parse(stdout);
}
/**
* Cancel an EAS build.
*/
async function cancelEasBuildAsync(cwd, buildId) {
try {
await getExecOutput(await which('eas', true), ['build:cancel', buildId], { cwd });
Expand All @@ -20557,6 +20563,22 @@ async function cancelEasBuildAsync(cwd, buildId) {
info(`Failed to cancel build ${buildId}: ${errorMessage(e)}`);
}
}
/**
* Query the EAS BuildInfo from given buildId.
*/
async function queryEasBuildInfoAsync(cwd, buildId) {
try {
const { stdout } = await getExecOutput(await which('eas', true), ['build:view', buildId, '--json'], {
cwd,
silent: true,
});
return JSON.parse(stdout);
}
catch (e) {
info(`Failed to query eas build ${buildId}: ${errorMessage(e)}`);
}
return null;
}
/**
* Try to resolve the project info, by running 'expo config --type prebuild'.
*/
Expand Down
22 changes: 22 additions & 0 deletions build/setup/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -75810,6 +75810,9 @@ async function easBuild(cmd) {
}
return JSON.parse(stdout);
}
/**
* Create an new EAS build using the user-provided command.
*/
async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
let stdout = '';
let cmd = command;
Expand All @@ -75832,6 +75835,9 @@ async function createEasBuildFromRawCommandAsync(cwd, command, extraArgs = []) {
}
return JSON.parse(stdout);
}
/**
* Cancel an EAS build.
*/
async function cancelEasBuildAsync(cwd, buildId) {
try {
await getExecOutput(await which('eas', true), ['build:cancel', buildId], { cwd });
Expand All @@ -75840,6 +75846,22 @@ async function cancelEasBuildAsync(cwd, buildId) {
info(`Failed to cancel build ${buildId}: ${errorMessage(e)}`);
}
}
/**
* Query the EAS BuildInfo from given buildId.
*/
async function queryEasBuildInfoAsync(cwd, buildId) {
try {
const { stdout } = await getExecOutput(await which('eas', true), ['build:view', buildId, '--json'], {
cwd,
silent: true,
});
return JSON.parse(stdout);
}
catch (e) {
info(`Failed to query eas build ${buildId}: ${errorMessage(e)}`);
}
return null;
}
/**
* Try to resolve the project info, by running 'expo config --type prebuild'.
*/
Expand Down

0 comments on commit 700c651

Please sign in to comment.