Skip to content
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

chore: Added create-release-pr job to post-release action #1615

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions .github/workflows/post-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,7 @@ jobs:
run: node ./bin/update-system-config-pages.js --version ${{ steps.get_tag.outputs.latest_tag }} --staging-key ${{ secrets.NEW_RELIC_API_KEY_STAGING }} --prod-key ${{ secrets.NEW_RELIC_API_KEY_PRODUCTION }}
- name: Publish API Docs
run: npm run publish-docs
- name: Create Docs Website PR
run: node ./bin/create-docs-pr.js --tag ${{ steps.get_tag.outputs.latest_tag }}
env:
GITHUB_TOKEN: ${{ secrets.GH_TOKEN }}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This isn't the correct secret. It's NODE_AGENT_GH_TOKEN

42 changes: 35 additions & 7 deletions bin/create-docs-pr.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ program.option(
'Name of changelog(defaults to NEWS.md)',
DEFAULT_FILE_NAME
)
program.option('-f --force', 'bypass validation')
program.option('--dry-run', 'executes script but does not commit nor create PR')
program.option(
'--repo-path <path',
'Path to the docs-website fork on local machine',
'docs-website'
'/tmp/docs-website'
)
mrickard marked this conversation as resolved.
Show resolved Hide resolved

program.option('--repo-owner <owner>', 'Owner of the target repo', 'newrelic')

const RELEASE_NOTES_PATH =
'./src/content/docs/release-notes/agent-release-notes/nodejs-release-notes'

Expand All @@ -48,6 +50,9 @@ async function createReleaseNotesPr() {

console.log(`Script running with following options: ${JSON.stringify(options)}`)

const username = options.username || process.env.GITHUB_ACTOR
const repoOwner = options.repoOwner

try {
const version = options.tag.replace('refs/tags/', '')
console.log(`Getting version from tag: ${version}`)
Expand All @@ -56,6 +61,10 @@ async function createReleaseNotesPr() {
validateTag(version, options.force)
logStep('Get Release Notes from File')
const { body, releaseDate } = await getReleaseNotes(version, options.changelog)

logStep('Set up docs repo')
await cloneDocsRepo(options.repoPath, repoOwner)

logStep('Branch Creation')
const branchName = await createBranch(options.repoPath, version, options.dryRun)
logStep('Format release notes file')
Expand All @@ -65,7 +74,7 @@ async function createReleaseNotesPr() {
logStep('Commit Release Notes')
await commitReleaseNotes(version, options.remote, branchName, options.dryRun)
logStep('Create Pull Request')
await createPR(options.username, version, branchName, options.dryRun)
await createPR(username, version, branchName, options.dryRun, repoOwner)
console.log('*** Full Run Successful ***')
} catch (err) {
if (err.status && err.status === 404) {
Expand Down Expand Up @@ -128,14 +137,29 @@ async function readReleaseNoteFile(file) {
return new Promise((resolve, reject) => {
fs.readFile(file, 'utf8', (err, data) => {
if (err) {
return reject(err)
reject(err)
}

return resolve(data)
resolve(data)
})
})
}

/**
* Clones docs repo
*
* @param repoPath
* @param repoOwner
* @returns {boolean} success or failure
*/
async function cloneDocsRepo(repoPath, repoOwner) {
const branch = 'develop'
const url = `https://x-access-token:${process.env.GITHUB_TOKEN}@github.com/${repoOwner}/docs-website.git`
const cloneOptions = [`--branch=${branch}`, '--single-branch']

return git.clone(url, repoPath, cloneOptions)
}

/**
* Creates a branch in your local `docs-website` fork
* That follows the pattern `add-node-<new agent version>`
Expand Down Expand Up @@ -227,6 +251,9 @@ async function commitReleaseNotes(version, remote, branch, dryRun) {
console.log('Dry run indicated (--dry-run), skipping committing release notes.')
return
}
const GITHUB_ACTOR = process.env.GITHUB_ACTOR
const GITHUB_EMAIL = `gh-actions-${GITHUB_ACTOR}@github.com`
await git.setUser(GITHUB_ACTOR, GITHUB_EMAIL)

console.log(`Adding release notes for ${version}`)
const files = [getFileName(version)]
Expand All @@ -243,14 +270,15 @@ async function commitReleaseNotes(version, remote, branch, dryRun) {
* @param {string} version version number
* @param {string} branch github branch
* @param {boolean} dryRun whether or not we should actually create the PR
* @param {string} repoOwner Owner of the docs-website repo, if targeting a fork instead of newrelic
*/
async function createPR(username, version, branch, dryRun) {
async function createPR(username, version, branch, dryRun, repoOwner) {
if (!process.env.GITHUB_TOKEN) {
console.log('GITHUB_TOKEN required to create a pull request')
stopOnError()
}

const github = new Github('newrelic', 'docs-website')
const github = new Github(repoOwner, 'docs-website')
const title = `Node.js Agent ${version} Release Notes`
const prOptions = {
head: `${username}:${branch}`,
Expand Down
13 changes: 10 additions & 3 deletions bin/git-commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,16 +116,22 @@ async function sparseCloneRepo(repoInfo, checkoutFiles) {
process.chdir('..')
}

async function setUser(name, email) {
const setName = await execAsPromise(`git config user.name ${name}`)
const setEmail = await execAsPromise(`git config user.email ${email}`)
return [setName, setEmail].join(' ')
}

function execAsPromise(command) {
return new Promise((resolve, reject) => {
console.log(`Executing: '${command}'`)

exec(command, (err, stdout) => {
if (err) {
return reject(err)
reject(err)
}

return resolve(stdout)
resolve(stdout)
})
})
}
Expand All @@ -143,5 +149,6 @@ module.exports = {
checkout,
clone,
sparseCloneRepo,
addFiles
addFiles,
setUser
}