Skip to content

Commit

Permalink
ci: Fix metamaskbot comment build links
Browse files Browse the repository at this point in the history
Various build links in the `metamaskbot` PR comment were broken. All
links have been fixed except beta (which is trickier to fix, requires
more substantial changes to the beta workflows). Additionally,
validation was added to verify each build link, omitting any that are
not working from the comment (and logging warning).
  • Loading branch information
Gudahtt committed Dec 20, 2024
1 parent 695d0db commit 6ec646c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 52 deletions.
16 changes: 15 additions & 1 deletion .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -329,10 +329,16 @@ workflows:
- prep-deps
- prep-build
- prep-build-mv2
- trigger-beta-build
- prep-build-mmi
- prep-build-flask
- prep-build-flask-mv2
- prep-build-test
- prep-build-test-mv2
- prep-build-test-webpack
- prep-build-test-flask
- prep-build-test-flask-mv2
- prep-build-test-mmi
- trigger-beta-build
- prep-build-storybook
- prep-build-ts-migration-dashboard
- benchmark
Expand Down Expand Up @@ -1533,8 +1539,16 @@ jobs:
destination: builds-mv2
- store_artifacts:
path: builds-test
- store_artifacts:
path: builds-test-mv2
- store_artifacts:
path: builds-test-webpack
- store_artifacts:
path: builds-test-flask
- store_artifacts:
path: builds-test-flask-mv2
- store_artifacts:
path: builds-test-mmi
- store_artifacts:
path: test-artifacts
destination: test-artifacts
Expand Down
121 changes: 70 additions & 51 deletions development/metamaskbot-build-announce.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,17 @@ function getPercentageChange(from, to) {
return parseFloat(((to - from) / Math.abs(from)) * 100).toFixed(2);
}

/**
* Check whether an artifact exists,
*
* @param {string} url - The URL of the artifact to check.
* @returns True if the artifact exists, false if it doesn't
*/
async function artifactExists(url) {
const response = await fetch(url, { method: 'HEAD' });
return response.ok;
}

