Skip to content

Commit

Permalink
add pipeline
Browse files Browse the repository at this point in the history
  • Loading branch information
susumutomita committed Mar 23, 2024
1 parent b8e2451 commit dfac316
Show file tree
Hide file tree
Showing 63 changed files with 4,814 additions and 1,284 deletions.
5 changes: 5 additions & 0 deletions .eslintrc copy.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
/** @type {import("eslint").Linter.Config} */
module.exports = {
root: true,
extends: ["next"],
};
7 changes: 7 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
version: 2
updates:
- package-ecosystem: 'npm'
directory: '/'
schedule:
interval: 'daily'
open-pull-requests-limit: 10
45 changes: 45 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: CI

on:
push:
pull_request:
branches: ['main']

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
build-and-test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Set up Node.js
uses: actions/setup-node@v4
with:
node-version: '20'

- name: Cache Node modules
uses: actions/cache@v4
with:
path: node_modules
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install dependencies
run: make install

- name: Lint
run: make lint

- name: TextLint
run: make lint_text

- name: Check format
run: make format_check

- name: Test
run: make test
26 changes: 26 additions & 0 deletions .github/workflows/delete-workflow-history.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
name: Delete workflow history

on:
workflow_dispatch:
inputs:
workflow:
description: workflow-id, workflow-name or filename
required: true
type: string

jobs:
delete-history:
runs-on: ubuntu-latest
timeout-minutes: 10
env:
GH_TOKEN: ${{ github.token }}
GH_REPO: ${{ github.repository }}
WORKFLOW: ${{ github.event.inputs.workflow }}

steps:
- run: gh workflow view "${WORKFLOW}"
- run: |
gh run list --workflow "${WORKFLOW}" --limit 1000 --json databaseId,status --jq '.[] | select(.status == "completed") | .databaseId' \
| xargs -n 1 -I {} gh api -X DELETE repos/${REPOSITORY}/actions/runs/{}
env:
REPOSITORY: ${{ github.repository }}
23 changes: 23 additions & 0 deletions .github/workflows/dependabot_auto_merge.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
name: Dependabot auto-merge
on: pull_request_target

permissions:
pull-requests: write
contents: write

jobs:
dependabot:
runs-on: ubuntu-latest
if: ${{ github.actor == 'dependabot[bot]' }}
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v1.1.1
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"
- name: Enable auto-merge for Dependabot PRs
if: ${{ steps.metadata.outputs.update-type == 'version-update:semver-minor' }}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
5 changes: 5 additions & 0 deletions .huskyrc.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"hooks": {
"pre-commit": "lint-staged"
}
}
9 changes: 9 additions & 0 deletions .prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"semi": true,
"singleQuote": true,
"printWidth": 80,
"tabWidth": 2,
"useTabs": false,
"trailingComma": "es5",
"bracketSpacing": true
}
7 changes: 7 additions & 0 deletions .textlintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"filters": {},
"rules": {
"no-mixed-zenkaku-and-hankaku-alphabet": true,
"no-mixed-zenkaku-and-hankaku-number": true
}
}
38 changes: 38 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
.PHONY: install
install:
yarn install

.PHONY: build
build:
yarn build

.PHONY: clean
clean:
yarn clean

.PHONY: test
test:
yarn test

.PHONY: test_coverage
test_coverage:
yarn test:coverage

.PHONY: lint
lint:
yarn lint

.PHONY: lint_text
lint_text:
yarn lint:text

.PHONY: format
format:
yarn format

.PHONY: format_check
format_check:
yarn format:check

.PHONY: before_commit
before_commit: test format lint lint_text
12 changes: 6 additions & 6 deletions app/debug.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
const DEFAULT_DEBUGGER_URL =
process.env.DEBUGGER_URL ?? "http://localhost:3010/";
process.env.DEBUGGER_URL ?? 'http://localhost:3010/';

export const DEFAULT_DEBUGGER_HUB_URL =
process.env.NODE_ENV === "development"
? new URL("/hub", DEFAULT_DEBUGGER_URL).toString()
process.env.NODE_ENV === 'development'
? new URL('/hub', DEFAULT_DEBUGGER_URL).toString()
: undefined;

