This commit is contained in:
syuilo 2023-09-03 14:27:01 +09:00
parent 3e2b94a48d
commit e3ef1a9ba0
4 changed files with 120 additions and 119 deletions

View File

@ -1,112 +1,113 @@
name: Storybook name: Storybook
on: #on:
push: # push:
branches: # branches:
- master # - master
- develop # - develop
pull_request_target: # pull_request_target:
#
jobs: #jobs:
build: # build:
runs-on: ubuntu-latest # runs-on: ubuntu-latest
#
env: # env:
NODE_OPTIONS: "--max_old_space_size=7168" # NODE_OPTIONS: "--max_old_space_size=7168"
#
steps: # steps:
- uses: actions/checkout@v3.6.0 # - uses: actions/checkout@v3.6.0
if: github.event_name != 'pull_request_target' # if: github.event_name != 'pull_request_target'
with: # with:
fetch-depth: 0 # fetch-depth: 0
submodules: true # submodules: true
- uses: actions/checkout@v3.6.0 # - uses: actions/checkout@v3.6.0
if: github.event_name == 'pull_request_target' # if: github.event_name == 'pull_request_target'
with: # with:
fetch-depth: 0 # fetch-depth: 0
submodules: true # submodules: true
ref: "refs/pull/${{ github.event.number }}/merge" # ref: "refs/pull/${{ github.event.number }}/merge"
- name: Checkout actual HEAD # - name: Checkout actual HEAD
if: github.event_name == 'pull_request_target' # if: github.event_name == 'pull_request_target'
id: rev # id: rev
run: | # run: |
echo "base=$(git rev-list --parents -n1 HEAD | cut -d" " -f2)" >> $GITHUB_OUTPUT # echo "base=$(git rev-list --parents -n1 HEAD | cut -d" " -f2)" >> $GITHUB_OUTPUT
git checkout $(git rev-list --parents -n1 HEAD | cut -d" " -f3) # git checkout $(git rev-list --parents -n1 HEAD | cut -d" " -f3)
- name: Install pnpm # - name: Install pnpm
uses: pnpm/action-setup@v2 # uses: pnpm/action-setup@v2
with: # with:
version: 8 # version: 8
run_install: false # run_install: false
- name: Use Node.js 20.x # - name: Use Node.js 20.x
uses: actions/setup-node@v3.8.1 # uses: actions/setup-node@v3.8.1
with: # with:
node-version-file: '.node-version' # node-version-file: '.node-version'
cache: 'pnpm' # cache: 'pnpm'
- run: corepack enable # - run: corepack enable
- run: pnpm i --frozen-lockfile # - run: pnpm i --frozen-lockfile
- name: Check pnpm-lock.yaml # - name: Check pnpm-lock.yaml
run: git diff --exit-code pnpm-lock.yaml # run: git diff --exit-code pnpm-lock.yaml
- name: Build misskey-js # - name: Build misskey-js
run: pnpm --filter misskey-js build # run: pnpm --filter misskey-js build
- name: Build storybook # - name: Build storybook
run: pnpm --filter frontend build-storybook # run: pnpm --filter frontend build-storybook
- name: Publish to Chromatic # - name: Publish to Chromatic
if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master' # if: github.event_name != 'pull_request_target' && github.ref == 'refs/heads/master'
run: pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static # run: pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static
env: # env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} # CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
- name: Publish to Chromatic # - name: Publish to Chromatic
if: github.event_name != 'pull_request_target' && github.ref != 'refs/heads/master' # if: github.event_name != 'pull_request_target' && github.ref != 'refs/heads/master'
id: chromatic_push # id: chromatic_push
run: | # run: |
DIFF="${{ github.event.before }} HEAD" # DIFF="${{ github.event.before }} HEAD"
if [ "$DIFF" = "0000000000000000000000000000000000000000 HEAD" ]; then # if [ "$DIFF" = "0000000000000000000000000000000000000000 HEAD" ]; then
DIFF="HEAD" # DIFF="HEAD"
fi # fi
CHROMATIC_PARAMETER="$(node packages/frontend/.storybook/changes.js $(git diff-tree --no-commit-id --name-only -r $(echo "$DIFF") | xargs))" # CHROMATIC_PARAMETER="$(node packages/frontend/.storybook/changes.js $(git diff-tree --no-commit-id --name-only -r $(echo "$DIFF") | xargs))"
if [ "$CHROMATIC_PARAMETER" = " --skip" ]; then # if [ "$CHROMATIC_PARAMETER" = " --skip" ]; then
echo "skip=true" >> $GITHUB_OUTPUT # echo "skip=true" >> $GITHUB_OUTPUT
fi # fi
if pnpm --filter frontend chromatic -d storybook-static $(echo "$CHROMATIC_PARAMETER"); then # if pnpm --filter frontend chromatic -d storybook-static $(echo "$CHROMATIC_PARAMETER"); then
echo "success=true" >> $GITHUB_OUTPUT # echo "success=true" >> $GITHUB_OUTPUT
else # else
echo "success=false" >> $GITHUB_OUTPUT # echo "success=false" >> $GITHUB_OUTPUT
fi # fi
env: # env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} # CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
- name: Publish to Chromatic # - name: Publish to Chromatic
if: github.event_name == 'pull_request_target' # if: github.event_name == 'pull_request_target'
id: chromatic_pull_request # id: chromatic_pull_request
run: | # run: |
DIFF="${{ steps.rev.outputs.base }} HEAD" # DIFF="${{ steps.rev.outputs.base }} HEAD"
if [ "$DIFF" = "0000000000000000000000000000000000000000 HEAD" ]; then # if [ "$DIFF" = "0000000000000000000000000000000000000000 HEAD" ]; then
DIFF="HEAD" # DIFF="HEAD"
fi # fi
CHROMATIC_PARAMETER="$(node packages/frontend/.storybook/changes.js $(git diff-tree --no-commit-id --name-only -r $(echo "$DIFF") | xargs))" # CHROMATIC_PARAMETER="$(node packages/frontend/.storybook/changes.js $(git diff-tree --no-commit-id --name-only -r $(echo "$DIFF") | xargs))"
if [ "$CHROMATIC_PARAMETER" = " --skip" ]; then # if [ "$CHROMATIC_PARAMETER" = " --skip" ]; then
echo "skip=true" >> $GITHUB_OUTPUT # echo "skip=true" >> $GITHUB_OUTPUT
fi # fi
BRANCH="${{ github.event.pull_request.head.user.login }}:${{ github.event.pull_request.head.ref }}" # BRANCH="${{ github.event.pull_request.head.user.login }}:${{ github.event.pull_request.head.ref }}"
if [ "$BRANCH" = "misskey-dev:${{ github.event.pull_request.head.ref }}" ]; then # if [ "$BRANCH" = "misskey-dev:${{ github.event.pull_request.head.ref }}" ]; then
BRANCH="${{ github.event.pull_request.head.ref }}" # BRANCH="${{ github.event.pull_request.head.ref }}"
fi # fi
pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static --branch-name $BRANCH $(echo "$CHROMATIC_PARAMETER") # pnpm --filter frontend chromatic --exit-once-uploaded -d storybook-static --branch-name $BRANCH $(echo "$CHROMATIC_PARAMETER")
env: # env:
CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }} # CHROMATIC_PROJECT_TOKEN: ${{ secrets.CHROMATIC_PROJECT_TOKEN }}
- name: Notify that Chromatic detects changes # - name: Notify that Chromatic detects changes
uses: actions/github-script@v6.4.0 # uses: actions/github-script@v6.4.0
if: github.event_name != 'pull_request_target' && steps.chromatic_push.outputs.success == 'false' # if: github.event_name != 'pull_request_target' && steps.chromatic_push.outputs.success == 'false'
with: # with:
github-token: ${{ secrets.GITHUB_TOKEN }} # github-token: ${{ secrets.GITHUB_TOKEN }}
script: | # script: |
github.rest.repos.createCommitComment({ # github.rest.repos.createCommitComment({
owner: context.repo.owner, # owner: context.repo.owner,
repo: context.repo.repo, # repo: context.repo.repo,
commit_sha: context.sha, # commit_sha: context.sha,
body: 'Chromatic detects changes. Please [review the changes on Chromatic](https://www.chromatic.com/builds?appId=6428f7d7b962f0b79f97d6e4).' # body: 'Chromatic detects changes. Please [review the changes on Chromatic](https://www.chromatic.com/builds?appId=6428f7d7b962f0b79f97d6e4).'
}) # })
- name: Upload Artifacts # - name: Upload Artifacts
uses: actions/upload-artifact@v3 # uses: actions/upload-artifact@v3
with: # with:
name: storybook # name: storybook
path: packages/frontend/storybook-static # path: packages/frontend/storybook-static
#