async function start() {
const {
GITHUB_COMMENT_TOKEN,
Expand Down Expand Up @@ -65,50 +76,62 @@ async function start() {
// build the github comment content

// links to extension builds
const platforms = ['chrome', 'firefox'];
const buildLinks = platforms
.map((platform) => {
const url =
platform === 'firefox'
? `${BUILD_LINK_BASE}/builds-mv2/metamask-${platform}-${VERSION}.zip`
: `${BUILD_LINK_BASE}/builds/metamask-${platform}-${VERSION}.zip`;
return `<a href="${url}">${platform}</a>`;
})
.join(', ');
const betaBuildLinks = `<a href="${BUILD_LINK_BASE}/builds-beta/metamask-beta-chrome-${VERSION}.zip">chrome</a>`;
const flaskBuildLinks = platforms
.map((platform) => {
const url =
platform === 'firefox'
? `${BUILD_LINK_BASE}/builds-flask-mv2/metamask-flask-${platform}-${VERSION}-flask.0.zip`
: `${BUILD_LINK_BASE}/builds-flask/metamask-flask-${platform}-${VERSION}-flask.0.zip`;
return `<a href="${url}">${platform}</a>`;
})
.join(', ');
const mmiBuildLinks = platforms
.map((platform) => {
const url = `${BUILD_LINK_BASE}/builds-mmi/metamask-mmi-${platform}-${VERSION}-mmi.0.zip`;
return `<a href="${url}">${platform}</a>`;
})
.join(', ');
const testBuildLinks = platforms
.map((platform) => {
const url =
platform === 'firefox'
? `${BUILD_LINK_BASE}/builds-test-mv2/metamask-${platform}-${VERSION}.zip`
: `${BUILD_LINK_BASE}/builds-test/metamask-${platform}-${VERSION}.zip`;
return `<a href="${url}">${platform}</a>`;
})
.join(', ');
const testFlaskBuildLinks = platforms
.map((platform) => {
const url =
platform === 'firefox'
? `${BUILD_LINK_BASE}/builds-test-flask-mv2/metamask-flask-${platform}-${VERSION}-flask.0.zip`
: `${BUILD_LINK_BASE}/builds-test-flask/metamask-flask-${platform}-${VERSION}-flask.0.zip`;
return `<a href="${url}">${platform}</a>`;
})
.join(', ');
const buildMap = {
builds: {
chrome: `${BUILD_LINK_BASE}/builds/metamask-chrome-${VERSION}.zip`,
firefox: `${BUILD_LINK_BASE}/builds-mv2/metamask-firefox-${VERSION}.zip`,
},
'builds (beta)': {
chrome: `${BUILD_LINK_BASE}/builds-beta/metamask-flask-chrome-${VERSION}-beta.0.zip`,
},
'builds (flask)': {
chrome: `${BUILD_LINK_BASE}/builds-flask/metamask-flask-chrome-${VERSION}-flask.0.zip`,
firefox: `${BUILD_LINK_BASE}/builds-flask-mv2/metamask-flask-firefox-${VERSION}-flask.0.zip`,
},
'builds (MMI)': {
chrome: `${BUILD_LINK_BASE}/builds-mmi/metamask-mmi-chrome-${VERSION}-mmi.0.zip`,
},
'builds (test)': {
chrome: `${BUILD_LINK_BASE}/builds-test/metamask-chrome-${VERSION}.zip`,
firefox: `${BUILD_LINK_BASE}/builds-test-mv2/metamask-firefox-${VERSION}.zip`,
},
'builds (test webpack)': {
chrome: `${BUILD_LINK_BASE}/builds-test-webpack/metamask-chrome-${VERSION}.zip`,
},
'builds (test-flask)': {
chrome: `${BUILD_LINK_BASE}/builds-test-flask/metamask-flask-chrome-${VERSION}-flask.0.zip`,
firefox: `${BUILD_LINK_BASE}/builds-test-flask-mv2/metamask-flask-firefox-${VERSION}-flask.0.zip`,
},
'builds (test-mmi)': {
chrome: `${BUILD_LINK_BASE}/builds-test-mmi/metamask-mmi-chrome-${VERSION}-mmi.0.zip`,
},
};

// Builds that have been verified to exist
const verifiedBuildMap = {};
await Promise.all(
Object.entries(buildMap).map(async ([label, builds]) => {
verifiedBuildMap[label] = {};
await Promise.all(
Object.entries(builds).map(async ([platform, url]) => {
if (await artifactExists(url)) {
verifiedBuildMap[label][platform] = url;
} else {
console.warn(`Build missing: ${url}`);
}
}),
);
}),
);

const buildContentRows = Object.entries(verifiedBuildMap).map(
(label, builds) => {
const buildLinks = Object.entries(builds).map((platform, url) => {
return `<a href="${url}">${platform}</a>`;
});
return `${label}: ${buildLinks.join(', ')}`;
},
);

// links to bundle browser builds
const bundles = {};
Expand Down Expand Up @@ -171,12 +194,7 @@ async function start() {
const allArtifactsUrl = `https://circleci.com/gh/MetaMask/metamask-extension/${CIRCLE_BUILD_NUM}#artifacts/containers/0`;

const contentRows = [
`builds: ${buildLinks}`,
`builds (beta): ${betaBuildLinks}`,
`builds (flask): ${flaskBuildLinks}`,
`builds (MMI): ${mmiBuildLinks}`,
`builds (test): ${testBuildLinks}`,
`builds (test-flask): ${testFlaskBuildLinks}`,
...buildContentRows,
`build viz: ${depVizLink}`,
`mv3: ${moduleInitStatsBackgroundLink}`,
`mv3: ${moduleInitStatsUILink}`,
Expand All @@ -198,8 +216,9 @@ async function start() {
const exposedContent = `Builds ready [${SHORT_SHA1}]`;
const artifactsBody = `<details><summary>${exposedContent}</summary>${hiddenContent}</details>\n\n`;

const benchmarkPlatforms = ['chrome'];
const benchmarkResults = {};
for (const platform of platforms) {
for (const platform of benchmarkPlatforms) {
const benchmarkPath = path.resolve(
__dirname,
'..',
Expand Down

0 comments on commit 6ec646c

Please sign in to comment.