export function createDebugUrl(frameURL: string | URL): string {
try {
const url = new URL("/", DEFAULT_DEBUGGER_URL);
const url = new URL('/', DEFAULT_DEBUGGER_URL);

url.searchParams.set("url", frameURL.toString());
url.searchParams.set('url', frameURL.toString());

return url.toString();
} catch (error) {
return "#";
return '#';
}
}
2 changes: 1 addition & 1 deletion app/examples/custom-hub/frames/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { POST } from "frames.js/next/server";
export { POST } from 'frames.js/next/server';
36 changes: 18 additions & 18 deletions app/examples/custom-hub/page.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,40 +8,40 @@ import {
getPreviousFrame,
useFramesReducer,
getFrameMessage,
} from "frames.js/next/server";
import Link from "next/link";
import { getTokenUrl } from "frames.js";
import { createDebugUrl } from "../../debug";
import { currentURL } from "../../utils";
} from 'frames.js/next/server';
import Link from 'next/link';
import { getTokenUrl } from 'frames.js';
import { createDebugUrl } from '../../debug';
import { currentURL } from '../../utils';

type State = {
active: string;
total_button_presses: number;
};

const initialState = { active: "1", total_button_presses: 0 };
const initialState = { active: '1', total_button_presses: 0 };

const reducer: FrameReducer<State> = (state, action) => {
return {
total_button_presses: state.total_button_presses + 1,
active: action.postBody?.untrustedData.buttonIndex
? String(action.postBody?.untrustedData.buttonIndex)
: "1",
: '1',
};
};

