From c5cda0ba76fb29121bd326cf3f4b9bf9b9083d98 Mon Sep 17 00:00:00 2001 From: AJAY JAGANATHAN Date: Thu, 3 Oct 2024 22:37:53 +0530 Subject: [PATCH] test pr in odh.io --- .../update-release-version/action.yaml | 3 +- .../scripts/get-component-release-notes.js | 45 ++++++++++- .github/scripts/test.js | 25 +++++++ .github/workflows/pre-release.yaml | 3 +- .github/workflows/release.yaml | 37 +++++++++- .github/workflows/test.yaml | 74 +++++++++++++++++++ 6 files changed, 183 insertions(+), 4 deletions(-) create mode 100644 .github/scripts/test.js create mode 100644 .github/workflows/test.yaml diff --git a/.github/actions/update-release-version/action.yaml b/.github/actions/update-release-version/action.yaml index b6871c4a8e8..11272c18e59 100644 --- a/.github/actions/update-release-version/action.yaml +++ b/.github/actions/update-release-version/action.yaml @@ -46,7 +46,8 @@ runs: branch: ${{ inputs.branch-name }} delete-branch: true title: ${{ inputs.title }} - reviewers: "VaishnaviHire,zdtsw" + # TODO + # reviewers: "VaishnaviHire,zdtsw" base: ${{ inputs.base-branch }} - name: Set pr number in output shell: bash diff --git a/.github/scripts/get-component-release-notes.js b/.github/scripts/get-component-release-notes.js index eacc54e5568..0723399f753 100644 --- a/.github/scripts/get-component-release-notes.js +++ b/.github/scripts/get-component-release-notes.js @@ -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 = releaseName.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}`) @@ -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#")) { @@ -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', `\n ### Open Data Hub version: ${currentTag}\n${createMarkdownTable(releaseNotesArray)}\n`) } catch (error) { core.setFailed(`Action failed with error ${error}`); } diff --git a/.github/scripts/test.js b/.github/scripts/test.js new file mode 100644 index 00000000000..b5b2feeb392 --- /dev/null +++ b/.github/scripts/test.js @@ -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`); +} \ No newline at end of file diff --git a/.github/workflows/pre-release.yaml b/.github/workflows/pre-release.yaml index 89f57a0e68a..bf8c23c900e 100644 --- a/.github/workflows/pre-release.yaml +++ b/.github/workflows/pre-release.yaml @@ -35,7 +35,8 @@ jobs: - name: Push version tag to quay.io run: | skopeo login -u ${{ secrets.QUAY_ID }} -p ${{ secrets.QUAY_TOKEN }} quay.io - skopeo copy docker://quay.io/${{ secrets.QUAY_ORG }}/opendatahub-operator:pr-${{ github.event.pull_request.number }} docker://quay.io/${{ secrets.QUAY_ORG }}/opendatahub-operator:v${{ env.VERSION }} + # TODO + # skopeo copy docker://quay.io/${{ secrets.QUAY_ORG }}/opendatahub-operator:pr-${{ github.event.pull_request.number }} docker://quay.io/${{ secrets.QUAY_ORG }}/opendatahub-operator:v${{ env.VERSION }} echo "Successfully updated tag to quay.io with version: v${{ env.VERSION }}" - uses: actions/checkout@v4 - name: Create version update pr in incubation diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 49548932a28..214fab2e931 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,6 +11,9 @@ 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 }} + version: ${{ steps.read-comments.outputs.version }} steps: - uses: actions/checkout@v4 - name: Get release data from pr @@ -20,9 +23,12 @@ jobs: issue-number: ${{ github.event.pull_request.number }} body-includes: "#Release#" - name: Set version/tracker-url in env + id: read-comments run: | - echo "VERSION=$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /version$/{print $2}')" >> $GITHUB_ENV + VERSION="$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /version$/{print $2}')" + echo "VERSION=$VERSION" >> $GITHUB_ENV echo "TRACKER_URL=$(echo "${{ steps.fc.outputs.comment-body }}" | awk -F= '$1 ~ /tracker-url$/{print $2}')" >> $GITHUB_ENV + echo "version=$VERSION" >> $GITHUB_OUTPUT - uses: fregante/setup-git-user@v2 - name: Create and push version tags run: | @@ -42,6 +48,35 @@ 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: + - name: Checkout opendatahub.io + uses: actions/checkout@v4 + with: + repository: AjayJagan/opendatahub.io # Replace later with opendatahub/opendatahub.io + - uses: actions/create-github-app-token@v1 + id: generate-token + with: + app-id: ${{ secrets.APP_ID }} # Replace later with appropriate values + private-key: ${{ secrets.APP_PRIVATE_KEY }} # Replace later with appropriate values + owner: AjayJagan # # Replace later with opendatahub + repositories: opendatahub.io + - name: Update release-notes.md + 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 < + 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 <