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

(fix): ODH release automation: Release notes generation #1265

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
65 changes: 45 additions & 20 deletions .github/scripts/get-component-release-notes.js
Original file line number Diff line number Diff line change
@@ -1,27 +1,51 @@
function getModifiedComponentName(name){
function getModifiedComponentName(name) {
let modifiedWord = name.split("-").join(" ").replace(/[^a-zA-Z ]/g, "").trim()
modifiedWord = modifiedWord[0].toUpperCase() + modifiedWord.slice(1).toLowerCase()
return modifiedWord.replace("Odh", "ODH")
}
module.exports = ({ github, core }) => {
const { TRACKER_URL } = process.env
console.log(`The TRACKER_URL is ${TRACKER_URL}`)
const arr = TRACKER_URL.split("/")
module.exports = async ({ github, core, context }) => {
const { TRACKER_URL: trackerUrl, VERSION: currentTag } = process.env
console.log(`The TRACKER_URL is ${trackerUrl}`)
const arr = trackerUrl.split("/")
const owner = arr[3]
const repo = arr[4]
const issue_number = arr[6]

github.request('GET /repos/{owner}/{repo}/issues/{issue_number}/comments', {
owner,
repo,
issue_number,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github.text+json'
}
}).then((result) => {
try {
const latestReleaseResult = await github.rest.repos.getLatestRelease({
owner: context.repo.owner,
repo: context.repo.repo,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github+json',
}
})
const previousTag = latestReleaseResult.data["tag_name"]
console.log(`The current tag is: ${previousTag}`)

const releaseNotesResult = await github.rest.repos.generateReleaseNotes({
owner: context.repo.owner,
repo: context.repo.repo,
tag_name: currentTag,
previous_tag_name: previousTag,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github+json'
}
})
const releaseNotesString = releaseNotesResult.data["body"]

const commentsResult = await github.rest.issues.listComments({
owner,
repo,
issue_number,
headers: {
'X-GitHub-Api-Version': '2022-11-28',
'Accept': 'application/vnd.github.text+json'
}
})
let outputStr = "## Component Release Notes\n"
result.data.forEach((issue) => {
commentsResult.data.forEach((issue) => {
let issueCommentBody = issue.body_text
if (issueCommentBody.includes("#Release#")) {
let components = issueCommentBody.split("\n")
Expand All @@ -33,15 +57,16 @@ module.exports = ({ github, core }) => {
let [componentName, branchUrl, tagUrl] = component.split("|")
componentName = getModifiedComponentName(componentName.trim())
const releaseNotesUrl = (tagUrl || branchUrl).trim();
if(!outputStr.includes(componentName)) outputStr += `- **${componentName}**: ${releaseNotesUrl}\n`
if (!outputStr.includes(componentName)) outputStr += `- **${componentName}**: ${releaseNotesUrl}\n`

}
})
}
})
outputStr += "\n" + releaseNotesString
console.log("Created component release notes successfully...")
core.setOutput('release-notes-body', outputStr);
}).catch(e => {
core.setFailed(`Action failed with error ${e}`);
})
} catch (error) {
core.setFailed(`Action failed with error ${error}`);
}
}
5 changes: 3 additions & 2 deletions .github/workflows/pre-release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ on:
pull_request:
types:
- closed

jobs:
push-tags-and-create-release-prs:
if: github.event_name == 'pull_request' && github.event.pull_request.merged == false && github.event.action == 'closed' && contains(github.event.pull_request.title, '[DO NOT MERGE] Test')
Expand All @@ -23,7 +22,7 @@ jobs:
exit 1
fi
shell: bash
- name: Get release data
- name: Get release data from comment
uses: peter-evans/find-comment@v3
id: release-data
with:
Expand All @@ -50,6 +49,8 @@ jobs:
base-branch: incubation
- name: Create release branch
run: |
git fetch origin incubation:incubation
git checkout incubation
git checkout -b odh-${{ env.VERSION }}
git push -f origin odh-${{ env.VERSION }}
- uses: ./.github/actions/update-manifest-branches
Expand Down
6 changes: 2 additions & 4 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,14 @@ jobs:
with:
script: |
const script = require('./.github/scripts/get-component-release-notes.js')
script({github, core})
await script({github, core, context})
- name: Create GH release
uses: softprops/action-gh-release@v2
with:
body: ${{ steps.release-notes.outputs.release-notes-body }}
tag_name: v${{ env.VERSION }}
generate_release_notes: true
append_body: true
make_latest: true
# To be enabled later.
# TODO: To be enabled later.
# create-community-operators-pr:
# needs: [gh-release]
# name: Create community operators prod pr # https://github.com/redhat-openshift-ecosystem/community-operators-prod
Expand Down
Loading