Skip to content

Commit

Permalink
update beta-4 versions, fix CI
Browse files Browse the repository at this point in the history
  • Loading branch information
sarahschwartz committed Nov 2, 2023
1 parent 86c4875 commit 285bba6
Show file tree
Hide file tree
Showing 8 changed files with 80 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion docs/builds/sway
Submodule sway updated 1734 files
2 changes: 1 addition & 1 deletion docs/fuel-indexer
Submodule fuel-indexer updated 231 files
2 changes: 1 addition & 1 deletion docs/latest/builds/sway
Submodule sway updated 36302 files
2 changes: 1 addition & 1 deletion docs/latest/sway
Submodule sway updated 316 files
2 changes: 1 addition & 1 deletion docs/sway
Submodule sway updated 507 files
60 changes: 60 additions & 0 deletions scripts/update-latest/gitUtils.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand Down Expand Up @@ -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}`);
}
};
20 changes: 14 additions & 6 deletions scripts/update-latest/updateLatest.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,10 @@ import {
createPR,
fetchTag,
fetchBranch,
getVersionCommit,
getReleaseTimestamp,
gitResetCommit,
getCommitByTimestamp,
checkoutBranch,
} from './gitUtils.mjs';

export async function updateLatest(newVersions) {
Expand Down Expand Up @@ -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);
}
}
}

0 comments on commit 285bba6

Please sign in to comment.