Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[GA] Add Set api label action #2900

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 16 additions & 20 deletions .github/workflows/api_changes_check.yml
Original file line number Diff line number Diff line change
Expand Up @@ -41,25 +41,21 @@ jobs:
echo ${CHANGED_FILES}
CHANGED_FILES=$(echo $CHANGED_FILES | tr '\n' ' ')
echo "changed_files=${CHANGED_FILES}" >> $GITHUB_OUTPUT
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ !(contains(steps.diff.outputs.changed_files, 'differ')) && contains(github.event.pull_request.labels.*.name, 'API') }}
with:
github-token: ${{ secrets.ADD_LABELS_WITH_REST_API }}
script: |
github.rest.issues.removeLabel({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
name: "API"
})
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1

- name: Add label
if: ${{ contains(steps.diff.outputs.changed_files, 'differ') }}
run: echo "add" > api_status.txt

- 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

- 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

- name: Upload artifact
uses: actions/upload-artifact@v4
with:
github-token: ${{ secrets.ADD_LABELS_WITH_REST_API }}
script: |
github.rest.issues.addLabels({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["API"]
})
name: api_status
path: api_status.txt
59 changes: 59 additions & 0 deletions .github/workflows/api_set_label.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
name: Set API label
permissions: read-all

on:
workflow_run:
workflows: ["API changes check"]
types:
- completed

jobs:
update_labels:
runs-on: ubuntu-latest

permissions:
pull-requests: write

steps:
- name: Download artifact
id: download-artifact
uses: dawidd6/action-download-artifact@bf251b5aa9c2f7eeb574a96ee720e24f801b7c11 # v6
with:
run_id: ${{ github.event.workflow_run.id }}
name: api_status

- name: Get api_status
run: cat api_status.txt

- name: Set output value
id: status
run: echo "api_status=$(cat api_status.txt)" >> $GITHUB_OUTPUT

- name: Print api_status
run: echo ${{ steps.status.outputs.api_status }}

- name: Add label
uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
if: ${{ steps.status.outputs.api_status == 'add' }}
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
script: |
github.rest.issues.addLabels({
issue_number: ${{ github.event.workflow_run.pull_requests[0].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' }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
github.rest.issues.addLabels({
issue_number: ${{ github.event.workflow_run.pull_requests[0].number }},
owner: context.repo.owner,
repo: context.repo.repo,
labels: ["API"]
})
Loading