From 5b4aff5823f2dfd4af94dd35bd8a7ccd9505c1af Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 27 Sep 2025 10:36:36 +0700 Subject: [PATCH 1/3] ci: trigger package dependends on issue comment --- .../workflows/package-dependends-trigger.yml | 86 +++++++++++++++++++ 1 file changed, 86 insertions(+) create mode 100644 .github/workflows/package-dependends-trigger.yml diff --git a/.github/workflows/package-dependends-trigger.yml b/.github/workflows/package-dependends-trigger.yml new file mode 100644 index 0000000..954f90f --- /dev/null +++ b/.github/workflows/package-dependends-trigger.yml @@ -0,0 +1,86 @@ +name: Package Dependends Trigger + +on: + pull_request_target: + types: [labeled, opened, reopened, synchronize] + +permissions: + pull-requests: write + contents: read + +jobs: + comment-package-dependends-on-issue: + name: Comment package dependends on issue + runs-on: ubuntu-latest + if: "${{ (github.event.action != 'labeled' || github.event.label.name == 'Trigger: Find Dependents') && github.repository_owner == 'e18e' }}" + steps: + - name: Get issue title & description + id: issue + shell: bash + run: | + content=$(gh issue view ${{ github.event.pull_request.number }} --json title,body) + title=$(echo "$content" | jq -r .title) + description=$(echo "$content" | jq -r .body) + echo "title=$title" >> $GITHUB_OUTPUT + echo "description=$description" >> $GITHUB_OUTPUT + + - name: Extract package name from issue title + id: package_name + uses: actions/github-script@ed597411d8f924073f98dfc5c65a23a2325f34cd # v8.0.0 + env: + TITLE: ${{ steps.issue.outputs.title }} + with: + script: | + # Extracted title should be in the format of (boundary): + # Replace `` + # Replace ``, ``, ... + # Replace `` with `` + # Cleanup `` + # Cleanup ``, ``, ..` + # Remove `` + # Remove ``, ``, ... + + function extractAllPackages(str) { + const packageRegex = /`([@\w/-]+)`/g; + const matches = []; + let match; + + // Only process if it starts with Replace/Cleanup/Remove + if (/^(Replace|Cleanup|Remove)\s+/.test(str)) { + while ((match = packageRegex.exec(str)) !== null) { + matches.push(match[1]); + } + // For "Replace X with Y", only keep the first package(s) before "with" + if (str.includes(' with ')) { + const beforeWith = str.split(' with ')[0]; + const beforeWithMatches = []; + packageRegex.lastIndex = 0; // Reset regex + while ((match = packageRegex.exec(beforeWith)) !== null) { + beforeWithMatches.push(match[1]); + } + return beforeWithMatches; + } + } + + return matches; + } + + const packages = extractAllPackages(TITLE); + if (packages.length === 0) { + core.setFailed(`Could not extract package name from title: ${TITLE}`); + return; + } + + core.setOutput('packages', packages.join(' ')); + + - name: Run Fuzzyma's tool + shell: bash + run: | + output=() + for package in "${{ steps.package_name.outputs.packages }}"; do + echo "Running for $package" + output+=("### $package") + output+=("$(npx --yes github:Fuzzyma/e18e-tools $package -n 20 -q -o md -U https://npm.devminer.xyz/registry)") + done + + gh issue comment ${{ github.event.pull_request.number }} --body "${output[*]}" From 062f5c4998cf06072a713f224015a6523c5f3818 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 27 Sep 2025 10:40:53 +0700 Subject: [PATCH 2/3] chore: typo on dependends -> dependents --- .github/workflows/package-dependends-trigger.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/package-dependends-trigger.yml b/.github/workflows/package-dependends-trigger.yml index 954f90f..af03471 100644 --- a/.github/workflows/package-dependends-trigger.yml +++ b/.github/workflows/package-dependends-trigger.yml @@ -1,4 +1,4 @@ -name: Package Dependends Trigger +name: Package Dependents Trigger on: pull_request_target: @@ -9,8 +9,8 @@ permissions: contents: read jobs: - comment-package-dependends-on-issue: - name: Comment package dependends on issue + comment-package-dependents-on-issue: + name: Comment package dependents on issue runs-on: ubuntu-latest if: "${{ (github.event.action != 'labeled' || github.event.label.name == 'Trigger: Find Dependents') && github.repository_owner == 'e18e' }}" steps: From f73f2d594511fcfa363036e416987495ac56a324 Mon Sep 17 00:00:00 2001 From: Reinaldy Rafli Date: Sat, 27 Sep 2025 10:44:03 +0700 Subject: [PATCH 3/3] ref: just use edit-last for now --- .github/workflows/package-dependends-trigger.yml | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/.github/workflows/package-dependends-trigger.yml b/.github/workflows/package-dependends-trigger.yml index af03471..4d99db2 100644 --- a/.github/workflows/package-dependends-trigger.yml +++ b/.github/workflows/package-dependends-trigger.yml @@ -76,11 +76,19 @@ jobs: - name: Run Fuzzyma's tool shell: bash run: | - output=() + output=("") for package in "${{ steps.package_name.outputs.packages }}"; do echo "Running for $package" output+=("### $package") output+=("$(npx --yes github:Fuzzyma/e18e-tools $package -n 20 -q -o md -U https://npm.devminer.xyz/registry)") done - gh issue comment ${{ github.event.pull_request.number }} --body "${output[*]}" + # Do we have existing comment that contains the marker? + existing_comment=$(gh issue comment ${{ github.event.pull_request.number }} --json body) + if echo "$existing_comment" | grep -q ""; then + # Update the existing comment + gh issue comment ${{ github.event.pull_request.number }} --body "${output[*]}" --edit-last + else + # Create a new comment + gh issue comment ${{ github.event.pull_request.number }} --body "${output[*]}" + fi