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

View File

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

View File

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

View File

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