This commit introduces the ability to show previews for PRs by any author. It works as follows: - The build artifacts of all PRs are uploaded to the preview server. - Automatically verified PRs (i.e. from trusted authors or having a specific label) are deployed and publicly accessible as usual. - PRs that could not be automatically verified are stored for later use (after re-verification). - A PR can be marked as "trusted" and make its preview publicly accessible by adding the GitHub label specified in the `AIO_TRUSTED_PR_LABEL` env var of the preview server. At the moment, there is no automatic mechanism for notifying the preview server about changes to the PR's verification status. The PR's "visibility" will be checked and updated every time a new build is uploaded.
40 lines
1.3 KiB
TypeScript
40 lines
1.3 KiB
TypeScript
// Imports
|
|
import {getEnvVar} from '../common/utils';
|
|
import {BuildVerifier} from './build-verifier';
|
|
|
|
// Run
|
|
_main();
|
|
|
|
// Functions
|
|
function _main() {
|
|
const secret = 'unused';
|
|
const githubToken = getEnvVar('AIO_GITHUB_TOKEN');
|
|
const repoSlug = getEnvVar('AIO_REPO_SLUG');
|
|
const organization = getEnvVar('AIO_GITHUB_ORGANIZATION');
|
|
const allowedTeamSlugs = getEnvVar('AIO_GITHUB_TEAM_SLUGS').split(',');
|
|
const trustedPrLabel = getEnvVar('AIO_TRUSTED_PR_LABEL');
|
|
const pr = +getEnvVar('AIO_PREVERIFY_PR');
|
|
|
|
const buildVerifier = new BuildVerifier(secret, githubToken, repoSlug, organization, allowedTeamSlugs,
|
|
trustedPrLabel);
|
|
|
|
// Exit codes:
|
|
// - 0: The PR can be automatically trusted (i.e. author belongs to trusted team or PR has the "trusted PR" label).
|
|
// - 1: An error occurred.
|
|
// - 2: The PR cannot be automatically trusted.
|
|
buildVerifier.getPrIsTrusted(pr).
|
|
then(isTrusted => {
|
|
if (!isTrusted) {
|
|
console.warn(
|
|
`The PR cannot be automatically verified, because it doesn't have the "${trustedPrLabel}" label and the ` +
|
|
`the author is not an active member of any of the following teams: ${allowedTeamSlugs.join(', ')}`);
|
|
}
|
|
|
|
process.exit(isTrusted ? 0 : 2);
|
|
}).
|
|
catch(err => {
|
|
console.error(err);
|
|
process.exit(1);
|
|
});
|
|
}
|