Forráskód Böngészése

Ping maintainers using workflow_run (#8309)

* ping maintainers when framework updated

* update description

* add nate

* add contents write permission

* Change to use workflow_run

* fix directory

* remove nate

* fix name

* update script

* add permissions

* encode comment to utf-8

* fix syntax

* change how script gets called

* handle no maintainers

* fix path

* update handling no maintainers

* fix variable name
ecruz-te 2 éve
szülő
commit
ea25262d95

+ 11 - 16
.github/workflows/ping_maintainers.yml → .github/workflows/get-maintainers.yml

@@ -1,11 +1,11 @@
-name: Ping maintainers
+name: get-maintainers
 on: 
   pull_request:
     types: [opened, reopened]
 permissions:
   pull-requests: write
 jobs:
-  ping_maintainers:
+  get_maintainers:
     runs-on: ubuntu-22.04
     steps:
       - uses: actions/checkout@v3
@@ -23,20 +23,15 @@ jobs:
         with:
           python-version: '3.10'
           architecture: 'x64'
+      - name: Save PR number
+        run: |
+          mkdir -p ./maintainers
+          echo ${{ github.event.number }} > ./maintainers/NR
       - name: Get Maintainers
         run: |
-          echo "MAINTAINERS_COMMENT<<EOF" >> $GITHUB_ENV
-          echo "$(./toolset/github_actions/get_maintainers.py)" >> $GITHUB_ENV
-          echo "EOF" >> $GITHUB_ENV
-      - name: Ping maintainers
-        if: env.MAINTAINERS_COMMENT
-        uses: actions/github-script@v6
+          python ./toolset/github_actions/get_maintainers.py > ./maintainers/maintainers.md
+      - name: Save Maintainers
+        uses: actions/upload-artifact@v3
         with:
-          github-token: ${{ secrets.GITHUB_TOKEN }}
-          script: |
-            github.rest.issues.createComment({
-              issue_number: context.issue.number,
-              owner: context.repo.owner,
-              repo: context.repo.repo,
-              body: process.env.MAINTAINERS_COMMENT
-            });
+          name: maintainers
+          path: maintainers/

+ 49 - 0
.github/workflows/ping-maintainers.yml

@@ -0,0 +1,49 @@
+name: Ping Maintainers
+on:
+  workflow_run:
+    workflows: [ "get-maintainers"]
+    types:
+      - completed
+permissions:
+  pull-requests: write
+jobs:
+  ping_maintainers:
+    runs-on: ubuntu-22.04
+    steps:
+      - name: 'Download maintainers artifact'
+        uses: actions/github-script@v6
+        with:
+          script: |
+            let artifacts = await github.rest.actions.listWorkflowRunArtifacts({
+               owner: context.repo.owner,
+               repo: context.repo.repo,
+               run_id: ${{github.event.workflow_run.id }},
+            });
+            let matchArtifact = artifacts.data.artifacts.filter((artifact) => {
+              return artifact.name == "maintainers"
+            })[0];
+            let download = await github.rest.actions.downloadArtifact({
+               owner: context.repo.owner,
+               repo: context.repo.repo,
+               artifact_id: matchArtifact.id,
+               archive_format: 'zip',
+            });
+            let fs = require('fs');
+            fs.writeFileSync('${{github.workspace}}/maintainers.zip', Buffer.from(download.data));
+      - run: unzip maintainers.zip
+      - name: Ping maintainers
+        uses: actions/github-script@v6
+        with:
+          github-token: ${{ secrets.GITHUB_TOKEN }}
+          script: |
+            let fs = require('fs');
+            let issue_number = Number(fs.readFileSync('./NR'));
+            let maintainers_comment = fs.readFileSync('./maintainers.md', 'utf8');
+            if (maintainers_comment) {
+              await github.rest.issues.createComment({
+                issue_number: issue_number,
+                owner: context.repo.owner,
+                repo: context.repo.repo,
+                body: maintainers_comment
+              });
+            }