-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request 'build: declarations patch workflow' (#1) from pat…
…ch-workflow into master
- Loading branch information
Showing
7 changed files
with
243 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
name: publish | ||
|
||
permissions: | ||
contents: write | ||
|
||
on: | ||
workflow_dispatch: | ||
|
||
jobs: | ||
publish: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout Repository | ||
uses: actions/checkout@v4 | ||
|
||
- name: Setup Git | ||
run: | | ||
re=$(curl --silent --header "Accept: application/json" "https://api.github.com/users/github-actions%5Bbot%5D") | ||
lo=$(echo "$re" | jq --raw-output ".login") | ||
id=$(echo "$re" | jq --raw-output ".id") | ||
git config --global user.name "$lo" | ||
git config --global user.email "[email protected]" | ||
- name: Setup mise | ||
uses: jdx/mise-action@v2 | ||
|
||
- name: Install Dependencies | ||
run: pnpm install --frozen-lockfile | ||
|
||
- name: Build Declarations | ||
run: pnpm build | ||
|
||
- name: Publish Declarations | ||
working-directory: dist | ||
run: | | ||
un=$(git config --get user.name) | ||
ru="${{github.server_url}}/${{github.repository}}.git" | ||
ru=$(echo "$ru" | sed "s#https://#https://$un:${{github.token}}@#") | ||
td=$(mktemp -d) | ||
git clone --quiet --no-checkout --single-branch --branch dist "$ru" "$td" | ||
mv "$td/.git" . | ||
git add . | ||
if git diff-index --quiet HEAD --; then | ||
echo "No changes to commit" | ||
else | ||
git commit --quiet --message "$(date --utc)" | ||
git push | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
dist |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
[tools] | ||
node = "prefix:22" | ||
pnpm = "prefix:9" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
{ | ||
"compilerOptions": { | ||
"strict": true, | ||
"module": "NodeNext", | ||
"moduleResolution": "NodeNext", | ||
"resolveJsonModule": true, | ||
"rootDir": ".", | ||
"noEmit": true, | ||
"outDir": "./dist", | ||
"allowJs": true, | ||
"checkJs": true, | ||
"target": "ESNext", | ||
"skipLibCheck": true | ||
}, | ||
"include": [ | ||
"./makefile.js" | ||
] | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import {argv} from "node:process" | ||
import {existsSync} from "node:fs" | ||
import {fileURLToPath} from "node:url" | ||
import {join} from "node:path" | ||
import {mkdir, writeFile} from "node:fs/promises" | ||
import {OpenAPIV3 as OpenApi} from "openapi-types" | ||
import sade from "sade" | ||
|
||
const config = { | ||
source: { | ||
owner: "onlyoffice", | ||
repo: "docspace-declarations", | ||
reference: "src", | ||
paths: [ | ||
{name: "data", path: "asc.data.backup.swagger.json"}, | ||
{name: "files", path: "asc.files.swagger.json"}, | ||
{name: "people", path: "asc.people.swagger.json"}, | ||
{name: "web", path: "asc.web.api.swagger.json"}, | ||
], | ||
}, | ||
} | ||
|
||
main() | ||
|
||
/** | ||
* @returns {void} | ||
*/ | ||
function main() { | ||
sade("./makefile.js") | ||
.command("build") | ||
.action(build) | ||
.parse(argv) | ||
} | ||
|
||
/** | ||
* @returns {Promise<void>} | ||
*/ | ||
async function build(){ | ||
const c = config.source | ||
|
||
const rd = rootDir() | ||
|
||
const dd = distDir(rd) | ||
if (!existsSync(dd)) { | ||
await mkdir(dd) | ||
} | ||
//TODO: console info? | ||
for (const p of c.paths){ | ||
const u = `https://raw.githubusercontent.com/${c.owner}/${c.repo}/${c.reference}/${p.path}` | ||
const r = await (await fetch(u)).json() | ||
patch(r) | ||
const dp = join(dd, p.path) | ||
const ds = JSON.stringify(r, null, 2) | ||
await writeFile(dp, ds) | ||
} | ||
} | ||
|
||
/** | ||
* @param {OpenApi.Document<{}>} d | ||
* @returns {void} | ||
*/ | ||
function patch(d) { | ||
for (const pn in d.paths){ | ||
const po = d.paths[pn] | ||
if (!po) { | ||
continue | ||
} | ||
|
||
// https://github.com/ONLYOFFICE/DocSpace-server/blob/v2.0.2-server/web/ASC.Web.Api/Api/CapabilitiesController.cs#L33 | ||
if (pn.endsWith("{.format}")) { | ||
delete d.paths[pn] | ||
continue | ||
} | ||
|
||
for (const mn of Object.values(OpenApi.HttpMethods)) { | ||
const mo = po[mn] | ||
if (!mo) { | ||
continue | ||
} | ||
|
||
if (mo.description) { | ||
mo.description = `**Note**: ${mo.description}` | ||
} | ||
|
||
if (mo.summary) { | ||
if (!mo.description) { | ||
mo.description = mo.summary | ||
} else { | ||
mo.description = `${mo.summary}\n\n${mo.description}` | ||
} | ||
} | ||
|
||
if ("x-shortName" in mo && typeof mo["x-shortName"] === "string") { | ||
mo.summary = mo["x-shortName"] | ||
} | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* @returns {string} | ||
*/ | ||
function rootDir() { | ||
const u = new URL(".", import.meta.url) | ||
return fileURLToPath(u) | ||
} | ||
|
||
/** | ||
* @param {string} d | ||
* @returns {string} | ||
*/ | ||
function distDir(d) { | ||
return join(d, "dist") | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "docspace-declarations", | ||
"private": true, | ||
"type": "module", | ||
"scripts": { | ||
"build": "pnpm make build", | ||
"make": "node ./makefile.js" | ||
}, | ||
"devDependencies": { | ||
"openapi-types": "^12.1.3", | ||
"sade": "^1.8.1" | ||
}, | ||
"engines": { | ||
"node": "^22" | ||
} | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.