diff --git a/.gitmodules b/.gitmodules index 0b9b9e98f..5745c65df 100644 --- a/.gitmodules +++ b/.gitmodules @@ -43,8 +43,8 @@ # branch = docs [submodule "docs/latest/builds/sway"] path = docs/latest/builds/sway - # branch = gh-pages url = https://github.com/FuelLabs/sway.git + # branch = gh-pages [submodule "docs/latest/fuels-wallet"] path = docs/latest/fuels-wallet url = https://github.com/FuelLabs/fuels-wallet.git diff --git a/docs/builds/sway b/docs/builds/sway index c1d862068..a65eae487 160000 --- a/docs/builds/sway +++ b/docs/builds/sway @@ -1 +1 @@ -Subproject commit c1d862068009340aeaf59d75e8966f9538182f22 +Subproject commit a65eae487081414812ead7017ce9c8b47ff37be4 diff --git a/docs/fuel-indexer b/docs/fuel-indexer index 011b68256..6a3f138b1 160000 --- a/docs/fuel-indexer +++ b/docs/fuel-indexer @@ -1 +1 @@ -Subproject commit 011b68256f3be47dffdb020640f772cd3961d4da +Subproject commit 6a3f138b149257306acf3cb37e68fd8c67cf4ea7 diff --git a/docs/latest/builds/sway b/docs/latest/builds/sway index e75f14b03..a65eae487 160000 --- a/docs/latest/builds/sway +++ b/docs/latest/builds/sway @@ -1 +1 @@ -Subproject commit e75f14b03636bc96751a6760304a1a6d3eb5937d +Subproject commit a65eae487081414812ead7017ce9c8b47ff37be4 diff --git a/docs/latest/fuel-indexer b/docs/latest/fuel-indexer index 7d73a3238..6a3f138b1 160000 --- a/docs/latest/fuel-indexer +++ b/docs/latest/fuel-indexer @@ -1 +1 @@ -Subproject commit 7d73a323871423b018e8e452a951a81f09184ecd +Subproject commit 6a3f138b149257306acf3cb37e68fd8c67cf4ea7 diff --git a/docs/latest/fuel-specs b/docs/latest/fuel-specs index 4a841c59d..1b3b772a8 160000 --- a/docs/latest/fuel-specs +++ b/docs/latest/fuel-specs @@ -1 +1 @@ -Subproject commit 4a841c59dc39d75a1a8e37ecc7ea3c9a54301bc8 +Subproject commit 1b3b772a824c276c686434f39bbdb0e8e91edaed diff --git a/docs/latest/sway b/docs/latest/sway index e75f14b03..512a3386f 160000 --- a/docs/latest/sway +++ b/docs/latest/sway @@ -1 +1 @@ -Subproject commit e75f14b03636bc96751a6760304a1a6d3eb5937d +Subproject commit 512a3386f8961185188302f391ccc96553d23a7a diff --git a/docs/sway b/docs/sway index 7497fb621..512a3386f 160000 --- a/docs/sway +++ b/docs/sway @@ -1 +1 @@ -Subproject commit 7497fb621e04a41f96a17e0c246c36364a91d12b +Subproject commit 512a3386f8961185188302f391ccc96553d23a7a diff --git a/scripts/update-latest/gitUtils.mjs b/scripts/update-latest/gitUtils.mjs index fd9dd5d2f..6747338a3 100644 --- a/scripts/update-latest/gitUtils.mjs +++ b/scripts/update-latest/gitUtils.mjs @@ -50,6 +50,12 @@ export const checkoutVersion = async (version, dir) => { }); }; +export const checkoutBranch = async (branch, dir) => { + await exec('git', ['checkout', branch], { + cwd: dir, + }); +}; + export const commitAll = async (message) => { await exec('git', ['add', '.']); await exec('git', ['commit', '-m', message]); @@ -108,3 +114,57 @@ export const gitResetCommit = async (releaseCommit, dir) => { cwd: dir, }); }; + +export const getReleaseTimestamp = async (version, dir) => { + try { + let releaseTimestamp = null; + await exec('git', ['log', '--format="%ct"', '-n', '1', `tags/${version}`], { + cwd: dir, + listeners: { + stdout: (data) => { + console.log('data.toString()', data.toString()); + releaseTimestamp = parseInt(data.toString().trim().slice(1, -1), 10); + }, + }, + }); + return releaseTimestamp; + } catch (error) { + console.error( + `Error getting commit timestamp for version ${version}: ${error.message}` + ); + return null; + } +}; + +export const getCommitByTimestamp = async (timestamp, branch, dir) => { + try { + let closestCommitHash = ''; + let commits = []; + + // Fetch all commits in branch + await exec('git', ['log', '--format="%H %ct"', '--max-count=300', branch], { + cwd: dir, + listeners: { + stdout: (data) => { + const commitLines = data.toString().trim().split('\n'); + commits = commits.concat(commitLines); + }, + }, + }); + + // Find a commit with a timestamp after the timestamp + for (let i = 0; i < commits.length; i++) { + const commit = commits[i]; + const [commitHash, commitTimestamp] = commit.split(' '); + const cleanTS = parseInt(commitTimestamp.slice(0, -1)); + if (cleanTS < timestamp) { + break; + } + closestCommitHash = commitHash.substr(1); + } + + return closestCommitHash; + } catch (error) { + console.error(`Error finding commit by timestamp: ${error.message}`); + } +}; diff --git a/scripts/update-latest/updateLatest.mjs b/scripts/update-latest/updateLatest.mjs index 9b392dc0d..a88e295ff 100644 --- a/scripts/update-latest/updateLatest.mjs +++ b/scripts/update-latest/updateLatest.mjs @@ -9,8 +9,10 @@ import { createPR, fetchTag, fetchBranch, - getVersionCommit, + getReleaseTimestamp, gitResetCommit, + getCommitByTimestamp, + checkoutBranch, } from './gitUtils.mjs'; export async function updateLatest(newVersions) { @@ -106,15 +108,21 @@ export async function update(version, dir, branch) { await checkoutVersion(version, dir); } if (branch) { - let releaseCommit; + let releaseTimestamp; if (dir !== 'docs/latest/fuels-ts') { - releaseCommit = await getVersionCommit(version, dir); + releaseTimestamp = await getReleaseTimestamp(version, dir); + console.log('RELEASE TIMESTAMP:', releaseTimestamp); } await fetchBranch(branch, dir); - await switchToExistingBranch(branch, dir); + await checkoutBranch(branch, dir); if (dir !== 'docs/latest/fuels-ts') { - // go to the version commit in the right branch; - await gitResetCommit(releaseCommit, dir); + const commitHash = await getCommitByTimestamp( + releaseTimestamp, + branch, + dir + ); + console.log('COMMIT HASH:', commitHash); + await gitResetCommit(commitHash, dir); } } }