Skip to content

Commit

Permalink
[GA] Fix set api label action (#2908)
Browse files Browse the repository at this point in the history
### 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
  • Loading branch information
AlexanderDokuchaev authored Aug 23, 2024
1 parent 7c19980 commit 3e61532
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 11 deletions.
11 changes: 7 additions & 4 deletions .github/workflows/api_changes_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
16 changes: 9 additions & 7 deletions .github/workflows/api_set_label.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,32 +27,34 @@ 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"]
})
- 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"]
Expand Down

0 comments on commit 3e61532

Please sign in to comment.