Skip to content

Commit

Permalink
use actions/labeler Action instead of tj-actions/changed-files & acti…
Browse files Browse the repository at this point in the history
…ons/github-script
  • Loading branch information
shota-kitazawa committed May 5, 2024
1 parent c0a9aaf commit cd5a434
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 37 deletions.
5 changes: 5 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
reviewapps:
- changed-files:
- all-globs-to-any-file:
- '!.github/**/*.yml'
- '!**/*.md'
41 changes: 4 additions & 37 deletions .github/workflows/add-labels.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,52 +3,19 @@ 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.
labeler:
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
- id: label-the-PR
uses: actions/labeler@v5
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]
});
}
repo-token: ${{ steps.generate_token.outputs.token }}

0 comments on commit cd5a434

Please sign in to comment.