2024-07-09 14:02:25 +00:00
|
|
|
import { YupAPI } from 'yup-api-interact'
|
2024-07-10 08:36:50 +00:00
|
|
|
import { FCHubUtils } from 'farcaster-hub-utils'
|
2024-07-09 14:02:25 +00:00
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
const args = Bun.argv.slice(2);
|
2024-07-09 14:02:25 +00:00
|
|
|
|
2024-07-26 22:21:03 +00:00
|
|
|
const secrets = args[0]
|
2024-07-10 08:36:50 +00:00
|
|
|
const event = args[1]
|
2024-07-09 14:02:25 +00:00
|
|
|
const action = args[2]
|
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
type TGithubEvent = {
|
|
|
|
inputs: {
|
|
|
|
version: string
|
2024-07-26 22:21:03 +00:00
|
|
|
fconly: boolean
|
2024-07-10 08:36:50 +00:00
|
|
|
},
|
|
|
|
forced: boolean,
|
|
|
|
repository: {
|
|
|
|
name: string,
|
|
|
|
full_name: string,
|
|
|
|
html_url: string,
|
|
|
|
description: string
|
|
|
|
},
|
|
|
|
head_commit: {
|
|
|
|
id: string,
|
|
|
|
message: string,
|
|
|
|
timestamp: string,
|
|
|
|
url: string,
|
|
|
|
author: {
|
|
|
|
name: string,
|
|
|
|
email: string,
|
|
|
|
username: string
|
|
|
|
},
|
|
|
|
committer: {
|
|
|
|
name: string,
|
|
|
|
email: string,
|
|
|
|
username: string
|
|
|
|
}
|
|
|
|
}
|
2024-07-26 22:21:03 +00:00
|
|
|
}
|
2024-07-09 14:02:25 +00:00
|
|
|
|
|
|
|
const main = async () => {
|
2024-07-10 08:36:50 +00:00
|
|
|
const ENABLED = true;
|
|
|
|
let YUP_PK = '';
|
|
|
|
let FC_SIGNER = ''
|
2024-07-26 22:21:03 +00:00
|
|
|
let HUB_URL = ''
|
|
|
|
let HUB_USER = ''
|
|
|
|
let HUB_PASS = ''
|
2024-07-10 08:36:50 +00:00
|
|
|
let GithubEvent: TGithubEvent = {} as TGithubEvent;
|
|
|
|
const USER_FID = 709233;
|
|
|
|
|
|
|
|
console.log('Anouncement enabled status: ', '[ ', ENABLED, ' ]');
|
|
|
|
|
|
|
|
try {
|
|
|
|
const parsedSecrets = JSON.parse(secrets);
|
|
|
|
YUP_PK = parsedSecrets.YUP_PK;
|
|
|
|
FC_SIGNER = parsedSecrets.FC_SIGNER;
|
2024-07-26 22:21:03 +00:00
|
|
|
HUB_URL = parsedSecrets.HUB_URL;
|
|
|
|
HUB_USER = parsedSecrets.HUB_USER;
|
|
|
|
HUB_PASS = parsedSecrets.HUB_PASS;
|
2024-07-10 08:36:50 +00:00
|
|
|
GithubEvent = JSON.parse(event);
|
|
|
|
} catch (e) {
|
|
|
|
console.error('Error parsing data', e)
|
|
|
|
}
|
|
|
|
|
2024-07-26 22:21:03 +00:00
|
|
|
const yupAPI = new YupAPI({ PK: YUP_PK });
|
|
|
|
const fchubUtils = new FCHubUtils(FC_SIGNER, USER_FID, HUB_URL, HUB_USER, HUB_PASS);
|
2024-07-10 08:36:50 +00:00
|
|
|
|
2024-07-26 22:21:03 +00:00
|
|
|
if (action === 'update') {
|
2024-07-10 08:36:50 +00:00
|
|
|
const VERSION = GithubEvent.inputs.version;
|
2024-07-26 22:21:03 +00:00
|
|
|
const FCONLY = GithubEvent.inputs.fconly;
|
2024-07-25 21:01:24 +00:00
|
|
|
const message = `Clear Wallet - New version ${VERSION} released! \n
|
|
|
|
ChangeLog: https://bit.ly/clw-cl \n
|
|
|
|
ChromeStore: https://bit.ly/clw-evm \n
|
|
|
|
`
|
2024-07-26 22:21:03 +00:00
|
|
|
if (ENABLED) {
|
|
|
|
if (!FCONLY) {
|
|
|
|
await yupAPI.sendPost({
|
|
|
|
content: message,
|
|
|
|
platforms: ['twitter', 'threads', 'bsky', 'lens']
|
|
|
|
})
|
|
|
|
}
|
2024-07-25 21:01:24 +00:00
|
|
|
const fcPost = await fchubUtils.createFarcasterPost({
|
2024-07-10 08:36:50 +00:00
|
|
|
content: message,
|
|
|
|
})
|
2024-07-25 21:01:24 +00:00
|
|
|
const fcPostHash = Buffer.from(fcPost).toString('hex');
|
2024-07-26 22:21:03 +00:00
|
|
|
if (fcPostHash) {
|
2024-07-25 21:01:24 +00:00
|
|
|
await new Promise((resolve) => setTimeout(resolve, 3000));
|
|
|
|
const launchCasterMessage = `@launch`
|
|
|
|
|
2024-07-26 22:21:03 +00:00
|
|
|
await fchubUtils.createFarcasterPost({
|
|
|
|
content: launchCasterMessage, replyTo: {
|
|
|
|
hash: fcPostHash,
|
|
|
|
fid: String(USER_FID)
|
|
|
|
}
|
|
|
|
})
|
|
|
|
|
2024-07-25 21:01:24 +00:00
|
|
|
}
|
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
} else {
|
|
|
|
console.log('No action required')
|
|
|
|
}
|
2024-07-09 14:02:25 +00:00
|
|
|
|
2024-07-26 22:21:03 +00:00
|
|
|
} else if (action === 'push') {
|
|
|
|
if (ENABLED && !GithubEvent.forced && GithubEvent?.head_commit?.message.includes('chore:') && !GithubEvent?.head_commit?.message.includes('!')) {
|
2024-07-10 08:36:50 +00:00
|
|
|
const commiter = GithubEvent?.head_commit?.author.username || GithubEvent?.head_commit?.committer?.username || ''
|
|
|
|
const message = `Github ClearWallet new repo commit!\n
|
|
|
|
ChromeStore: https://bit.ly/clw-evm \n
|
2024-07-26 22:21:03 +00:00
|
|
|
Commit: ${GithubEvent.head_commit.url} \n
|
|
|
|
${commiter ? `By: ${commiter}` : ''}
|
2024-07-10 08:36:50 +00:00
|
|
|
`;
|
2024-07-26 22:21:03 +00:00
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
await yupAPI.sendPost({
|
|
|
|
content: message,
|
|
|
|
platforms: ['twitter', 'threads', 'bsky', 'lens']
|
|
|
|
})
|
2024-07-09 14:02:25 +00:00
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
await fchubUtils.createFarcasterPost({
|
|
|
|
content: message,
|
|
|
|
})
|
2024-07-26 22:21:03 +00:00
|
|
|
} else {
|
2024-07-10 08:36:50 +00:00
|
|
|
console.log('No action required')
|
2024-07-26 22:21:03 +00:00
|
|
|
}
|
2024-07-09 14:02:25 +00:00
|
|
|
}
|
2024-07-26 22:21:03 +00:00
|
|
|
|
2024-07-10 08:36:50 +00:00
|
|
|
console.log('Workflow executed successfully');
|
2024-07-09 14:02:25 +00:00
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
main().catch(console.error);
|