Skip to content

Commit

Permalink
test pr in odh.io
Browse files Browse the repository at this point in the history
  • Loading branch information
AjayJagan committed Oct 4, 2024
1 parent 15dfe1a commit 95611fa
Show file tree
Hide file tree
Showing 4 changed files with 152 additions and 1 deletion.
45 changes: 44 additions & 1 deletion .github/scripts/get-component-release-notes.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,43 @@ function getModifiedComponentName(name) {
modifiedWord = modifiedWord[0].toUpperCase() + modifiedWord.slice(1).toLowerCase()
return modifiedWord.replace("Odh", "ODH")
}

function getComponentVersion(url) {
const splitArr = url.trim().split("/")
let idx = null
if (splitArr.includes("tag")) {
idx = splitArr.indexOf("tag")
} else if (splitArr.includes("tree")) {
idx = splitArr.indexOf("tree")
}
const releaseName = splitArr.slice(idx + 1).join("/")
const semverRegex = /\bv?\d+\.\d+\.\d+\b/;
const match = str.match(semverRegex);
return match ? match[0] : null;
}

function createMarkdownTable(array){
if (!array.length) return '';

const colWidths = array[0].map((_, colIndex) =>
Math.max(...array.map(row => String(row[colIndex]).length))
);

const header = array[0].map((header, index) =>
header.toString().padEnd(colWidths[index])
).join(' | ');

const separator = colWidths.map(width => '-'.repeat(width)).join(' | ');

const rows = array.slice(1).map(row =>
row.map((cell, index) =>
cell.toString().padEnd(colWidths[index])
).join(' | ')
);

return [header, separator, ...rows].join('\n');
}

module.exports = async ({ github, core, context }) => {
const { TRACKER_URL: trackerUrl, VERSION: currentTag } = process.env
console.log(`The TRACKER_URL is ${trackerUrl}`)
Expand Down Expand Up @@ -45,6 +82,7 @@ module.exports = async ({ github, core, context }) => {
}
})
let outputStr = "## Component Release Notes\n"
const releaseNotesArray = [["Technology", "Version"]]
commentsResult.data.forEach((issue) => {
let issueCommentBody = issue.body_text
if (issueCommentBody.includes("#Release#")) {
Expand All @@ -57,15 +95,20 @@ module.exports = async ({ github, core, context }) => {
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`
releaseNotesArray.push([componentName, getComponentVersion(releaseNotesUrl)])
}

}
})
}
})

outputStr += "\n" + releaseNotesString
console.log("Created component release notes successfully...")
core.setOutput('release-notes-body', outputStr);
core.setOutput('release-notes-markdown', createMarkdownTable(releaseNotesArray))
} catch (error) {
core.setFailed(`Action failed with error ${error}`);
}
Expand Down
25 changes: 25 additions & 0 deletions .github/scripts/test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
function arrayToMarkdownTable(array) {
if (array.length === 0) return '';

// Create header row and separator
const header = array[0];
const separator = header.map(() => '---').join('|');

// Create the Markdown table
const rows = array.map(row => row.join('|')).join('\n');

// Combine header, separator, and rows
return [header.join('|'), separator, rows].join('\n');
}

const data = [
["Technology", "Version"],
["Opendatahub", "v2.18.0"],
["dashboard", "v2.11.0"],
["Model reg", "2.11.11"]
]

module.exports = ({ github, core }) => {
const markdownTable = arrayToMarkdownTable(data);
core.setOutput("MD", `\n ### Open Data Hub version\n${markdownTable}\n`);
}
9 changes: 9 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ jobs:
gh-release:
if: github.event.pull_request.merged && startsWith(github.event.pull_request.title, 'ODH Release') && endsWith(github.event.pull_request.title, 'Version Update')
runs-on: ubuntu-latest
outputs:
release-notes: ${{ steps.release-notes.outputs.release-notes-markdown }}
steps:
- uses: actions/checkout@v4
- name: Get release data from pr
Expand Down Expand Up @@ -42,6 +44,13 @@ jobs:
body: ${{ steps.release-notes.outputs.release-notes-body }}
tag_name: v${{ env.VERSION }}
make_latest: true
opendatahub-io-release-notes:
runs-on: ubuntu-latest
needs: gh-release
steps:
- env:
RN: ${{ needs.gh-release.outputs.release-notes }}
run: echo "$RN"
# TODO: To be enabled later.
# create-community-operators-pr:
# needs: [gh-release]
Expand Down
74 changes: 74 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: "Test pr in odh.io"
on:
workflow_dispatch:
permissions:
pull-requests: write
contents: write
jobs:
create-pr:
runs-on: ubuntu-latest
steps:
- name: Checkout opendatahub.io
uses: actions/checkout@v4
with:
repository: AjayJagan/opendatahub.io
- uses: actions/create-github-app-token@v1
id: generate-token
with:
app-id: ${{ secrets.APP_ID }}
private-key: ${{ secrets.APP_PRIVATE_KEY }}
owner: AjayJagan
repositories: opendatahub.io
- name: test md
id: table
uses: actions/github-script@v7
with:
script: |
function arrayToMarkdownTable(array) {
if (!array.length) return '';
// Determine column widths
const colWidths = array[0].map((_, colIndex) =>
Math.max(...array.map(row => String(row[colIndex]).length))
);
// Create the header row
const header = array[0].map((header, index) =>
header.toString().padEnd(colWidths[index])
).join(' | ');
// Create the separator row
const separator = colWidths.map(width => '-'.repeat(width)).join(' | ');
// Create the data rows
const rows = array.slice(1).map(row =>
row.map((cell, index) =>
cell.toString().padEnd(colWidths[index])
).join(' | ')
);
// Combine header, separator, and rows into a complete table
return [header, separator, ...rows].join('\n');
}
const data = [
['Technology', 'Version'],
['Opendatahub operator', 'V2.18.0'],
['odh dashboard','v1.18'],
['model reg','v10.1.11']
];
core.setOutput("MD", `\n ### Open Data Hub version\n${arrayToMarkdownTable(data)}\n`);
- name: change something
run: |
LINE_NUMBER=$(awk '/###/{ print NR-1; exit }' ./src/content/docs/release-notes.md)
sed -i "${LINE_NUMBER}r /dev/stdin" ./src/content/docs/release-notes.md <<EOF
${{ steps.table.outputs.MD }}
EOF
- name: Create pr
uses: peter-evans/create-pull-request@v7
with:
token: ${{ steps.generate-token.outputs.token }}
commit-message: my first commit
delete-branch: true
title: This is a test PR
branch: testbranch

0 comments on commit 95611fa

Please sign in to comment.