From 3e6153244bf130f7b6819d84500164fd05e90d31 Mon Sep 17 00:00:00 2001 From: Alexander Dokuchaev Date: Fri, 23 Aug 2024 09:17:41 +0300 Subject: [PATCH] [GA] Fix set api label action (#2908) ### Changes Add pr number to artifact from api check ### Reason for changes `github.event.workflow_run.pull_requests[0].number` is not available for PR from fork --- .github/workflows/api_changes_check.yml | 11 +++++++---- .github/workflows/api_set_label.yml | 16 +++++++++------- 2 files changed, 16 insertions(+), 11 deletions(-) diff --git a/.github/workflows/api_changes_check.yml b/.github/workflows/api_changes_check.yml index e0222229af6..5815795f88c 100644 --- a/.github/workflows/api_changes_check.yml +++ b/.github/workflows/api_changes_check.yml @@ -44,18 +44,21 @@ jobs: - name: Add label if: ${{ contains(steps.diff.outputs.changed_files, 'differ') }} - run: echo "add" > api_status.txt + run: | + echo '{"pr_number": "${{ github.event.pull_request.number }}", "action": "add"}' > api_status.json - name: Remove label if: ${{ !(contains(steps.diff.outputs.changed_files, 'differ')) && contains(github.event.pull_request.labels.*.name, 'API') }} - run: echo "remove" > api_status.txt + run: | + echo '{"pr_number": "${{ github.event.pull_request.number }}", "action": "remove"}' > api_status.json - name: No change label if: ${{ !(contains(steps.diff.outputs.changed_files, 'differ')) && !contains(github.event.pull_request.labels.*.name, 'API') }} - run: echo "none" > api_status.txt + run: | + echo '{"pr_number": "${{ github.event.pull_request.number }}", "action": "none"}' > api_status.json - name: Upload artifact uses: actions/upload-artifact@v4 with: name: api_status - path: api_status.txt + path: api_status.json diff --git a/.github/workflows/api_set_label.yml b/.github/workflows/api_set_label.yml index 91580f2ca82..a6fc8214564 100644 --- a/.github/workflows/api_set_label.yml +++ b/.github/workflows/api_set_label.yml @@ -27,19 +27,21 @@ jobs: - name: Set output value id: status - run: echo "api_status=$(cat api_status.txt)" >> $GITHUB_OUTPUT + run: | + echo "action=$(cat api_status.json | jq -r .action)" >> $GITHUB_OUTPUT + echo "pr_number=$(cat api_status.json | jq -r .pr_number)" >> $GITHUB_OUTPUT - - name: Print api_status - run: echo ${{ steps.status.outputs.api_status }} + - name: Print outputs + run: echo ${{ steps.status.outputs.action }} ${{ steps.status.outputs.pr_number }} - name: Add label uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - if: ${{ steps.status.outputs.api_status == 'add' }} + if: ${{ steps.status.outputs.action == 'add' }} with: github-token: "${{ secrets.GITHUB_TOKEN }}" script: | github.rest.issues.addLabels({ - issue_number: ${{ github.event.workflow_run.pull_requests[0].number }}, + issue_number: ${{ steps.status.outputs.pr_number }}, owner: context.repo.owner, repo: context.repo.repo, labels: ["API"] @@ -47,12 +49,12 @@ jobs: - name: Remove label uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 - if: ${{ steps.status.outputs.api_status == 'remove' }} + if: ${{ steps.status.outputs.action == 'remove' }} with: github-token: ${{ secrets.GITHUB_TOKEN }} script: | github.rest.issues.addLabels({ - issue_number: ${{ github.event.workflow_run.pull_requests[0].number }}, + issue_number: ${{ steps.status.outputs.pr_number }}, owner: context.repo.owner, repo: context.repo.repo, labels: ["API"]