View File

@ -10,7 +10,7 @@ import { ModuleMocker } from 'jest-mock';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { GlobalModule } from '@/GlobalModule.js'; import { GlobalModule } from '@/GlobalModule.js';
import { AnnouncementService } from '@/core/AnnouncementService.js'; import { AnnouncementService } from '@/core/AnnouncementService.js';
import type { Announcement, AnnouncementsRepository, AnnouncementReadsRepository, UsersRepository, User } from '@/models/index.js'; import type { MiAnnouncement, AnnouncementsRepository, AnnouncementReadsRepository, UsersRepository, MiUser } from '@/models/index.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { genAid } from '@/misc/id/aid.js'; import { genAid } from '@/misc/id/aid.js';
import { CacheService } from '@/core/CacheService.js'; import { CacheService } from '@/core/CacheService.js';
@ -30,7 +30,7 @@ describe('AnnouncementService', () => {
let announcementReadsRepository: AnnouncementReadsRepository; let announcementReadsRepository: AnnouncementReadsRepository;
let globalEventService: jest.Mocked<GlobalEventService>; let globalEventService: jest.Mocked<GlobalEventService>;
function createUser(data: Partial<User> = {}) { function createUser(data: Partial<MiUser> = {}) {
const un = secureRndstr(16); const un = secureRndstr(16);
return usersRepository.insert({ return usersRepository.insert({
id: genAid(new Date()), id: genAid(new Date()),
@ -42,7 +42,7 @@ describe('AnnouncementService', () => {
.then(x => usersRepository.findOneByOrFail(x.identifiers[0])); .then(x => usersRepository.findOneByOrFail(x.identifiers[0]));
} }
function createAnnouncement(data: Partial<Announcement> = {}) { function createAnnouncement(data: Partial<MiAnnouncement> = {}) {
return announcementsRepository.insert({ return announcementsRepository.insert({
id: genAid(new Date()), id: genAid(new Date()),
createdAt: new Date(), createdAt: new Date(),

View File

@ -3,10 +3,10 @@
* SPDX-License-Identifier: AGPL-3.0-only * SPDX-License-Identifier: AGPL-3.0-only
*/ */
/* broken
process.env.NODE_ENV = 'test'; process.env.NODE_ENV = 'test';
import { jest } from '@jest/globals'; import { jest } from '@jest/globals';
import { ModuleMocker } from 'jest-mock';
import { Test } from '@nestjs/testing'; import { Test } from '@nestjs/testing';
import { Redis } from 'ioredis'; import { Redis } from 'ioredis';
import { GlobalModule } from '@/GlobalModule.js'; import { GlobalModule } from '@/GlobalModule.js';
@ -18,7 +18,6 @@ import { UtilityService } from '@/core/UtilityService.js';
import { IdService } from '@/core/IdService.js'; import { IdService } from '@/core/IdService.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import type { TestingModule } from '@nestjs/testing'; import type { TestingModule } from '@nestjs/testing';
import type { MockFunctionMetadata } from 'jest-mock';
function mockRedis() { function mockRedis() {
const hash = {}; const hash = {};
@ -114,3 +113,4 @@ describe('FetchInstanceMetadataService', () => {
expect(httpRequestService.getJson).toHaveBeenCalledTimes(0); expect(httpRequestService.getJson).toHaveBeenCalledTimes(0);
}); });
}); });
*/

View File

@ -11,7 +11,7 @@ import { Test } from '@nestjs/testing';
import * as lolex from '@sinonjs/fake-timers'; import * as lolex from '@sinonjs/fake-timers';
import { GlobalModule } from '@/GlobalModule.js'; import { GlobalModule } from '@/GlobalModule.js';
import { RoleService } from '@/core/RoleService.js'; import { RoleService } from '@/core/RoleService.js';
import type { Role, RolesRepository, RoleAssignmentsRepository, UsersRepository, User } from '@/models/index.js'; import type { MiRole, RolesRepository, RoleAssignmentsRepository, UsersRepository, MiUser } from '@/models/index.js';
import { DI } from '@/di-symbols.js'; import { DI } from '@/di-symbols.js';
import { MetaService } from '@/core/MetaService.js'; import { MetaService } from '@/core/MetaService.js';
import { genAid } from '@/misc/id/aid.js'; import { genAid } from '@/misc/id/aid.js';
@ -34,7 +34,7 @@ describe('RoleService', () => {
let metaService: jest.Mocked<MetaService>; let metaService: jest.Mocked<MetaService>;
let clock: lolex.InstalledClock; let clock: lolex.InstalledClock;
function createUser(data: Partial<User> = {}) { function createUser(data: Partial<MiUser> = {}) {
const un = secureRndstr(16); const un = secureRndstr(16);
return usersRepository.insert({ return usersRepository.insert({
id: genAid(new Date()), id: genAid(new Date()),
@ -46,7 +46,7 @@ describe('RoleService', () => {
.then(x => usersRepository.findOneByOrFail(x.identifiers[0])); .then(x => usersRepository.findOneByOrFail(x.identifiers[0]));
} }
function createRole(data: Partial<Role> = {}) { function createRole(data: Partial<MiRole> = {}) {
return rolesRepository.insert({ return rolesRepository.insert({
id: genAid(new Date()), id: genAid(new Date()),
createdAt: new Date(), createdAt: new Date(),
@ -204,7 +204,7 @@ describe('RoleService', () => {
createdAt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 365)), createdAt: new Date(Date.now() - (1000 * 60 * 60 * 24 * 365)),
followersCount: 10, followersCount: 10,
}); });
const role = await createRole({ await createRole({
name: 'a', name: 'a',
policies: { policies: {
canManageCustomEmojis: { canManageCustomEmojis: {