Files
react-native/bots/post-artifacts-link.js
T
Luna Wei 046a7d2286 Fix artifacts link
Summary: Changelog: [Internal] - Fix artifacts link in PR commitly comment

Reviewed By: hramos

Differential Revision: D31624488

fbshipit-source-id: cef7c79f1f8d290aa9541c3c955c9a68dc5fd643
2021-10-13 15:05:46 -07:00

50 lines
1.4 KiB
JavaScript

/**
* Copyright (c) Facebook, Inc. and its affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*
* @format
*/
'use strict';
const {GITHUB_TOKEN, CIRCLE_BUILD_URL, GITHUB_SHA} = process.env;
if (!GITHUB_TOKEN || !CIRCLE_BUILD_URL) {
if (!GITHUB_TOKEN) {
console.error("Missing GITHUB_TOKEN. This should've been set by the CI.");
}
if (!CIRCLE_BUILD_URL) {
console.error(
"Missing CIRCLE_BUILD_URL. This should've been set by the CI.",
);
}
process.exit(1);
}
const {createOrUpdateComment} = require('./make-comment');
/**
* Creates or updates a comment with specified pattern.
* @param {string} buildURL link to circleCI build
* @param {string} commitSha github sha of PR
*/
function postArtifactLink(buildUrl, commitSha) {
// build url link is redirected by CircleCI so appending `/artifacts` doesn't work
const artifactLink = buildUrl;
const comment = [
`PR build artifact${
commitSha != null ? ` for ${commitSha}` : ''
} is ready.`,
`To use, download tarball from "Artifacts" tab in [this CircleCI job](${artifactLink}) then run \`yarn add <path to tarball>\` in your React Native project.`,
].join('\n');
createOrUpdateComment(comment);
}
try {
postArtifactLink(CIRCLE_BUILD_URL, GITHUB_SHA);
} catch (error) {
console.error(error);
process.exitCode = 1;
}