From 680b5bf9e909e2ae6d9250f825ff76d58baa3aa9 Mon Sep 17 00:00:00 2001 From: Jacob Heider Date: Thu, 12 Jan 2023 18:27:46 -0500 Subject: [PATCH] this works better than a poor-quality shell pipeline --- .github/workflows/cd.yml | 10 +++---- scripts/map-projects-to-githubs.ts | 42 ++++++++++++++++++++++++++++++ 2 files changed, 46 insertions(+), 6 deletions(-) create mode 100755 scripts/map-projects-to-githubs.ts diff --git a/.github/workflows/cd.yml b/.github/workflows/cd.yml index a77df9b5..ffc9ae61 100644 --- a/.github/workflows/cd.yml +++ b/.github/workflows/cd.yml @@ -11,13 +11,11 @@ jobs: HAS_ARTIFACTS: ${{ env.HAS_ARTIFACTS }} steps: - uses: actions/checkout@v3 - - run: > - grep -E ' github: [^\w]+/[^\w/]+' projects/**/package.yml | - sed -e 's|^projects/\(.*\)/package.yml: *github: \([^/]*/[^/]*\).*|{ "project": "\1", "github": "\2" }|' | - jq -sc . | - curl https://app.tea.xyz/api/receiveWatcherProjects --fail -X PUT \ - -H "content-type: application/json" -H "authorization: bearer ${{ secrets.TEA_API_TOKEN }}" -d @- - uses: teaxyz/setup@v0 + - run: ./scripts/map-projects-to-githubs.ts + env: + WATCHER_URL: ${{ secrets.WATCHER_URL }} + TEA_API_TOKEN: ${{ secrets.TEA_API_TOKEN }} - run: ./scripts/has-artifacts.ts ${{ github.repository }} ${{ github.sha }} >>$GITHUB_ENV env: GITHUB_TOKEN: ${{github.token}} diff --git a/scripts/map-projects-to-githubs.ts b/scripts/map-projects-to-githubs.ts new file mode 100755 index 00000000..ba328bba --- /dev/null +++ b/scripts/map-projects-to-githubs.ts @@ -0,0 +1,42 @@ +#!/usr/bin/env -S tea -E + +/*--- +args: + - deno + - run + - --allow-read + - --allow-env + - --allow-net + - --import-map={{ srcroot }}/import-map.json +---*/ + +import { usePantry } from "hooks" +import { panic } from "utils" +import * as semver from "semver" + +const url = Deno.env.get("WATCHER_URL") ?? panic("missing $WATCHER_URL") +const token = Deno.env.get("TEA_API_TOKEN") ?? panic("missing $TEA_API_TOKEN") + +const pantry = usePantry() + +const rv: Set<{project: string, github: string}> = new Set() + +for await (const {project} of pantry.ls()) { + const yml = await pantry.getYAML({project, constraint: new semver.Range('*') }).parse() + if (yml?.versions?.github) { + const github = yml.versions.github.split('/').slice(0, 2).join('/') + rv.add({ project, github }) + } +} + +const options = { + method: 'PUT', + headers: { + 'Content-Type': 'application/json', + 'Authorization': `bearer ${token}`, + }, + body: JSON.stringify([...rv]), +} + +console.log(rv) +await fetch(url, options) \ No newline at end of file