-
Notifications
You must be signed in to change notification settings - Fork 11
CCM-18044 Adding a simple release notes page with automation #245
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
Open
aidenvaines-cgi
wants to merge
7
commits into
main
Choose a base branch
from
CCM-18044_AddingReleaseNotesMechanism
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
0336dd3
CCM-18044 Adding a simple release notes page with automation
aidenvaines-cgi cc4c200
CCM-18044 PR Fixes
aidenvaines-cgi 5b4226b
CCM-18044 Stakeholder Fixes
aidenvaines-cgi 4e2a746
CCM-18044 Stakeholder Fixes
aidenvaines-cgi b83ffe3
Merge branch 'main' into CCM-18044_AddingReleaseNotesMechanism
aidenvaines-cgi c9d3f6a
CCM-18044 Stakeholder Fixes
aidenvaines-cgi 6549e96
CCM-18044 PR Fixes
aidenvaines-cgi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| name: "Release notes sync" | ||
| description: "Fetch release notes data from JIRA and update the Jekyll data cache" | ||
| inputs: | ||
| output-file: | ||
| description: "Path to the generated release notes cache file" | ||
| required: false | ||
| default: "docs/_data/release-notes.json" | ||
| jql: | ||
| description: "JQL used to fetch release notes" | ||
| required: false | ||
| default: 'project = CCM AND "Release Notes" IS NOT EMPTY AND fixVersion IS NOT EMPTY AND updated >= -365d' | ||
| max-results: | ||
| description: "Maximum JIRA issues to fetch per page" | ||
| required: false | ||
| default: "50" | ||
| project-key: | ||
| description: "JIRA project key used to look up fix version release dates" | ||
| required: false | ||
| default: "CCM" | ||
|
|
||
| runs: | ||
| using: "composite" | ||
| steps: | ||
| - name: "Fetch release notes cache" | ||
| env: | ||
| RELEASE_NOTES_CACHE_FILE: "${{ inputs.output-file }}" | ||
| RELEASE_NOTES_JQL: "${{ inputs.jql }}" | ||
| RELEASE_NOTES_MAX_RESULTS: "${{ inputs.max-results }}" | ||
| RELEASE_NOTES_PROJECT_KEY: "${{ inputs.project-key }}" | ||
| shell: bash | ||
| run: | | ||
| node ./.github/actions/release-notes/fetch-release-notes.js |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,305 @@ | ||
| #!/usr/bin/env node | ||
|
|
||
| const fs = require('node:fs'); | ||
| const path = require('node:path'); | ||
|
|
||
| const DEFAULT_RELEASE_NOTES_JQL = 'project = CCM AND "Release Notes" IS NOT EMPTY AND fixVersion IS NOT EMPTY AND updated >= -365d'; | ||
| const DEFAULT_RELEASE_NOTES_CACHE_FILE = 'docs/_data/release-notes.json'; | ||
| const DEFAULT_RELEASE_NOTES_MAX_RESULTS = 50; | ||
| const DEFAULT_RELEASE_NOTES_PROJECT_KEY = 'CCM'; | ||
|
|
||
| async function main() { | ||
| const repoRoot = process.cwd(); | ||
| const outputFile = process.env.RELEASE_NOTES_CACHE_FILE || DEFAULT_RELEASE_NOTES_CACHE_FILE; | ||
| const jiraBaseUrl = resolveJiraBaseUrl(); | ||
|
|
||
| if (!jiraBaseUrl) { | ||
| throw new Error('Set JIRA_BASE_URL or JIRA_URL before running the release notes sync.'); | ||
| } | ||
|
|
||
| const releaseNotesJql = process.env.RELEASE_NOTES_JQL || DEFAULT_RELEASE_NOTES_JQL; | ||
| const maxResults = Number.parseInt(process.env.RELEASE_NOTES_MAX_RESULTS || String(DEFAULT_RELEASE_NOTES_MAX_RESULTS), 10); | ||
| const releaseNotesProjectKey = process.env.RELEASE_NOTES_PROJECT_KEY || DEFAULT_RELEASE_NOTES_PROJECT_KEY; | ||
| const startedAt = new Date(); | ||
|
|
||
| if (!Number.isInteger(maxResults) || maxResults <= 0) { | ||
| throw new Error('RELEASE_NOTES_MAX_RESULTS must be a positive integer.'); | ||
| } | ||
|
|
||
| if (!process.env.JIRA_TOKEN && !process.env.JIRA_AUTH_HEADER) { | ||
| throw new Error('Set JIRA_TOKEN or JIRA_AUTH_HEADER before running the release notes sync.'); | ||
| } | ||
|
|
||
| fs.mkdirSync(path.dirname(path.resolve(repoRoot, outputFile)), { recursive: true }); | ||
|
|
||
| console.log(`Fetching release notes from ${jiraBaseUrl}`); | ||
|
|
||
| // Look up the custom field ID once so the search request can read release notes text. | ||
| const fields = await requestFields(jiraBaseUrl); | ||
| const releaseNotesFieldId = resolveReleaseNotesFieldId(fields); | ||
| const projectVersions = await requestProjectVersions(jiraBaseUrl, releaseNotesProjectKey); | ||
| const releaseDatesByName = buildReleaseDateMap(projectVersions); | ||
|
|
||
| console.log(`Resolved Release Notes field: ${releaseNotesFieldId}`); | ||
|
|
||
| const issuesByKey = new Map(); | ||
| let startAt = 0; | ||
| let pageNumber = 1; | ||
| let total = 0; | ||
|
|
||
| while (true) { | ||
| // Fetch one page of JIRA issues at a time until we have them all. | ||
| const payload = await requestSearch({ | ||
| jiraBaseUrl, | ||
| releaseNotesFieldId, | ||
| jql: releaseNotesJql, | ||
| startAt, | ||
| maxResults, | ||
| }); | ||
|
|
||
| total = Number(payload.total || 0); | ||
| const pageIssues = Array.isArray(payload.issues) ? payload.issues : []; | ||
| console.log(`Fetched page ${pageNumber} with ${pageIssues.length} issue(s)`); | ||
|
|
||
| for (const rawIssue of pageIssues) { | ||
| const issue = normalizeIssue(rawIssue, releaseNotesFieldId); | ||
| if (issue) { | ||
| issuesByKey.set(issue.key, issue); | ||
| } | ||
| } | ||
|
|
||
| if (pageIssues.length === 0 || issuesByKey.size >= total) { | ||
| break; | ||
| } | ||
|
|
||
| startAt += maxResults; | ||
| pageNumber += 1; | ||
| } | ||
|
|
||
| const output = { | ||
| releases: groupIssuesByFixVersion(Array.from(issuesByKey.values()), releaseDatesByName), | ||
| }; | ||
|
|
||
| fs.writeFileSync(path.resolve(repoRoot, outputFile), `${JSON.stringify(output, null, 2)}\n`, 'utf8'); | ||
| console.log(`Updated release notes cache at ${outputFile}`); | ||
| } | ||
|
|
||
| async function requestFields(jiraBaseUrl) { | ||
| return fetchJson(`${jiraBaseUrl}/field`); | ||
| } | ||
|
|
||
| async function requestProjectVersions(jiraBaseUrl, projectKey) { | ||
| const encodedProjectKey = encodeURIComponent(projectKey); | ||
| return fetchJson(`${jiraBaseUrl}/project/${encodedProjectKey}/versions`); | ||
| } | ||
|
|
||
| async function requestSearch({ | ||
| jiraBaseUrl, | ||
| releaseNotesFieldId, | ||
| jql, | ||
| startAt, | ||
| maxResults, | ||
| }) { | ||
| const url = new URL(`${jiraBaseUrl}/search`); | ||
| url.searchParams.set('jql', jql); | ||
| url.searchParams.set('fields', `summary,fixVersions,issuetype,updated,${releaseNotesFieldId}`); | ||
| url.searchParams.set('startAt', String(startAt)); | ||
| url.searchParams.set('maxResults', String(maxResults)); | ||
|
|
||
| return fetchJson(url.toString()); | ||
| } | ||
|
|
||
| async function fetchJson(url) { | ||
| const response = await fetch(url, { | ||
| method: 'GET', | ||
| headers: buildHeaders(), | ||
| }); | ||
|
|
||
| if (!response.ok) { | ||
| throw new Error(`JIRA request failed with status ${response.status} ${response.statusText}`); | ||
| } | ||
|
|
||
| return response.json(); | ||
| } | ||
|
|
||
| function buildHeaders() { | ||
| const headers = { | ||
| Accept: 'application/json', | ||
| }; | ||
|
|
||
| if (process.env.JIRA_AUTH_HEADER && process.env.JIRA_AUTH_HEADER.trim()) { | ||
| const header = process.env.JIRA_AUTH_HEADER; | ||
| const index = header.indexOf(':'); | ||
| if (index <= 0) { | ||
| throw new Error('JIRA_AUTH_HEADER must be in the format "Header-Name: value".'); | ||
| } | ||
| headers[header.slice(0, index).trim()] = header.slice(index + 1).trim(); | ||
| return headers; | ||
| } | ||
|
|
||
| headers.Authorization = `Bearer ${process.env.JIRA_TOKEN}`; | ||
| return headers; | ||
| } | ||
|
|
||
| function resolveReleaseNotesFieldId(fields) { | ||
| const match = fields.find((field) => String(field.name || '').trim().toLowerCase() === 'release notes'); | ||
| if (!match || !match.id) { | ||
| throw new Error("Unable to resolve the JIRA field named 'Release Notes'."); | ||
| } | ||
| return match.id; | ||
| } | ||
|
|
||
| function buildReleaseDateMap(versions) { | ||
| const releaseDatesByName = new Map(); | ||
|
|
||
| if (!Array.isArray(versions)) { | ||
| return releaseDatesByName; | ||
| } | ||
|
|
||
| for (const version of versions) { | ||
| const name = String(version && version.name ? version.name : '').trim(); | ||
| const releaseDate = String(version && version.releaseDate ? version.releaseDate : '').trim(); | ||
|
|
||
| if (name && releaseDate) { | ||
| releaseDatesByName.set(name, releaseDate); | ||
| } | ||
| } | ||
|
|
||
| return releaseDatesByName; | ||
| } | ||
|
|
||
| function normalizeIssue(issue, releaseNotesFieldId) { | ||
| const fields = issue && typeof issue === 'object' ? issue.fields || {} : {}; | ||
| const fixVersions = Array.isArray(fields.fixVersions) | ||
| ? fields.fixVersions | ||
| .map((version) => String(version && version.name ? version.name : '').trim()) | ||
| .filter(Boolean) | ||
| : []; | ||
| const releaseNotes = extractText(fields[releaseNotesFieldId]); | ||
| // Keep only the fields needed by the generated JSON. | ||
| const normalized = { | ||
| key: String(issue && issue.key ? issue.key : '').trim(), | ||
| fix_versions: fixVersions, | ||
| release_notes: releaseNotes, | ||
| }; | ||
|
|
||
| if (!normalized.key || !normalized.release_notes || normalized.fix_versions.length === 0) { | ||
| return null; | ||
| } | ||
|
|
||
| return normalized; | ||
| } | ||
|
|
||
| function resolveJiraBaseUrl() { | ||
| if (process.env.JIRA_BASE_URL && process.env.JIRA_BASE_URL.trim()) { | ||
| return process.env.JIRA_BASE_URL.replace(/\/$/, ''); | ||
| } | ||
|
|
||
| if (process.env.JIRA_URL && process.env.JIRA_URL.trim()) { | ||
| return `${process.env.JIRA_URL.replace(/\/$/, '')}/rest/api/2`; | ||
| } | ||
|
|
||
| return ''; | ||
| } | ||
|
|
||
| function extractText(value) { | ||
| if (value === null || value === undefined) { | ||
| return ''; | ||
| } | ||
|
|
||
| if (typeof value === 'string') { | ||
| return value.trim(); | ||
| } | ||
|
|
||
| if (Array.isArray(value)) { | ||
| return value.map(extractText).filter(Boolean).join('\n').trim(); | ||
| } | ||
|
|
||
| if (typeof value === 'object') { | ||
| if (typeof value.text === 'string') { | ||
| return value.text.trim(); | ||
| } | ||
| if (Array.isArray(value.content)) { | ||
| return value.content | ||
| .map(extractText) | ||
| .filter(Boolean) | ||
| .join('\n') | ||
| .replace(/\n{3,}/g, '\n\n') | ||
| .trim(); | ||
| } | ||
| } | ||
|
|
||
| return String(value).trim(); | ||
| } | ||
|
|
||
| function groupIssuesByFixVersion(issues, releaseDatesByName) { | ||
| const releases = new Map(); | ||
|
|
||
| for (const issue of issues) { | ||
| // Group each issue under every fix version it belongs to. | ||
| for (const fixVersion of issue.fix_versions) { | ||
| if (!releases.has(fixVersion)) { | ||
| releases.set(fixVersion, []); | ||
| } | ||
| releases.get(fixVersion).push({ | ||
| key: issue.key, | ||
| release_notes: issue.release_notes, | ||
| }); | ||
| } | ||
| } | ||
|
|
||
| return Array.from(releases, ([rawName, items]) => ({ | ||
| name: formatReleaseName(rawName), | ||
| jira_name: rawName, | ||
| release_date: releaseDatesByName.get(rawName) || null, | ||
| items, | ||
| })).sort(compareReleasesByDateDesc); | ||
| } | ||
|
|
||
| function compareReleasesByDateDesc(left, right) { | ||
| const leftDate = left.release_date ? Date.parse(left.release_date) : Number.NaN; | ||
| const rightDate = right.release_date ? Date.parse(right.release_date) : Number.NaN; | ||
| const leftHasDate = Number.isFinite(leftDate); | ||
| const rightHasDate = Number.isFinite(rightDate); | ||
|
|
||
| if (leftHasDate && rightHasDate && leftDate !== rightDate) { | ||
| return rightDate - leftDate; | ||
| } | ||
|
|
||
| if (leftHasDate && !rightHasDate) { | ||
| return -1; | ||
| } | ||
|
|
||
| if (!leftHasDate && rightHasDate) { | ||
| return 1; | ||
| } | ||
|
|
||
| return right.name.localeCompare(left.name, undefined, { | ||
| numeric: true, | ||
| sensitivity: 'base', | ||
| }); | ||
| } | ||
|
|
||
| function formatReleaseName(name) { | ||
| const trimmedName = String(name || '').trim(); | ||
|
|
||
| // Jira names prefixed with "Release" are displayed as "Core". | ||
| if (/^release\s+/i.test(trimmedName)) { | ||
| return trimmedName.replace(/^release\s+/i, 'Core '); | ||
| } | ||
|
|
||
| // Reformat kebab-case names (e.g. digital-letters-0.0.0 → Digital Letters 0.0.0). | ||
| if (!trimmedName.includes('-') || trimmedName.includes(' ')) { | ||
| return trimmedName; | ||
| } | ||
|
|
||
| return trimmedName | ||
| .split('-') | ||
| .map((part) => part.charAt(0).toUpperCase() + part.slice(1)) | ||
| .join(' '); | ||
| } | ||
|
|
||
| main().catch((error) => { | ||
| console.error(error.message || error); | ||
| process.exit(1); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| name: "Release notes sync" | ||
|
|
||
| on: | ||
| workflow_dispatch: | ||
| schedule: | ||
| - cron: "0 6 * * 1" | ||
|
|
||
| permissions: | ||
| contents: write | ||
| pull-requests: write | ||
|
|
||
| jobs: | ||
| sync-release-notes: | ||
| name: "Sync release notes" | ||
| runs-on: ubuntu-latest | ||
| timeout-minutes: 10 | ||
| steps: | ||
| - name: "Checkout code" | ||
| uses: actions/checkout@v4 | ||
|
|
||
| - name: "Update release notes data" | ||
| uses: ./.github/actions/release-notes | ||
| env: | ||
| JIRA_TOKEN: "${{ secrets.JIRA_TOKEN }}" | ||
| JIRA_BASE_URL: "${{ secrets.JIRA_URL }}/rest/api/2" | ||
|
|
||
| - name: "Detect release notes changes" | ||
| id: changes | ||
| shell: bash | ||
| run: | | ||
| if git diff --quiet -- docs/_data/release-notes.json; then | ||
| echo "has_changes=false" >> "$GITHUB_OUTPUT" | ||
| else | ||
| echo "has_changes=true" >> "$GITHUB_OUTPUT" | ||
| fi | ||
|
|
||
| - name: "Create pull request" | ||
| if: steps.changes.outputs.has_changes == 'true' | ||
| uses: peter-evans/create-pull-request@5f6978faf089d4d20b00c7766989d076bb2fc7f1 # v8.1.1 | ||
Check failureCode scanning / SonarCloud External GitHub Actions and workflows should be pinned to a commit hash High
Use full commit SHA hash for this dependency. See more on SonarQube Cloud
|
||
| with: | ||
| token: "${{ secrets.GITHUB_TOKEN }}" | ||
| branch: "automation/release-notes-cache" | ||
| delete-branch: true | ||
| commit-message: "sync release notes" | ||
| title: "CCM-18043: Sync release notes" | ||
| body: | | ||
| ## Summary | ||
|
|
||
| This PR syncs the release notes generated from JIRA for the last year. | ||
|
|
||
| - Trigger: `${{ github.event_name }}` | ||
| - Source: `JIRA_URL secret (expanded to REST API base path)` | ||
| add-paths: | | ||
| docs/_data/release-notes.json | ||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This code has not been covered by Sonar Analysis - https://sonarcloud.io/code?id=NHSDigital_nhs-notify-web-cms&branch=CCM-18044_AddingReleaseNotesMechanism&selected=NHSDigital_nhs-notify-web-cms%3A.github%2Factions%2Frelease-notes