Skip to content

Commit ab3e74e

Browse files
authored
publish app/component readme to marketplace (PipedreamHQ#3461)
If a README.md is added to an app, action, or trigger directory, it will get published to the Pipedream marketplace. Only three sections are currently supported: Overview, Getting Started, and Troubleshooting. Each section needs to start off with a heading 1 (`#`). Example: ``` # Overview This is an overview of the app ```
1 parent 411e0d9 commit ab3e74e

5 files changed

Lines changed: 183 additions & 6 deletions

File tree

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
on:
2+
push:
3+
branches:
4+
- master
5+
6+
jobs:
7+
publish-components:
8+
name: Publish Marketplace Content to Pipedream
9+
runs-on: ubuntu-latest
10+
steps:
11+
- name: Checkout code
12+
uses: actions/checkout@v3.0.2
13+
- uses: pnpm/action-setup@v2.2.2
14+
with:
15+
version: 7.0.0
16+
- name: Get pnpm store directory
17+
id: pnpm-cache
18+
run: |
19+
echo "::set-output name=pnpm_cache_dir::$(pnpm store path)"
20+
- uses: actions/cache@v3
21+
name: Setup pnpm cache
22+
with:
23+
path: ${{ steps.pnpm-cache.outputs.pnpm_cache_dir }}
24+
key: ${{ runner.os }}-pnpm-store-${{ hashFiles('**/pnpm-lock.yaml') }}
25+
restore-keys: |
26+
${{ runner.os }}-pnpm-store-
27+
- name: Install dependencies
28+
run: pnpm install -r --no-frozen-lockfile --fix-lockfile
29+
- name: Setup Node Env
30+
uses: actions/setup-node@v3.4.1
31+
with:
32+
node-version: 14
33+
registry-url: https://registry.npmjs.org/
34+
cache: 'pnpm'
35+
- name: Get Changed Files
36+
id: files
37+
uses: jitterbit/get-changed-files@v1
38+
with:
39+
format: 'csv'
40+
- name: Publish changes to marketplace content
41+
id: publish
42+
env:
43+
PD_API_KEY: ${{ secrets.PD_API_KEY }}
44+
ENDPOINT: ${{ secrets.ENDPOINT }}
45+
shell: bash {0} # don't fast fail
46+
run: |
47+
echo *** Added or modified
48+
echo ${{ steps.files.outputs.added_modified }}
49+
echo *** Renamed files
50+
echo ${{ steps.files.outputs.renamed }}
51+
echo ** merged lists
52+
printf '%s,%s' '${{ steps.files.outputs.added_modified }}' '${{ steps.files.outputs.renamed }}'
53+
echo *** End
54+
mapfile -d ',' -t added_modified_renamed_files < <(printf '%s,%s' '${{ steps.files.outputs.added_modified }}' '${{ steps.files.outputs.renamed }}')
55+
56+
pnpm dlx ts-node --esm scripts/updateMarketplaceReadme.mts $added_modified_renamed_files
57+

package.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,13 @@
4444
"eslint-plugin-jsonc": "^1.6.0",
4545
"eslint-plugin-pipedream": "0.2.4",
4646
"eslint-plugin-putout": "^15.1.1",
47+
"graphql-request": "^3.7.0",
4748
"husky": "^7.0.4",
4849
"jest": "^27.5.1",
4950
"lint-staged": "^12.3.4",
5051
"pnpm": "^7.0.1",
5152
"putout": ">=20",
53+
"graphql": "^16.2.0",
5254
"renamer": "^4.0.0",
5355
"ts-jest": "^27.1.4",
5456
"tsc-esm-fix": "^2.18.0",

pnpm-lock.yaml

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
import * as path from "node:path";
2+
import * as fs from "node:fs";
3+
import { GraphQLClient, gql } from "graphql-request";
4+
import * as Sentry from "@sentry/node";
5+
6+
Sentry.init({
7+
dsn: process.env.SENTRY_DSN,
8+
tracesSampleRate: 1.0,
9+
environment: process.env.CI ? "production" : "development",
10+
});
11+
12+
const pdClient = new GraphQLClient(
13+
"https://api.pipedream.com/graphql",
14+
{
15+
headers: {
16+
Authorization: `Bearer ${process.env.PD_API_KEY}`,
17+
},
18+
}
19+
);
20+
21+
// This script expects the first argument to be a comma separated list of file paths.
22+
// Example: `ts-node scripts/updateMarketplaceReadme.mts components/slack/README.md,components/slack/actions/add-star/README.md`
23+
const run = async () => {
24+
const fileCsv = process.argv[2] || "";
25+
26+
const filePaths = fileCsv.split(",").filter(Boolean);
27+
28+
const readmePaths = filePaths.filter(
29+
(p) => p.startsWith("components/") && p.endsWith("/README.md")
30+
);
31+
32+
for (const readmePath of readmePaths) {
33+
const fullReadmePath = path.join(process.cwd(), readmePath);
34+
35+
console.log("processing file", fullReadmePath);
36+
37+
const b64 = fs.readFileSync(fullReadmePath).toString("base64");
38+
39+
const pathSegments = readmePath.split("/");
40+
41+
let key: string;
42+
43+
if (pathSegments.length === 3) {
44+
key = pathSegments[1];
45+
} else if (pathSegments.length === 5) {
46+
key = pathSegments[1] + "-" + pathSegments[3];
47+
} else {
48+
Sentry.captureMessage(
49+
"Unable to determine app/component key from file path.",
50+
{
51+
level: "error",
52+
extra: {
53+
readmePath,
54+
fullReadmePath,
55+
},
56+
}
57+
);
58+
console.warn(
59+
`"${readmePath}" is an invalid path. Cannot determine if this is an app or a component. Skipping...`
60+
);
61+
continue;
62+
}
63+
64+
const query = gql`
65+
mutation addNewMarketplaceEntry(
66+
$markdownB64: String!
67+
$path: String!
68+
$key: String!
69+
) {
70+
marketplaceContentSet(
71+
key: $key
72+
markdownB64: $markdownB64
73+
path: $path
74+
) {
75+
marketplaceContent {
76+
id
77+
}
78+
errors
79+
}
80+
}
81+
`;
82+
83+
const variables = {
84+
key,
85+
markdownB64: b64,
86+
path: readmePath,
87+
};
88+
89+
try {
90+
const response = await pdClient.request(query, variables);
91+
92+
if (response?.marketplaceContentSet?.errors?.length > 0) {
93+
Sentry.captureMessage("Set marketplace content error", {
94+
level: "error",
95+
extra: {
96+
errors: response.marketplaceContentSet.errors,
97+
key,
98+
fullReadmePath,
99+
readmePath,
100+
},
101+
});
102+
}
103+
104+
console.log(JSON.stringify(response, null, 2));
105+
} catch (e) {
106+
Sentry.captureException(e, {
107+
extra: {
108+
key,
109+
fullReadmePath,
110+
readmePath,
111+
},
112+
});
113+
}
114+
}
115+
};
116+
117+
run();

tsconfig.json

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
"outDir": "dist",
55
"composite": true,
66
"baseUrl": ".",
7-
"rootDir": "."
7+
"rootDir": ".",
8+
"moduleResolution": "node"
89
},
910
"exclude": [
1011
"components"
@@ -450,4 +451,4 @@
450451
"path": "components/exact"
451452
}
452453
]
453-
}
454+
}

0 commit comments

Comments
 (0)