diff --git a/.github/workflows/detect-breaking-changes.yml b/.github/workflows/detect-breaking-changes.yml index 0a1bb17533a..16b4e17859d 100644 --- a/.github/workflows/detect-breaking-changes.yml +++ b/.github/workflows/detect-breaking-changes.yml @@ -39,6 +39,7 @@ jobs: return `https://github.com/grafana/grafana/runs/${result.data.jobs[0].id}?check_suite_focus=true`; - name: Detect breaking changes + id: breaking-changes run: ./scripts/check-breaking-changes.sh env: FORCE_COLOR: 3 @@ -49,7 +50,7 @@ jobs: id: finder - name: Comment on PR - if: ${{ env.BREAKING_CHANGES_IS_BREAKING == '1' || env.BREAKING_CHANGES_IS_BREAKING == 1 }} + if: ${{ steps.breaking-changes.outputs.is_breaking == 1 }} uses: marocchino/sticky-pull-request-comment@v2 with: number: ${{ steps.finder.outputs.pr }} @@ -58,18 +59,36 @@ jobs: _(Open the links below in a new tab to go to the correct steps)_ - ${{ env.BREAKING_CHANGES_MESSAGE }} + ${{ steps.breaking-changes.outputs.message }} [Check console output](${{steps.get-job-link.outputs.result}}) - name: Remove comment on PR - if: ${{ env.BREAKING_CHANGES_IS_BREAKING == '0' || env.BREAKING_CHANGES_IS_BREAKING == 0 }} + if: ${{ steps.breaking-changes.outputs.is_breaking == 0 }} uses: marocchino/sticky-pull-request-comment@v2 with: + number: ${{ steps.finder.outputs.pr }} delete: true - - name: Add label (if there are breaking changes) - if: ${{ env.BREAKING_CHANGES_IS_BREAKING == '1' || env.BREAKING_CHANGES_IS_BREAKING == 1 }} + - name: Check if "breaking change" label exists + id: does-label-exist + uses: actions/github-script@v5 + env: + PR_NUMBER: ${{ steps.finder.outputs.pr }} + with: + script: | + const { data } = await github.rest.issues.listLabelsOnIssue({ + issue_number: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + }); + const labels = data.map(({ name }) => name); + const doesExist = labels.includes('breaking change'); + + return doesExist; + + - name: Add "breaking change" label + if: ${{ steps.breaking-changes.outputs.is_breaking == 1 && steps.does-label-exist.outputs.result == false }} uses: actions/github-script@v5 env: PR_NUMBER: ${{ steps.finder.outputs.pr }} @@ -82,25 +101,49 @@ jobs: labels: ['breaking change'] }) - - name: Remove label (if there are breaking changes) - if: ${{ env.BREAKING_CHANGES_IS_BREAKING == '0' || env.BREAKING_CHANGES_IS_BREAKING == 0 }} + - name: Remove "breaking change" label + if: ${{ steps.breaking-changes.outputs.is_breaking == 0 && steps.does-label-exist.outputs.result == true }} uses: actions/github-script@v5 env: PR_NUMBER: ${{ steps.finder.outputs.pr }} with: script: | - try { - github.rest.issues.removeLabel({ - issue_number: process.env.PR_NUMBER, - owner: context.repo.owner, - repo: context.repo.repo, - name: 'breaking change' - }) - } catch () { - console.log('"breaking change" label does not exist on the PR.') - } + github.rest.issues.removeLabel({ + issue_number: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + name: 'breaking change' + }) + + - name: Add "grafana/plugins-platform-frontend" as a reviewer + if: ${{ steps.breaking-changes.outputs.is_breaking == 1 }} + uses: actions/github-script@v5 + env: + PR_NUMBER: ${{ steps.finder.outputs.pr }} + with: + script: | + github.rest.pulls.requestReviewers({ + pull_number: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + reviewers: ['grafana/plugins-platform-frontend'] + }) + + - name: Remove "grafana/plugins-platform-frontend" from the list of reviewers + if: ${{ steps.breaking-changes.outputs.is_breaking == 0 }} + uses: actions/github-script@v5 + env: + PR_NUMBER: ${{ steps.finder.outputs.pr }} + with: + script: | + github.rest.pulls.removeRequestedReviewers({ + pull_number: process.env.PR_NUMBER, + owner: context.repo.owner, + repo: context.repo.repo, + reviewers: ['grafana/plugins-platform-frontend'] + }) - name: Exit - run: exit ${{ env.BREAKING_CHANGES_IS_BREAKING }} + run: exit ${{ steps.breaking-changes.outputs.is_breaking }} shell: bash diff --git a/scripts/check-breaking-changes.sh b/scripts/check-breaking-changes.sh index a0b1cc63581..b9f776a9ed6 100755 --- a/scripts/check-breaking-changes.sh +++ b/scripts/check-breaking-changes.sh @@ -11,7 +11,6 @@ while IFS= read -r line; do IFS=':' read -ra ADDR <<< "$line" PACKAGE_PATH="${ADDR[0]}" PACKAGE_NAME="${ADDR[1]}" - PACKAGE_VERSION="${ADDR[2]}" # Calculate current and previous package paths / names PREV="$PACKAGE_NAME@canary" @@ -46,8 +45,8 @@ while IFS= read -r line; do done <<< "$PACKAGES" # "Export" the message to an environment variable that can be used across Github Actions steps -echo "BREAKING_CHANGES_IS_BREAKING=$EXIT_CODE" >> $GITHUB_ENV -echo "BREAKING_CHANGES_MESSAGE=$GITHUB_MESSAGE" >> $GITHUB_ENV +echo "::set-output name=is_breaking::$EXIT_CODE" +echo "::set-output name=message::$GITHUB_MESSAGE" # We will exit the workflow accordingly at another step exit 0 \ No newline at end of file