From 58ac8bc8e9573337c10c013fee0be478d1ef8b74 Mon Sep 17 00:00:00 2001
From: ikasoba <57828948+ikasoba@users.noreply.github.com>
Date: Tue, 23 Jan 2024 06:35:15 +0900
Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=AD=A3=E3=81=A7=E3=81=8D=E3=81=9F?=
 =?UTF-8?q?=E3=81=8B=E3=82=82=20(#13066)?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit

---
 .../workflows/check-misskey-js-autogen.yml    | 29 ++++++++++++-------
 1 file changed, 18 insertions(+), 11 deletions(-)

diff --git a/.github/workflows/check-misskey-js-autogen.yml b/.github/workflows/check-misskey-js-autogen.yml
index 0b34cdc202..545b215756 100644
--- a/.github/workflows/check-misskey-js-autogen.yml
+++ b/.github/workflows/check-misskey-js-autogen.yml
@@ -1,7 +1,7 @@
 name: Check Misskey JS autogen
 
 on:
-  pull_request:
+  pull_request_target:
     branches:
       - master
       - develop
@@ -15,13 +15,14 @@ jobs:
       pull-requests: write
 
     env:
-      api_json_names: "api-base.json api-head.json"
+      api_json_name: "api-head.json"
 
     steps:
       - name: checkout
         uses: actions/checkout@v4
         with:
           submodules: true
+          ref: ${{ github.event.pull_request.head.sha }}
 
       - name: setup pnpm
         uses: pnpm/action-setup@v2
@@ -87,22 +88,27 @@ jobs:
           find . -mindepth 1 -maxdepth 1 -type f -name '*.zip' -exec unzip {} -d . ';'
           ls -la
 
+      - name: get head checksum
+        run: |-
+          checksum=$(realpath head_checksum)
+
+          cd packages/misskey-js/src
+          find autogen -type f -exec sh -c 'echo $(sed -E "s/^\s+\*\s+generatedAt:.+$//" {} | sha256sum | cut -d" " -f 1) {}' \; > $checksum
+          cd ../../..
+
       - name: build autogen
         run: |-
-          for name in $(echo $api_json_names)
-          do
-            checksum=$(mktemp)
-            mv $name packages/misskey-js/generator/api.json
+            checksum=$(realpath ${api_json_name}_checksum)
+            mv $api_json_name packages/misskey-js/generator/api.json
 
             cd packages/misskey-js/generator
             pnpm run generate
-            find built -type f -exec sh -c 'echo $(sed -E "s/^\s+\*\s+generatedAt:.+$//" {} | sha256sum | cut -d" " -f 1) {}' \; > $checksum
-            cd ../../..
-            cp $checksum ${name}_checksum
-          done
+            cd built
+            find autogen -type f -exec sh -c 'echo $(sed -E "s/^\s+\*\s+generatedAt:.+$//" {} | sha256sum | cut -d" " -f 1) {}' \; > $checksum
+            cd ../../../..
 
       - name: check update for type definitions
-        run: diff $(echo -n ${api_json_names} | awk -v RS=" " '{ printf "%s_checksum ", $0 }')
+        run: diff head_checksum ${api_json_name}_checksum
 
       - name: send message
         if: failure()
@@ -125,3 +131,4 @@ jobs:
           comment_tag: check-misskey-js-autogen
           mode: delete
           message: "Thank you!"
+          create_if_not_exists: false