Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion .github/workflows/main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ name: main
on: [push]

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

steps:
Expand All @@ -30,3 +30,17 @@ jobs:
- run: pnpm lint

- run: pnpm test

- run: pnpm build

- run: npm pack
working-directory: dist

- name: npm publish
run: |
echo "//registry.npmjs.org/:_authToken=$NPM_TOKEN" > .npmrc
mv dist/*.tgz pack.tgz
npm publish pack.tgz
# if: success() && github.ref == 'refs/heads/master'
env:
NPM_TOKEN: ${{ secrets.NPM_TOKEN }}
24 changes: 5 additions & 19 deletions .github/workflows/solve-daily.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,32 +13,18 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: pnpm/action-setup@v2
with:
version: 6
- uses: actions/setup-node@v2
with:
node-version: 16
cache: pnpm
- run: npm install platane-wordle-bot

- run: pnpm install --frozen-lockfile

- name: cache word list
uses: actions/cache@v2
with:
path: node_modules/wordList-cache.txt
key: wordList-cache
restore-keys: wordList-cache

- run: pnpm twitter-refresh
- run: npm run twitter-refresh
working-directory: node_modules/platane-wordle-bot
env:
GITHUB_TOKEN: ${{ secrets.MY_GITHUB_TOKEN }}
TWITTER_CLIENT_ID: ${{ secrets.TWITTER_CLIENT_ID }}
TWITTER_CLIENT_SECRET: ${{ secrets.TWITTER_CLIENT_SECRET }}
TWITTER_REFRESH_TOKEN: ${{ secrets.TWITTER_REFRESH_TOKEN }}

- run: pnpm start
- run: npm run solve
working-directory: node_modules/platane-wordle-bot
env:
GITHUB_REPOSITORY: ${{ github.repository }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
dist
node_modules
.env
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"@types/jest": "27.4.1",
"@types/node": "16.11.11",
"@types/node-fetch": "2.5.11",
"@vercel/ncc": "0.33.3",
"jest": "27.5.1",
"prettier": "2.6.0",
"sucrase": "3.20.3",
Expand All @@ -31,6 +32,7 @@
}
},
"scripts": {
"build": "ncc build src/twitter/auth.ts -o dist/twitter-auth && ncc build src/twitter/refresh.ts -o dist/twitter-refresh && ncc build src/index.ts -o dist/solve -e puppeteer -e puppeteer-screen-recorder && node -e \"const pkg=require('./package.json');console.log(JSON.stringify({name:'platane-wordle-bot',version:pkg.version+'-'+process.env.GITHUB_RUN_NUMBER,dependencies:{puppeteer:pkg.dependencies.puppeteer,'puppeteer-screen-recorder':pkg.dependencies['puppeteer-screen-recorder']},scripts:{solve:'node solve/index.js','twitter-refresh':'node twitter-refresh/index.js','twitter-auth':'node twitter-auth/index.js'}}))\" > dist/package.json ",
"twitter-auth": "sucrase-node src/twitter/auth.ts",
"twitter-refresh": "sucrase-node src/twitter/refresh.ts",
"start": "sucrase-node src/index.ts",
Expand Down
7 changes: 7 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

7 changes: 3 additions & 4 deletions src/twitter/auth.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import * as http from "http";
import * as path from "path";
import type { Socket } from "net";
import TwitterApi from "twitter-api-v2";
import "dotenv/config";
import { writeDotEnv } from "./writeDotEnv";
import { createSecretUpdater } from "github-secret-dotenv/lib/github";
import { readPackageJson } from "github-secret-dotenv/lib/readPackageJson";
import { getRepository } from "./getRepository";

const CALLBACK_URL = "http://localhost:4194/callback";

Expand Down Expand Up @@ -74,15 +73,15 @@ const CALLBACK_URL = "http://localhost:4194/callback";
console.log(data, { expiresIn });
}

writeDotEnv(path.join(__dirname, "../../.env"), {
writeDotEnv(".env", {
TWITTER_ACCESS_TOKEN: accessToken,
TWITTER_REFRESH_TOKEN: refreshToken!,
});

console.log("written to .env");

const updateSecret = createSecretUpdater({
...readPackageJson(path.join(__dirname, "../.."))!,
...getRepository()!,
githubAccessToken:
process.env.GITHUB_ACCESS_TOKEN ?? process.env.GITHUB_TOKEN!,
});
Expand Down
12 changes: 12 additions & 0 deletions src/twitter/getRepository.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { readPackageJson } from "github-secret-dotenv/lib/readPackageJson";

const readRepository = () => {
const [owner, repo] = (process.env.GITHUB_REPOSITORY ?? "").split("/");
if (!repo) return undefined;
return { owner, repo };
};

export const getRepository = () => ({
...readRepository(),
...readPackageJson()!,
});
7 changes: 3 additions & 4 deletions src/twitter/refresh.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
import * as path from "path";
import TwitterApi from "twitter-api-v2";
import { writeDotEnv } from "./writeDotEnv";
import { createSecretUpdater } from "github-secret-dotenv/lib/github";
import { readPackageJson } from "github-secret-dotenv/lib/readPackageJson";
import { getRepository } from "./getRepository";
import "dotenv/config";

/**
Expand All @@ -29,15 +28,15 @@ import "dotenv/config";
console.log(data, { expiresIn });
}

writeDotEnv(path.join(__dirname, "../../.env"), {
writeDotEnv(".env", {
TWITTER_ACCESS_TOKEN: accessToken,
TWITTER_REFRESH_TOKEN: refreshToken!,
});

console.log("written to .env");

const updateSecret = createSecretUpdater({
...readPackageJson(path.join(__dirname, "../.."))!,
...getRepository()!,
githubAccessToken:
process.env.GITHUB_ACCESS_TOKEN ?? process.env.GITHUB_TOKEN!,
});
Expand Down