From df9bb5375f323e492342989b430777c6d9ad2146 Mon Sep 17 00:00:00 2001 From: HeshamHM28 Date: Tue, 8 Apr 2025 15:15:31 +0200 Subject: [PATCH 1/3] Add PR labeler workflow to label PRs modifying workflows --- .github/workflows/label-workflow-changes.yml | 55 ++++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 .github/workflows/label-workflow-changes.yml diff --git a/.github/workflows/label-workflow-changes.yml b/.github/workflows/label-workflow-changes.yml new file mode 100644 index 000000000..71cf83e7b --- /dev/null +++ b/.github/workflows/label-workflow-changes.yml @@ -0,0 +1,55 @@ +name: PR Labeler + +on: + pull_request_target: + paths: + - ".github/workflows/**" + types: [opened, synchronize, reopened] + +jobs: + label-workflow-changes: + runs-on: ubuntu-latest + permissions: + pull-requests: write + steps: + - name: Label PR with workflow changes + uses: actions/github-script@v6 + with: + script: | + const labelName = 'workflow-modified'; + + // Check if the label exists + try { + const labels = await github.rest.issues.listLabelsForRepo({ + owner: context.repo.owner, + repo: context.repo.repo + }); + + const labelExists = labels.data.some(label => label.name === labelName); + + if (!labelExists) { + // Create the label if it doesn't exist + await github.rest.issues.createLabel({ + owner: context.repo.owner, + repo: context.repo.repo, + name: labelName, + color: '#f9d0c4', + description: 'This PR modifies GitHub Actions workflows' + }); + console.log(`Label "${labelName}" created`); + } else { + console.log(`Label "${labelName}" already exists`); + } + } catch (error) { + console.error(`Failed to check or create label: ${error.message}`); + throw error; + } + + // Add the label to the PR + await github.rest.issues.addLabels({ + issue_number: context.issue.number, + owner: context.repo.owner, + repo: context.repo.repo, + labels: [labelName] + }); + console.log(`Label "${labelName}" added to the PR.`); From aea9d97f1b8f108d2e9476f891e495048d587132 Mon Sep 17 00:00:00 2001 From: HeshamHM28 Date: Tue, 8 Apr 2025 17:44:23 +0200 Subject: [PATCH 2/3] Switch from `pull_request_target` to `pull_request` --- .github/workflows/label-workflow-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-workflow-changes.yml b/.github/workflows/label-workflow-changes.yml index 71cf83e7b..3d2eb5113 100644 --- a/.github/workflows/label-workflow-changes.yml +++ b/.github/workflows/label-workflow-changes.yml @@ -1,7 +1,7 @@ name: PR Labeler on: - pull_request_target: + pull_request: paths: - ".github/workflows/**" types: [opened, synchronize, reopened] From 111366f17306e7fb4436e7c12eed2b83a1657063 Mon Sep 17 00:00:00 2001 From: HeshamHM28 Date: Tue, 8 Apr 2025 17:47:33 +0200 Subject: [PATCH 3/3] Fix label color format --- .github/workflows/label-workflow-changes.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/label-workflow-changes.yml b/.github/workflows/label-workflow-changes.yml index 3d2eb5113..1738c5309 100644 --- a/.github/workflows/label-workflow-changes.yml +++ b/.github/workflows/label-workflow-changes.yml @@ -33,7 +33,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, name: labelName, - color: '#f9d0c4', + color: 'f9d0c4', description: 'This PR modifies GitHub Actions workflows' }); console.log(`Label "${labelName}" created`);