Skip to content

Commit

Permalink
Comment on PR with link to PR artifact
Browse files Browse the repository at this point in the history
Summary: Changelog: [Internal] Configure circleCI to comment on PR after building tarball

Reviewed By: hramos

Differential Revision: D31387660

fbshipit-source-id: 28902148cf5e2ea15320333b90a6a7fa9d553c3b
  • Loading branch information
Luna Wei authored and facebook-github-bot committed Oct 9, 2021
1 parent aae9355 commit 2a605c3
Show file tree
Hide file tree
Showing 3 changed files with 66 additions and 0 deletions.
7 changes: 7 additions & 0 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -774,6 +774,13 @@ jobs:
- store_artifacts:
path: ~/react-native/build/
destination: build
- when:
condition:
matches: { pattern: '^pull\/.*$', value: << pipeline.git.branch >> }
steps:
- run:
name: Post link to PR build artifacts (pull-bot)
command: GITHUB_TOKEN="$PUBLIC_PULLBOT_GITHUB_TOKEN_A""$PUBLIC_PULLBOT_GITHUB_TOKEN_B" scripts/circleci/post-artifacts-link.sh

# -------------------------
# JOBS: Nightly
Expand Down
48 changes: 48 additions & 0 deletions bots/post-artifacts-link.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/**
* 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) {
const artifactLink = buildUrl + '/artifacts';
const comment = [
`PR build artifact${
commitSha != null ? ` for ${commitSha}` : ''
} is ready.`,
`To use, download tarball from [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;
}
11 changes: 11 additions & 0 deletions scripts/circleci/post-artifacts-link.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
#!/bin/bash
# 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.

GITHUB_OWNER=${CIRCLE_PROJECT_USERNAME:-facebook} \
GITHUB_REPO=${CIRCLE_PROJECT_REPONAME:-react-native} \
GITHUB_PR_NUMBER="${CIRCLE_PR_NUMBER:-${CIRCLE_PULL_REQUEST##*/}}" \
GITHUB_SHA=${CIRCLE_SHA1} \
exec node bots/post-artifacts-link.js

0 comments on commit 2a605c3

Please sign in to comment.