pantry/scripts/index-packages.ts
Neil a62c0ea3bb
init step for ingesting/indexing package details (#144)
* #143 init step for ingesting package details

* #143 create reusable workflow for triggering package ingestion/indexing

* space

* #143 create task after uploading bottles

* cleanup

---------

Co-authored-by: neil <neil@neils-MacBook-Pro.local>
2023-02-01 14:13:09 +08:00

43 lines
1.1 KiB
TypeScript
Executable file

#!/usr/bin/env -S tea -E
/*---
args:
- deno
- run
- --allow-read
- --allow-env
- --allow-net
- --allow-sys
- --import-map={{ srcroot }}/import-map.json
---*/
import * as semver from "semver"
import { usePantry } from "hooks"
import * as ARGV from "./utils/args.ts"
import { SQSClient, SendMessageCommand } from "npm:@aws-sdk/client-sqs"
const sqsClient = new SQSClient({ region: 'us-east-1' })
const pantry = usePantry()
const pkgs = await ARGV.toArray(ARGV.pkgs())
for(const { project } of pkgs) {
try {
const yml = await pantry.getYAML({ project, constraint: new semver.Range('*') }).parse()
const taskMessage = {
project,
github: yml?.versions?.github || "",
// TODO: add other useable data here eventually
}
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}`)
} catch (error) {
console.error(error);
}
}