From d82d88f840bf408c7b102b26ddc505f0501ccdc1 Mon Sep 17 00:00:00 2001 From: Levente Balogh Date: Tue, 14 Dec 2021 14:48:21 +0100 Subject: [PATCH] fix: use double-quote in shell script --- .github/workflows/detect-breaking-changes.yml | 76 +++++++++++-------- scripts/check-breaking-changes.sh | 2 +- 2 files changed, 45 insertions(+), 33 deletions(-) diff --git a/.github/workflows/detect-breaking-changes.yml b/.github/workflows/detect-breaking-changes.yml index 16b4e17859d..b4f92c57ca5 100644 --- a/.github/workflows/detect-breaking-changes.yml +++ b/.github/workflows/detect-breaking-changes.yml @@ -18,12 +18,6 @@ jobs: - name: Install Yarn run: npm install --global yarn - - name: Install dependencies - run: yarn install --immutable - - - name: Build packages - run: yarn packages:build - # We need this as we can only access the "Run ID" through the context and we need the "Job ID". - name: Get link for the Github Action job id: get-job-link @@ -38,6 +32,36 @@ jobs: return `https://github.com/grafana/grafana/runs/${result.data.jobs[0].id}?check_suite_focus=true`; + - name: Find current pull request ID + uses: jwalton/gh-find-current-pr@v1 + id: finder + + - 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 ? 1 : 0; + + - name: Debug + run: echo -e "Job link - ${{steps.get-job-link.outputs.result}} \nPull request - ${{steps.finder.outputs.pr}} \nLabel exists - ${{steps.does-label-exist.outputs.result}}" + + - name: Install dependencies + run: yarn install --immutable + + - name: Build packages + run: yarn packages:build + - name: Detect breaking changes id: breaking-changes run: ./scripts/check-breaking-changes.sh @@ -45,10 +69,6 @@ jobs: FORCE_COLOR: 3 GITHUB_JOB_LINK: ${{steps.get-job-link.outputs.result}} - - name: Find current pull request ID - uses: jwalton/gh-find-current-pr@v1 - id: finder - - name: Comment on PR if: ${{ steps.breaking-changes.outputs.is_breaking == 1 }} uses: marocchino/sticky-pull-request-comment@v2 @@ -70,25 +90,9 @@ jobs: number: ${{ steps.finder.outputs.pr }} delete: true - - 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 }} + if: ${{ steps.breaking-changes.outputs.is_breaking == 1 && steps.does-label-exist.outputs.result == 0 }} uses: actions/github-script@v5 env: PR_NUMBER: ${{ steps.finder.outputs.pr }} @@ -102,7 +106,7 @@ jobs: }) - name: Remove "breaking change" label - if: ${{ steps.breaking-changes.outputs.is_breaking == 0 && steps.does-label-exist.outputs.result == true }} + if: ${{ steps.breaking-changes.outputs.is_breaking == 0 && steps.does-label-exist.outputs.result == 1 }} uses: actions/github-script@v5 env: PR_NUMBER: ${{ steps.finder.outputs.pr }} @@ -115,6 +119,8 @@ jobs: name: 'breaking change' }) + # This is very weird, the actual request goes through (comes back with a 201), but does not assign the team. + # Related issue: https://github.com/renovatebot/renovate/issues/1908 - name: Add "grafana/plugins-platform-frontend" as a reviewer if: ${{ steps.breaking-changes.outputs.is_breaking == 1 }} uses: actions/github-script@v5 @@ -122,13 +128,16 @@ jobs: PR_NUMBER: ${{ steps.finder.outputs.pr }} with: script: | - github.rest.pulls.requestReviewers({ + const response = await github.rest.pulls.requestReviewers({ pull_number: process.env.PR_NUMBER, owner: context.repo.owner, repo: context.repo.repo, - reviewers: ['grafana/plugins-platform-frontend'] + reviewers: [], + team_reviewers: ['grafana/plugins-platform-frontend'] }) + console.log(response) + - name: Remove "grafana/plugins-platform-frontend" from the list of reviewers if: ${{ steps.breaking-changes.outputs.is_breaking == 0 }} uses: actions/github-script@v5 @@ -136,13 +145,16 @@ jobs: PR_NUMBER: ${{ steps.finder.outputs.pr }} with: script: | - github.rest.pulls.removeRequestedReviewers({ + const response = await github.rest.pulls.removeRequestedReviewers({ pull_number: process.env.PR_NUMBER, owner: context.repo.owner, repo: context.repo.repo, - reviewers: ['grafana/plugins-platform-frontend'] + reviewers: [], + team_reviewers: ['grafana/plugins-platform-frontend'] }) + console.log(response) + - name: Exit 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 b9f776a9ed6..26cd7e4bcbb 100755 --- a/scripts/check-breaking-changes.sh +++ b/scripts/check-breaking-changes.sh @@ -28,7 +28,7 @@ while IFS= read -r line; do echo "" echo "${PACKAGE_NAME}" echo "=================================================" - npm exec -- @grafana/levitate compare --prev $PREV --current $CURRENT + npm exec -- @grafana/levitate compare --prev "$PREV" --current "$CURRENT" # Check if the comparison returned with a non-zero exit code # Record the output, maybe with some additional information