|
| 1 | +name: Check Misskey JS autogen |
| 2 | + |
| 3 | +on: |
| 4 | + pull_request_target: |
| 5 | + branches: |
| 6 | + - master |
| 7 | + - develop |
| 8 | + - improve-misskey-js-autogen-check |
| 9 | + paths: |
| 10 | + - packages/backend/** |
| 11 | + |
| 12 | +jobs: |
| 13 | + # pull_request_target safety: permissions: read-all, and there are no secrets used in this job |
| 14 | + generate-misskey-js: |
| 15 | + runs-on: ubuntu-latest |
| 16 | + permissions: |
| 17 | + contents: read |
| 18 | + if: ${{ github.event.pull_request.mergeable == null || github.event.pull_request.mergeable == true }} |
| 19 | + steps: |
| 20 | + - name: checkout |
| 21 | + uses: actions/checkout@v4.1.1 |
| 22 | + with: |
| 23 | + submodules: true |
| 24 | + persist-credentials: false |
| 25 | + ref: refs/pull/${{ github.event.pull_request.number }}/merge |
| 26 | + |
| 27 | + - name: setup pnpm |
| 28 | + uses: pnpm/action-setup@v4 |
| 29 | + |
| 30 | + - name: setup node |
| 31 | + id: setup-node |
| 32 | + uses: actions/setup-node@v4.0.4 |
| 33 | + with: |
| 34 | + node-version-file: '.node-version' |
| 35 | + cache: pnpm |
| 36 | + |
| 37 | + - name: install dependencies |
| 38 | + run: pnpm i --frozen-lockfile |
| 39 | + |
| 40 | + # generate api.json |
| 41 | + - name: Copy Config |
| 42 | + run: cp .config/example.yml .config/default.yml |
| 43 | + - name: Build |
| 44 | + run: pnpm build |
| 45 | + - name: Generate API JSON |
| 46 | + run: pnpm --filter backend generate-api-json |
| 47 | + |
| 48 | + # build misskey js |
| 49 | + - name: Build misskey-js |
| 50 | + run: |- |
| 51 | + cp packages/backend/built/api.json packages/misskey-js/generator/api.json |
| 52 | + pnpm run --filter misskey-js-type-generator generate |
| 53 | +
|
| 54 | + # packages/misskey-js/generator/built/autogen |
| 55 | + - name: Upload Generated |
| 56 | + uses: actions/upload-artifact@v4 |
| 57 | + with: |
| 58 | + name: generated-misskey-js |
| 59 | + path: packages/misskey-js/generator/built/autogen |
| 60 | + |
| 61 | + # pull_request_target safety: permissions: read-all, and no user codes are executed |
| 62 | + get-actual-misskey-js: |
| 63 | + runs-on: ubuntu-latest |
| 64 | + permissions: |
| 65 | + contents: read |
| 66 | + if: ${{ github.event.pull_request.mergeable == null || github.event.pull_request.mergeable == true }} |
| 67 | + steps: |
| 68 | + - name: checkout |
| 69 | + uses: actions/checkout@v4.1.1 |
| 70 | + with: |
| 71 | + submodules: true |
| 72 | + persist-credentials: false |
| 73 | + ref: refs/pull/${{ github.event.pull_request.number }}/merge |
| 74 | + |
| 75 | + - name: Upload From Merged |
| 76 | + uses: actions/upload-artifact@v4 |
| 77 | + with: |
| 78 | + name: actual-misskey-js |
| 79 | + path: packages/misskey-js/src/autogen |
| 80 | + |
| 81 | + # pull_request_target safety: nothing is cloned from repository |
| 82 | + comment-misskey-js-autogen: |
| 83 | + runs-on: ubuntu-latest |
| 84 | + needs: [generate-misskey-js, get-actual-misskey-js] |
| 85 | + permissions: |
| 86 | + pull-requests: write |
| 87 | + steps: |
| 88 | + - name: download generated-misskey-js |
| 89 | + uses: actions/download-artifact@v4 |
| 90 | + with: |
| 91 | + name: generated-misskey-js |
| 92 | + path: misskey-js-generated |
| 93 | + |
| 94 | + - name: download actual-misskey-js |
| 95 | + uses: actions/download-artifact@v4 |
| 96 | + with: |
| 97 | + name: actual-misskey-js |
| 98 | + path: misskey-js-actual |
| 99 | + |
| 100 | + - name: check misskey-js changes |
| 101 | + id: check-changes |
| 102 | + run: | |
| 103 | + diff -r -u --label=generated --label=on-tree ./misskey-js-generated ./misskey-js-actual > misskey-js.diff || true |
| 104 | +
|
| 105 | + if [ -s misskey-js.diff ]; then |
| 106 | + echo "changes=true" >> $GITHUB_OUTPUT |
| 107 | + else |
| 108 | + echo "changes=false" >> $GITHUB_OUTPUT |
| 109 | + fi |
| 110 | +
|
| 111 | + - name: Print full diff |
| 112 | + run: cat ./misskey-js.diff |
| 113 | + |
| 114 | + - name: send message |
| 115 | + if: steps.check-changes.outputs.changes == 'true' |
| 116 | + uses: thollander/actions-comment-pull-request@v2 |
| 117 | + with: |
| 118 | + comment_tag: check-misskey-js-autogen |
| 119 | + message: |- |
| 120 | + Thank you for sending us a great Pull Request! 👍 |
| 121 | + Please regenerate misskey-js type definitions! 🙏 |
| 122 | +
|
| 123 | + example: |
| 124 | + ```sh |
| 125 | + pnpm run build-misskey-js-with-types |
| 126 | + ``` |
| 127 | +
|
| 128 | + - name: send message |
| 129 | + if: steps.check-changes.outputs.changes == 'false' |
| 130 | + uses: thollander/actions-comment-pull-request@v2 |
| 131 | + with: |
| 132 | + comment_tag: check-misskey-js-autogen |
| 133 | + mode: delete |
| 134 | + message: "Thank you!" |
| 135 | + create_if_not_exists: false |
| 136 | + |
| 137 | + - name: Make failure if changes are detected |
| 138 | + if: steps.check-changes.outputs.changes == 'true' |
| 139 | + run: exit 1 |
0 commit comments