// This is a react server component only
export default async function Home({ searchParams }: NextServerPageProps) {
const url = currentURL("/examples/custom-hub");
const url = currentURL('/examples/custom-hub');
const previousFrame = getPreviousFrame<State>(searchParams);

const frameMessage = await getFrameMessage(previousFrame.postBody, {
hubHttpUrl: "https://hub.freefarcasterhub.com:3281",
hubHttpUrl: 'https://hub.freefarcasterhub.com:3281',
fetchHubContext: true,
});

if (frameMessage && !frameMessage?.isValid) {
throw new Error("Invalid frame payload");
throw new Error('Invalid frame payload');
}

const [state, dispatch] = useFramesReducer<State>(
Expand All @@ -53,7 +53,7 @@ export default async function Home({ searchParams }: NextServerPageProps) {
// Here: do a server side side effect either sync or async (using await), such as minting an NFT if you want.
// example: load the users credentials & check they have an NFT

console.log("info: state is:", state);
console.log('info: state is:', state);

if (frameMessage) {
const {
Expand All @@ -70,13 +70,13 @@ export default async function Home({ searchParams }: NextServerPageProps) {
requesterUserData,
} = frameMessage;

console.log("info: frameMessage is:", frameMessage);
console.log('info: frameMessage is:', frameMessage);
}

// then, when done, return next frame
return (
<div className="p-4">
frames.js starter kit.{" "}
frames.js starter kit.{' '}
<Link href={createDebugUrl(url)} className="underline">
Debug
</Link>
Expand All @@ -88,21 +88,21 @@ export default async function Home({ searchParams }: NextServerPageProps) {
{/* <FrameImage src="https://framesjs.org/og.png" /> */}
<FrameImage>
<div tw="w-full h-full bg-slate-700 text-white justify-center items-center">
{frameMessage?.inputText ? frameMessage.inputText : "Hello world"}
{frameMessage?.inputText ? frameMessage.inputText : 'Hello world'}
</div>
</FrameImage>
<FrameInput text="put some text here" />
<FrameButton>
{state?.active === "1" ? "Active" : "Inactive"}
{state?.active === '1' ? 'Active' : 'Inactive'}
</FrameButton>
<FrameButton>
{state?.active === "2" ? "Active" : "Inactive"}
{state?.active === '2' ? 'Active' : 'Inactive'}
</FrameButton>
<FrameButton
action="mint"
target={getTokenUrl({
address: "0x060f3edd18c47f59bd23d063bbeb9aa4a8fec6df",
tokenId: "123",
address: '0x060f3edd18c47f59bd23d063bbeb9aa4a8fec6df',
tokenId: '123',
chainId: 7777777,
})}
>
Expand Down
2 changes: 1 addition & 1 deletion app/examples/mint-button/frames/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { POST } from "frames.js/next/server";
export { POST } from 'frames.js/next/server';
32 changes: 16 additions & 16 deletions app/examples/mint-button/page.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { getTokenUrl } from "frames.js";
import { getTokenUrl } from 'frames.js';
import {
FrameButton,
FrameContainer,
Expand All @@ -7,11 +7,11 @@ import {
NextServerPageProps,
getPreviousFrame,
useFramesReducer,
} from "frames.js/next/server";
import Link from "next/link";
import { zora } from "viem/chains";
import { currentURL } from "../../utils";
import { createDebugUrl } from "../../debug";
} from 'frames.js/next/server';
import Link from 'next/link';
import { zora } from 'viem/chains';
import { currentURL } from '../../utils';
import { createDebugUrl } from '../../debug';

type State = {
pageIndex: number;
Expand All @@ -22,27 +22,27 @@ const nfts: {
tokenUrl: string;
}[] = [
{
src: "https://ipfs.decentralized-content.com/ipfs/bafybeifs7vasy5zbmnpixt7tb6efi35kcrmpoz53d3vg5pwjz52q7fl6pq/cook.png",
src: 'https://ipfs.decentralized-content.com/ipfs/bafybeifs7vasy5zbmnpixt7tb6efi35kcrmpoz53d3vg5pwjz52q7fl6pq/cook.png',
tokenUrl: getTokenUrl({
address: "0x99de131ff1223c4f47316c0bb50e42f356dafdaa",
address: '0x99de131ff1223c4f47316c0bb50e42f356dafdaa',
chain: zora,
tokenId: "2",
tokenId: '2',
}),
},
{
src: "https://remote-image.decentralized-content.com/image?url=https%3A%2F%2Fipfs.decentralized-content.com%2Fipfs%2Fbafybeiegrnialwu66u3nwzkn4gik4i2x2h4ip7y3w2dlymzlpxb5lrqbom&w=1920&q=75",
src: 'https://remote-image.decentralized-content.com/image?url=https%3A%2F%2Fipfs.decentralized-content.com%2Fipfs%2Fbafybeiegrnialwu66u3nwzkn4gik4i2x2h4ip7y3w2dlymzlpxb5lrqbom&w=1920&q=75',
tokenUrl: getTokenUrl({
address: "0x060f3edd18c47f59bd23d063bbeb9aa4a8fec6df",
address: '0x060f3edd18c47f59bd23d063bbeb9aa4a8fec6df',
chain: zora,
tokenId: "1",
tokenId: '1',
}),
},
{
src: "https://remote-image.decentralized-content.com/image?url=https%3A%2F%2Fipfs.decentralized-content.com%2Fipfs%2Fbafybeidc6e5t3qmyckqh4fr2ewrov5asmeuv4djycopvo3ro366nd3bfpu&w=1920&q=75",
src: 'https://remote-image.decentralized-content.com/image?url=https%3A%2F%2Fipfs.decentralized-content.com%2Fipfs%2Fbafybeidc6e5t3qmyckqh4fr2ewrov5asmeuv4djycopvo3ro366nd3bfpu&w=1920&q=75',
tokenUrl: getTokenUrl({
address: "0x8f5ed2503b71e8492badd21d5aaef75d65ac0042",
address: '0x8f5ed2503b71e8492badd21d5aaef75d65ac0042',
chain: zora,
tokenId: "3",
tokenId: '3',
}),
},
];
Expand All @@ -60,7 +60,7 @@ const reducer: FrameReducer<State> = (state, action) => {

// This is a react server component only
export default async function Home({ searchParams }: NextServerPageProps) {
const url = currentURL("/examples/mint-button");
const url = currentURL('/examples/mint-button');
const previousFrame = getPreviousFrame<State>(searchParams);
const [state] = useFramesReducer<State>(reducer, initialState, previousFrame);

Expand Down
2 changes: 1 addition & 1 deletion app/examples/multi-page/frames/route.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export { POST } from "frames.js/next/server";
export { POST } from 'frames.js/next/server';
Loading

0 comments on commit dfac316

Please sign in to comment.