diff --git a/.github/workflows/check-issue-number.yml b/.github/workflows/check-issue-number.yml new file mode 100644 index 0000000000..2c834c9d0c --- /dev/null +++ b/.github/workflows/check-issue-number.yml @@ -0,0 +1,21 @@ +# Checks Release Notes in the PR description, runs when: +# opened - PR is opened +# edited - The title/description are changed +# synchronize - New commits appeared. +# We don't use the new content, but we still need to mark this commit Green/Red in GitHub UI + +name: Check YouTrack issue number in the description +on: + pull_request: + types: [opened, edited, synchronize] + +jobs: + check: + runs-on: ubuntu-24.04 + steps: + - uses: actions/checkout@v4 + with: + sparse-checkout: 'tools/changelog/check-issue-number-github-action' + - uses: ./tools/changelog/check-issue-number-github-action + with: + checkout_ref: ${{ github.ref }} diff --git a/tools/changelog/changelog.main.kts b/tools/changelog/changelog.main.kts index af2416a6a4..843cdc491a 100644 --- a/tools/changelog/changelog.main.kts +++ b/tools/changelog/changelog.main.kts @@ -22,6 +22,13 @@ * kotlin changelog.main.kts action=checkPr prDescription.txt * ``` * + * ## Checking YouTrack reference in a file + * Not supposed to be called manually, used by GitHub workflow: + * https://github.com/JetBrains/compose-multiplatform/blob/master/tools/changelog/check-issue-number-github-action/action.yml) + * ``` + * kotlin changelog.main.kts action=checkIssueNumber prDescription.txt + * ``` + * * compose-multiplatform - name of the GitHub repo * 5202 - PR number * @@ -85,6 +92,7 @@ println() when (argsKeyToValue["action"]) { "checkPr" -> checkPr() + "checkIssueNumber" -> checkIssueNumber() else -> generateChangelog() } @@ -312,6 +320,29 @@ fun checkPr() { } } +fun checkIssueNumber() { + val filePath = argsKeyless.getOrNull(0) ?: error("Please specify a file that contains PR description as the first argument") + + val body = File(filePath).readLines() + + if (body.any { it == "No related YouTrack issue" }) { + println("Author explicitly acknowledged YouTrack issue is missing") + } else { + val regexes = listOf( + Regex("^Fixes CMP-(\\d*)$"), + Regex("^Fixes https://youtrack.jetbrains.com/issue/CMP-(\\d*)$"), + Regex("^Fixes \\[CMP-(\\d*)\\](https://youtrack.jetbrains.com/issue/CMP-(\\d*))$"), + ) + val fixes = body.filter { + regexes.any{ r -> it.matches(r) } + } + if (fixes.isEmpty()) { + println("No YouTrack issue is mentioned in the PR description") + exitProcess(1) + } + } +} + /** * September 2024 */ diff --git a/tools/changelog/check-issue-number-github-action/action.yml b/tools/changelog/check-issue-number-github-action/action.yml new file mode 100644 index 0000000000..9f2936f2a9 --- /dev/null +++ b/tools/changelog/check-issue-number-github-action/action.yml @@ -0,0 +1,26 @@ +# Reusable GitHub action needed to check YouTrack issue number in the PR description. Used by multiple Compose repositories. + +name: Check YouTrack issue number in the description + +inputs: + checkout_ref: + type: string + default: 'master' + +runs: + using: "composite" + steps: + - uses: actions/checkout@v4 + with: + repository: JetBrains/compose-multiplatform + ref: ${{ inputs.checkout_ref }} + sparse-checkout: 'tools/changelog' + - name: Check YouTrack issue number in the description + shell: bash + env: + # To avoid injections as suggested in https://docs.github.com/en/actions/security-for-github-actions/security-guides/security-hardening-for-github-actions#using-an-intermediate-environment-variable + PR_DESCRIPTION: ${{ github.event.pull_request.body }} + run: | + cd tools/changelog + echo "$PR_DESCRIPTION" > prDescription.txt + kotlin changelog.main.kts action=checkIssueNumber prDescription.txt token=""