]> git.ipfire.org Git - thirdparty/vuejs/core.git/commitdiff
ci: fix size report permissions
author三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 21 Aug 2023 03:44:43 +0000 (11:44 +0800)
committer三咲智子 Kevin Deng <sxzz@sxzz.moe>
Mon, 21 Aug 2023 05:10:41 +0000 (13:10 +0800)
.github/workflows/size-data.yml [new file with mode: 0644]
.github/workflows/size-report.yml

diff --git a/.github/workflows/size-data.yml b/.github/workflows/size-data.yml
new file mode 100644 (file)
index 0000000..647e029
--- /dev/null
@@ -0,0 +1,49 @@
+name: size data
+
+on:
+  push:
+    branches:
+      - main
+  pull_request:
+    branches:
+      - main
+
+permissions:
+  contents: read
+
+jobs:
+  upload:
+    runs-on: ubuntu-latest
+
+    steps:
+      - uses: actions/checkout@v3
+
+      - name: Install pnpm
+        uses: pnpm/action-setup@v2
+
+      - name: Set node version to LTS
+        uses: actions/setup-node@v3
+        with:
+          node-version: lts/*
+          cache: pnpm
+
+      - name: Install dependencies
+        run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
+
+      - run: pnpm run size
+
+      - name: Upload Size Data
+        uses: actions/upload-artifact@v3
+        with:
+          name: size-data
+          path: temp/size
+
+      - name: Save PR number
+        if: ${{github.event_name == 'pull_request'}}
+        run: echo ${{ github.event.number }} > ./pr.txt
+
+      - uses: actions/upload-artifact@v2
+        if: ${{github.event_name == 'pull_request'}}
+        with:
+          name: pr-number
+          path: pr.txt
index 87c6865927b5b3eef8cd98bd45e4b93c9ef6b156..4d7e49e523bde3ebab779426a70f089538f6bba1 100644 (file)
@@ -1,18 +1,22 @@
 name: size report
 
 on:
-  pull_request:
-    branches:
-      - main
+  workflow_run:
+    workflows: ['size data']
+    types:
+      - completed
 
 permissions:
   contents: read
   pull-requests: write
+  issues: write
 
 jobs:
-  size:
+  size-report:
     runs-on: ubuntu-latest
-
+    if: >
+      github.event.workflow_run.event == 'pull_request' &&
+      github.event.workflow_run.conclusion == 'success'
     steps:
       - uses: actions/checkout@v3
 
@@ -25,37 +29,52 @@ jobs:
           node-version: lts/*
           cache: pnpm
 
-      - run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
-      - run: pnpm run size
+      - name: Install dependencies
+        run: PUPPETEER_SKIP_DOWNLOAD=1 pnpm install
 
-      - name: Download Previous Size Report
-        id: download-artifact
+      - name: Download PR number
         uses: dawidd6/action-download-artifact@v2
         with:
-          branch: main
-          name: size-report
-          path: temp/size-prev
-          if_no_artifact_found: warn
+          name: pr-number
+          run_id: ${{ github.event.workflow_run.id }}
+
+      - name: Read PR Number
+        id: pr-number
+        uses: juliangruber/read-file-action@v1
+        with:
+          path: ./pr.txt
 
-      - name: Upload Size Report
-        uses: actions/upload-artifact@v3
+      - name: Download Size Data
+        uses: dawidd6/action-download-artifact@v2
         with:
-          name: size-report
+          name: size-data
+          run_id: ${{ github.event.workflow_run.id }}
           path: temp/size
 
+      - name: Download Previous Size Data
+        uses: dawidd6/action-download-artifact@v2
+        with:
+          branch: main
+          workflow: size-data.yml
+          name: size-data
+          path: temp/size-prev
+          if_no_artifact_found: warn
+
       - name: Compare size
-        run: pnpm tsx scripts/size-report.ts > size.md
+        run: pnpm tsx scripts/size-report.ts > size-report.md
 
-      - name: Read Size Markdown
-        id: size-markdown
+      - name: Read Size Report
+        id: size-report
         uses: juliangruber/read-file-action@v1
         with:
-          path: ./size.md
+          path: ./size-report.md
 
       - name: Create Comment
         uses: actions-cool/maintain-one-comment@v3
         with:
+          token: ${{ secrets.GITHUB_TOKEN }}
+          number: ${{ steps.pr-number.outputs.content }}
           body: |
-            ${{steps.size-markdown.outputs.content}}
+            ${{ steps.size-report.outputs.content }}
             <!-- VUE_CORE_SIZE -->
           body-include: '<!-- VUE_CORE_SIZE -->'