-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Upgrade to Node v18, fix deploy-preview CI job #236
Changes from 2 commits
f195d4e
8a1503e
d144152
d1410a5
d9b2443
f2f67ae
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v16.14 | ||
v18.18 |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,7 +15,7 @@ | |
"typescript": "~4.6.2" | ||
}, | ||
"engines": { | ||
"node": ">=12" | ||
"node": ">=18" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think Node 18 is ok to declare as a minimum engine, since Node 16 maintenance LTS is about to end at the end of this month. See Node.js Releases. |
||
}, | ||
"repository": { | ||
"type": "git", | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
#!/usr/bin/env node | ||
/* | ||
* Copyright 2017 Palantir Technologies, Inc. All rights reserved. | ||
*/ | ||
|
||
// @ts-check | ||
/* eslint-disable camelcase */ | ||
|
||
// Submits a comment to the change PR or commit with links to artifacts that | ||
// show the results of the code change being applied. | ||
|
||
import dedent from "dedent"; | ||
import { execSync } from "node:child_process"; | ||
import { basename } from "node:path"; | ||
import { Octokit } from "octokit"; | ||
|
||
/** | ||
* @type {Array<{path: string; url: string;}>} | ||
*/ | ||
const { default: artifacts } = await import("./artifacts.json", { assert: { type: "json" }}); | ||
|
||
if (artifacts.items === undefined) { | ||
throw new Error( | ||
"Unable to read artifacts.json, please make sure the CircleCI API call succeeded with the necessary personal access token.", | ||
); | ||
} | ||
|
||
const ARTIFACTS = { | ||
documentation: "packages/docs-app/dist/index.html", | ||
landing: "packages/landing-app/dist/index.html", | ||
table: "packages/table-dev-app/dist/index.html", | ||
demo: "packages/demo-app/dist/index.html", | ||
}; | ||
|
||
function getArtifactAnchorLink(pkg) { | ||
const artifactInfo = artifacts.items.find(a => a.path === ARTIFACTS[pkg]); | ||
return `<a href="${artifactInfo?.url}">${pkg}</a>`; | ||
} | ||
|
||
if (process.env.GITHUB_API_TOKEN) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. looks like there are some old tokens in the CI env variables right now, I'm going to try those out. it those don't work though, I will have to generate & inject a new personal token just like palantir/blueprint#5827 and the preview comments will come from my GitHub account There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
// We can post a comment on the PR if we have the necessary github.com personal access token with access to this | ||
// repository and PR read/write permissions. | ||
// See https://docs.github.com/en/authentication/keeping-your-account-and-data-secure/creating-a-personal-access-token#creating-a-fine-grained-personal-access-token | ||
const octokit = new Octokit({ auth: process.env.GITHUB_API_TOKEN }); | ||
|
||
const artifactLinks = Object.keys(ARTIFACTS).map(getArtifactAnchorLink).join(" | "); | ||
const currentGitCommitMessage = execSync('git --no-pager log --pretty=format:"%s" -1') | ||
.toString() | ||
.trim() | ||
.replace(/\\"/g, '\\\\"'); | ||
const commentBody = dedent` | ||
<h3>${currentGitCommitMessage}</h3> | ||
Build artifact links for this commit: <strong>${artifactLinks}</strong> | ||
|
||
<em>This is an automated comment from the deploy-preview CircleCI job.</em> | ||
`; | ||
|
||
const repoParams = { | ||
owner: "palantir", | ||
repo: "blueprint", | ||
adidahiya marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}; | ||
|
||
if (process.env.CIRCLE_PULL_REQUEST) { | ||
// attempt to comment on the PR as an "issue comment" (not a review comment) | ||
await octokit.rest.issues.createComment({ | ||
...repoParams, | ||
issue_number: parseInt(basename(process.env.CIRCLE_PULL_REQUEST ?? ""), 10), | ||
body: commentBody, | ||
}); | ||
} else if (process.env.CIRCLE_SHA1) { | ||
// attempt to comment on the commit if there is no associated PR (this is most useful on the develop branch) | ||
await octokit.rest.repos.createCommitComment({ | ||
...repoParams, | ||
commit_sha: process.env.CIRCLE_SHA1, | ||
body: commentBody, | ||
}); | ||
} | ||
} else { | ||
// If the access token is missing, simply log artifact URLs (typical in builds on repository forks). | ||
console.warn( | ||
"No Github API token available, so we cannot post a preview comment on this build's PR. This is expected on forks which have enabled CircleCI building.", | ||
); | ||
Object.keys(ARTIFACTS).forEach(pkg => console.info(`${ARTIFACTS[pkg]}: ${getArtifactAnchorLink(pkg)}`)); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/usr/bin/env bash | ||
|
||
# This script submits a Github comment on the current PR with links to built artifacts hosted in CircleCI. | ||
# | ||
# To do this, it first queries the CircleCI API using a personal access token which is stored as an env variable. | ||
# Currently, this is a token generated by @adidahiya. | ||
# See https://support.circleci.com/hc/en-us/articles/360045457592-Access-uploaded-artifact-URL-in-job | ||
# See https://circleci.com/docs/managing-api-tokens/#creating-a-personal-api-token | ||
# | ||
# After querying for artifact information, it delegates to an adjacent Node.js script to parse the links | ||
# and post a Github comment. | ||
|
||
set -e | ||
set -o pipefail | ||
|
||
if [ -z "${CIRCLE_BUILD_NUM}" ]; then | ||
echo "Not on CircleCI, refusing to run script." | ||
exit 1 | ||
fi | ||
|
||
if [ -z "${CIRCLE_API_TOKEN}" ]; then | ||
echo "No CircleCI API token available to query for artifact asset URLs from this build." | ||
echo " --> If this is a build on a fork of the main repo, this is expected behavior. You can view artifact URLs through the CircleCI job web UI." | ||
echo " --> If this is a build on the main repo, something is wrong: check the \$CIRCLE_API_TOKEN environment variable." | ||
exit 0 | ||
fi | ||
|
||
SCRIPTS_DIR=$(dirname "$(readlink -f "$0")") | ||
artifacts=$(curl -X GET "https://circleci.com/api/v2/project/github/palantir/documentalist/$CIRCLE_BUILD_NUM/artifacts" -H "Accept: application/json" -u "$CIRCLE_API_TOKEN:") | ||
|
||
echo $artifacts > ./scripts/artifacts.json | ||
node $SCRIPTS_DIR/submit-comment-with-artifact-links.mjs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
is this PR supposed to hav ea comment on it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good Q, the preview comment is not working since we don't have the API token being injected right now but we do have docs built and saved as an artifact, which is most of the important part: https://app.circleci.com/pipelines/github/palantir/documentalist/389/workflows/8aba4d88-d87e-4dd5-a45f-ffdda3fad7a5/jobs/2679/artifacts