From 45c0d5d752f31b2a248b0f03dd7e6932772e3c9d Mon Sep 17 00:00:00 2001 From: shota-kitazawa Date: Sun, 5 May 2024 16:36:19 +0900 Subject: [PATCH] use actions/labeler Action instead of add-labels workflow --- .github/labeler.yml | 5 +++ .github/workflows/add-labels.yml | 54 -------------------------------- .github/workflows/labeler.yml | 21 +++++++++++++ 3 files changed, 26 insertions(+), 54 deletions(-) create mode 100644 .github/labeler.yml delete mode 100644 .github/workflows/add-labels.yml create mode 100644 .github/workflows/labeler.yml diff --git a/.github/labeler.yml b/.github/labeler.yml new file mode 100644 index 000000000..3c8cfd9bc --- /dev/null +++ b/.github/labeler.yml @@ -0,0 +1,5 @@ +reviewapps: + - changed-files: + - all-globs-to-any-file: + - '!.github/**/*.yml' + - '!**/*.md' diff --git a/.github/workflows/add-labels.yml b/.github/workflows/add-labels.yml deleted file mode 100644 index 933cec5ce..000000000 --- a/.github/workflows/add-labels.yml +++ /dev/null @@ -1,54 +0,0 @@ -name: add labels for some cases - -on: pull_request - -jobs: - reviewapps: - name: grant 'reviewapps' label if there are any changes in PR's source code. - runs-on: ubuntu-latest # windows-latest | macos-latest - if: ${{ ! startsWith(github.head_ref, 'renovate/') }} - steps: - - uses: actions/checkout@v4 - - - name: Get changed files - id: check-paths-ignore - uses: tj-actions/changed-files@v42 - with: - files_ignore: | - .github/**/*.yml - **.md - - # to trigger other Actions caused by adding reviewapp Label - - name: Generate token - if: steps.check-paths-ignore.outputs.any_changed == 'true' - id: generate_token - uses: tibdex/github-app-token@v2 - with: - app_id: ${{ secrets.APP_ID }} - private_key: ${{ secrets.PRIVATE_KEY }} - - - name: Labeling 'reviewapps' to PR - if: steps.check-paths-ignore.outputs.any_changed == 'true' - uses: actions/github-script@v7 - with: - github-token: ${{ steps.generate_token.outputs.token }} - result-encoding: string - script: | - const targetLabel = 'reviewapps'; - issue = await github.rest.issues.get({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - }); - flag = false; - issue.data.labels.filter(label => { - if (label.name == targetLabel) { flag = true; }; - }); - if (!flag) { - github.rest.issues.addLabels({ - owner: context.repo.owner, - repo: context.repo.repo, - issue_number: context.issue.number, - labels: [targetLabel] - }); - } diff --git a/.github/workflows/labeler.yml b/.github/workflows/labeler.yml new file mode 100644 index 000000000..ed8525606 --- /dev/null +++ b/.github/workflows/labeler.yml @@ -0,0 +1,21 @@ +name: add labels for some cases + +on: pull_request + +jobs: + labeler: + runs-on: ubuntu-latest # windows-latest | macos-latest + if: ${{ ! startsWith(github.head_ref, 'renovate/') }} + steps: + # to trigger other Actions caused by adding reviewapp Label + - name: Generate token + id: generate_token + uses: tibdex/github-app-token@v2 + with: + app_id: ${{ secrets.APP_ID }} + private_key: ${{ secrets.PRIVATE_KEY }} + + - id: label-the-PR + uses: actions/labeler@v5 + with: + repo-token: ${{ steps.generate_token.outputs.token }}