pantry/.github/scripts/index-packages.ts

61 lines
1.7 KiB
TypeScript
Raw Normal View History

#!/usr/bin/env -S tea -E
2023-06-19 17:05:52 +03:00
/*---
args:
- deno
- run
- --allow-read
- --allow-net
- --allow-env
- --allow-sys
dependencies:
deno.land: =1.34.2
---*/
import { SQSClient, SendMessageCommand } from "npm:@aws-sdk/client-sqs@^3"
2023-06-13 02:20:31 +03:00
import { SNSClient, PublishCommand } from "npm:@aws-sdk/client-sns@^3"
2023-06-19 17:05:52 +03:00
import * as ARGV from "./utils/args.ts"
import { hooks, utils } from "tea"
const { usePantry } = hooks
2023-06-19 17:05:52 +03:00
const region = Deno.env.get("AWS_REGION") ?? utils.panic("No region specified")
2023-06-13 02:10:04 +03:00
const sqsClient = new SQSClient({ region })
const snsClient = new SNSClient({ region })
const pantry = usePantry()
const pkgs = await ARGV.toArray(ARGV.pkgs())
for(const pkg of pkgs) {
try {
2023-06-19 17:05:52 +03:00
const yml = await pantry.project(pkg).yaml()
const project = pkg.project
const taskMessage = {
project,
github: yml?.versions?.github || "",
// TODO: add other useable data here eventually
}
2023-06-13 02:10:04 +03:00
// DEPRECATED: This is the old way of doing things
const res = await sqsClient.send(new SendMessageCommand({
MessageGroupId: 'project',
MessageDeduplicationId: project,
MessageBody: JSON.stringify(taskMessage),
QueueUrl: Deno.env.get("SQS_GENERATE_PACKAGE_DETAILS_URL")!,
}))
console.log(`SQS task for pkg:${project} messageId:${res.MessageId}`)
2023-06-13 02:10:04 +03:00
const snsMessage = await snsClient.send(new PublishCommand({
TopicArn: Deno.env.get("SNS_NEW_PACKAGES_TOPIC")!,
Message: JSON.stringify(taskMessage),
MessageGroupId: 'project',
MessageDeduplicationId: project,
}))
console.log(`SNS message published for pkg:${project} messageId:${snsMessage.MessageId}`)
} catch (error) {
console.error(error);
}
}