new release version v1_20_10_23 #44
6
.github/workflows/deploy.yaml
vendored
6
.github/workflows/deploy.yaml
vendored
@ -4,15 +4,11 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- main
|
- main
|
||||||
|
|
||||||
permissions:
|
permissions: write-all
|
||||||
contents: read
|
|
||||||
pages: write
|
|
||||||
id-token: write
|
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
findVersion:
|
findVersion:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
name: "server ${{ matrix.platform }}"
|
|
||||||
environment:
|
environment:
|
||||||
name: github-pages
|
name: github-pages
|
||||||
url: ${{ steps.deployment.outputs.page_url }}
|
url: ${{ steps.deployment.outputs.page_url }}
|
||||||
|
12
.github/workflows/find.yaml
vendored
12
.github/workflows/find.yaml
vendored
@ -10,13 +10,14 @@ on:
|
|||||||
jobs:
|
jobs:
|
||||||
findVersion:
|
findVersion:
|
||||||
runs-on: ubuntu-latest
|
runs-on: ubuntu-latest
|
||||||
env:
|
|
||||||
UPLOAD: "false"
|
|
||||||
VERSION: "0.1.0"
|
|
||||||
permissions:
|
permissions:
|
||||||
|
id-token: write
|
||||||
pull-requests: write
|
pull-requests: write
|
||||||
issues: write
|
issues: write
|
||||||
contents: write
|
contents: write
|
||||||
|
env:
|
||||||
|
UPLOAD: "false"
|
||||||
|
VERSION: "0.1.0"
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
name: Checkout code
|
name: Checkout code
|
||||||
@ -39,11 +40,11 @@ jobs:
|
|||||||
run: npm run updateVesion
|
run: npm run updateVesion
|
||||||
env:
|
env:
|
||||||
GITHUB_SECRET: ${{ secrets.GITHUB_TOKEN }}
|
GITHUB_SECRET: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
|
||||||
# Create pull request to update version in main branch
|
# Create pull request to update version in main branch
|
||||||
- uses: peter-evans/create-pull-request@v4
|
- uses: peter-evans/create-pull-request@v5
|
||||||
name: Create Pull Request
|
name: Create Pull Request
|
||||||
continue-on-error: true
|
|
||||||
if: env.UPLOAD == 'true'
|
if: env.UPLOAD == 'true'
|
||||||
with:
|
with:
|
||||||
commit-message: New Minecraft bedrock server release (${{ env.VERSION }})
|
commit-message: New Minecraft bedrock server release (${{ env.VERSION }})
|
||||||
@ -53,3 +54,4 @@ jobs:
|
|||||||
branch: version_update_${{ env.VERSION }}
|
branch: version_update_${{ env.VERSION }}
|
||||||
title: new release version v${{ env.VERSION }}
|
title: new release version v${{ env.VERSION }}
|
||||||
body: Auto update version, created with GitHub Actions
|
body: Auto update version, created with GitHub Actions
|
||||||
|
add-paths: "."
|
||||||
|
735
package-lock.json
generated
735
package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@ -31,14 +31,14 @@
|
|||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@types/adm-zip": "^0.5.0",
|
"@types/adm-zip": "^0.5.0",
|
||||||
"@types/node": "^20.2.5",
|
"@types/node": "^20.3.1",
|
||||||
"@types/tar": "^6.1.5",
|
"@types/tar": "^6.1.5",
|
||||||
"ts-node": "^10.9.1",
|
"ts-node": "^10.9.1",
|
||||||
"typescript": "^4.9.5"
|
"typescript": "^5.1.3"
|
||||||
},
|
},
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
"@actions/github": "^5.1.1",
|
"@actions/github": "^5.1.1",
|
||||||
"@sirherobrine23/http": "^3.6.11",
|
"@sirherobrine23/http": "^3.6.12",
|
||||||
"adm-zip": "^0.5.10",
|
"adm-zip": "^0.5.10",
|
||||||
"compare-versions": "^6.0.0-rc.1",
|
"compare-versions": "^6.0.0-rc.1",
|
||||||
"tar": "^6.1.15"
|
"tar": "^6.1.15"
|
||||||
|
19
src/find.ts
19
src/find.ts
@ -2,11 +2,9 @@ import { http } from "@sirherobrine23/http";
|
|||||||
import AdmZip from "adm-zip";
|
import AdmZip from "adm-zip";
|
||||||
import { compareVersions } from "compare-versions";
|
import { compareVersions } from "compare-versions";
|
||||||
import { createWriteStream } from "node:fs";
|
import { createWriteStream } from "node:fs";
|
||||||
import fs from "node:fs/promises";
|
|
||||||
import { tmpdir } from "node:os";
|
import { tmpdir } from "node:os";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import streamConsumer from "node:stream/promises";
|
import streamConsumer from "node:stream/promises";
|
||||||
import tar from "tar";
|
|
||||||
|
|
||||||
export type bedrockSchema = {
|
export type bedrockSchema = {
|
||||||
version: string,
|
version: string,
|
||||||
@ -63,28 +61,21 @@ export async function find() {
|
|||||||
return mount;
|
return mount;
|
||||||
}, {});
|
}, {});
|
||||||
const data: bedrockSchema[] = [];
|
const data: bedrockSchema[] = [];
|
||||||
|
|
||||||
await Promise.all(Object.keys(objURLs).map(async version => {
|
await Promise.all(Object.keys(objURLs).map(async version => {
|
||||||
let release: any;
|
let release: any;
|
||||||
const versionData = objURLs[version];
|
const versionData = objURLs[version];
|
||||||
await Promise.all(keys(versionData).map(platform => keys(versionData[platform]).map(async arch => {
|
await Promise.all(keys(versionData).map(platform => keys(versionData[platform]).map(async arch => {
|
||||||
const fileUrl = new URL(versionData[platform][arch].zip);
|
const fileUrl = new URL(versionData[platform][arch].zip);
|
||||||
const tmpFile = versionData[platform][arch].zip = path.join(tmpdir(), `${platform}_${arch}_` + path.basename(fileUrl.pathname));
|
const filePath = versionData[platform][arch].zip = path.join(tmpdir(), `${platform}_${arch}_` + path.basename(fileUrl.pathname));
|
||||||
const folderPath = tmpFile.slice(0, -(path.extname(tmpFile).length));
|
console.log("Downloading %O on %O path", fileUrl.toString(), filePath);
|
||||||
const tgzPath = versionData[platform][arch].tgz = folderPath + ".tgz";
|
await streamConsumer.pipeline(await http.streamRequest(fileUrl), createWriteStream(filePath));
|
||||||
await streamConsumer.pipeline(await http.streamRequest(fileUrl), createWriteStream(tmpFile));
|
|
||||||
await new Promise<void>((done, reject) => (new AdmZip(tmpFile)).extractAllToAsync(folderPath, true, true, err => err ? reject(err) : done()));
|
|
||||||
await tar.create({
|
|
||||||
gzip: true,
|
|
||||||
file: tgzPath,
|
|
||||||
cwd: folderPath,
|
|
||||||
}, await fs.readdir(folderPath));
|
|
||||||
await fs.rm(folderPath, { recursive: true, force: true });
|
|
||||||
release = ((/preview/).test(fileUrl.toString())) ? "preview" : "oficial";
|
release = ((/preview/).test(fileUrl.toString())) ? "preview" : "oficial";
|
||||||
})).flat(2));
|
})).flat(2));
|
||||||
const ff = keys(versionData).map(plt => keys(versionData[plt]).map(arch => versionData[plt][arch])).flat(3).at(0).zip;
|
const ff = keys(versionData).map(plt => keys(versionData[plt]).map(arch => versionData[plt][arch])).flat(3).at(0).zip;
|
||||||
const zip = new AdmZip(ff);
|
const zip = new AdmZip(ff);
|
||||||
const bedrockInfo = zip.getEntries().find(file => file.name.startsWith("bedrock_server"));
|
const bedrockInfo = zip.getEntries().find(file => file.name.startsWith("bedrock_server"));
|
||||||
data.push({
|
if (bedrockInfo) data.push({
|
||||||
version: version,
|
version: version,
|
||||||
date: bedrockInfo.header.time,
|
date: bedrockInfo.header.time,
|
||||||
release,
|
release,
|
||||||
|
97
src/index.ts
97
src/index.ts
@ -1,57 +1,80 @@
|
|||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
import { Github } from "@sirherobrine23/http";
|
import { Github } from "@sirherobrine23/http";
|
||||||
|
import AdmZip from "adm-zip";
|
||||||
import { compareVersions } from "compare-versions";
|
import { compareVersions } from "compare-versions";
|
||||||
import { createReadStream } from "node:fs";
|
import { createReadStream } from "node:fs";
|
||||||
import fs from "node:fs/promises";
|
import fs from "node:fs/promises";
|
||||||
import path from "node:path";
|
import path from "node:path";
|
||||||
import { finished } from "node:stream/promises";
|
import { pipeline } from "node:stream/promises";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
import tar from "tar";
|
||||||
import { bedrockSchema, find, keys } from "./find.js";
|
import { bedrockSchema, find, keys } from "./find.js";
|
||||||
|
|
||||||
const gh = await Github.repositoryManeger("Sirherobrine23", "BedrockFetch");
|
function errCatch(err) {
|
||||||
|
console.error(err);
|
||||||
|
process.exitCode = -1;
|
||||||
|
}
|
||||||
|
process.on("rejectionHandled", errCatch);
|
||||||
|
process.on("unhandledRejection", errCatch);
|
||||||
|
|
||||||
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
const __dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||||
const versionPath = path.resolve(__dirname, "../versions");
|
const versionPath = path.resolve(__dirname, "../versions");
|
||||||
const allPath = path.join(versionPath, "all.json");
|
const allPath = path.join(versionPath, "all.json");
|
||||||
let __versions: bedrockSchema[] = JSON.parse(await fs.readFile(allPath, "utf8"));
|
const gh = await Github.repositoryManeger("Sirherobrine23", "BedrockFetch", { token: process.env.GITHUB_TOKEN });
|
||||||
__versions = __versions.sort((b, a) => compareVersions(a.version, b.version));
|
|
||||||
const versions = new Map<string, Omit<bedrockSchema, "version">>(__versions.map(v => ([v.version, { date: v.date, release: v.release, url: v.url }])));
|
const __versions: bedrockSchema[] = JSON.parse(await fs.readFile(allPath, "utf8"));
|
||||||
|
const versions = new Map<string, Omit<bedrockSchema, "version">>(__versions.sort((b, a) => compareVersions(a.version, b.version)).map(v => ([v.version, { date: v.date, release: v.release, url: v.url }])));
|
||||||
|
|
||||||
console.log("Finding new server versions");
|
console.log("Finding new server versions");
|
||||||
const newVersions = await find();
|
const remoteURLs = await find();
|
||||||
let upload = false;
|
|
||||||
for (const rel of newVersions) {
|
for (const remoteURL of remoteURLs) {
|
||||||
if (versions.has(rel.version)) {
|
if (versions.has(remoteURL.version)) {
|
||||||
console.log("%s are added in database", rel.version);
|
console.log("Skiping %s so added to Releases and Versions!");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
const release = await gh.release.manegerRelease(rel.version, {
|
|
||||||
type: rel.release === "preview" ? "preRelease" : undefined,
|
console.log("Creating %s release", remoteURL.version);
|
||||||
releaseName: rel.version,
|
const release = await gh.release.manegerRelease(remoteURL.version, {
|
||||||
releaseBody: ([
|
type: remoteURL.release === "preview" ? "preRelease" : undefined,
|
||||||
`# ${rel.release} ${rel.version} ${rel.date.toUTCString()}`,
|
releaseName: remoteURL.version,
|
||||||
"",
|
releaseBody: ([`# ${remoteURL.date.toUTCString()} ${remoteURL.version}`, "",]).join("\n"),
|
||||||
`Auto fetch Minecraft bedrock server and release to Public, By @Sirherobrine23 and Github actions`
|
|
||||||
]).join("\n"),
|
|
||||||
});
|
});
|
||||||
console.log("Add %s to versions", rel.version);
|
console.log("Created %s", remoteURL.version);
|
||||||
if (!upload && process.env.GITHUB_ENV) {
|
|
||||||
const githubEnv = path.resolve(process.env.GITHUB_ENV);
|
await Promise.all(keys(remoteURL.url).map(platform => keys(remoteURL.url[platform]).map(async (arch) => {
|
||||||
upload = true;
|
let remoteName = `${platform}_${arch}.zip`;
|
||||||
await fs.writeFile(githubEnv, `VERSION=${rel.version}\nUPLOAD=true`);
|
const filePath = remoteURL.url[platform][arch].zip;
|
||||||
}
|
const zipStats = await fs.lstat(filePath);
|
||||||
await Promise.all(keys(rel.url).map(platform => keys(rel.url[platform]).map(arch => keys(rel.url[platform][arch]).map(async file => {
|
console.log("Uploading %s %O", remoteURL.version, remoteName);
|
||||||
const basename = path.basename(rel.url[platform][arch][file]);
|
if (!(release.getLocaAssets()[remoteName])) await pipeline(createReadStream(filePath), release.uploadAsset(remoteName, zipStats.size).on("fileAssest", (rel: Github.githubRelease["assets"][number]) => remoteURL.url[platform][arch].zip = rel.browser_download_url));
|
||||||
const fileStats = await fs.lstat(rel.url[platform][arch][file]);
|
console.log("done uploaded %s %O", remoteURL.version, remoteName);
|
||||||
await finished(createReadStream(rel.url[platform][arch][file]).pipe(release.uploadAsset(basename, fileStats.size)));
|
|
||||||
rel.url[platform][arch][file] = `https://github.com/Sirherobrine23/BedrockFetch/releases/download/${rel.version}/${basename}`;
|
const folderPath = filePath.slice(0, -4);
|
||||||
}))).flat(3));
|
const tgzPath = folderPath + ".tgz";
|
||||||
versions.set(rel.version, {
|
await new Promise<void>((done, reject) => (new AdmZip(filePath)).extractAllToAsync(folderPath, true, true, err => err ? reject(err) : done()));
|
||||||
date: rel.date,
|
await tar.create({
|
||||||
release: rel.release,
|
gzip: true,
|
||||||
url: rel.url
|
file: tgzPath,
|
||||||
|
cwd: folderPath,
|
||||||
|
}, await fs.readdir(folderPath));
|
||||||
|
|
||||||
|
const tgzStats = await fs.lstat(tgzPath);
|
||||||
|
remoteName = `${platform}_${arch}.tgz`;
|
||||||
|
console.log("Uploading %s %O", remoteURL.version, remoteName);
|
||||||
|
if (!(release.getLocaAssets()[remoteName])) await pipeline(createReadStream(tgzPath), release.uploadAsset(remoteName, tgzStats.size).on("fileAssest", (rel: Github.githubRelease["assets"][number]) => remoteURL.url[platform][arch].tgz = rel.browser_download_url));
|
||||||
|
console.log("done uploaded %s %O", remoteURL.version, remoteName);
|
||||||
|
|
||||||
|
for (const ff of ([tgzPath, filePath, folderPath])) await fs.rm(ff, { recursive: true, force: true });
|
||||||
|
})).flat(3))
|
||||||
|
|
||||||
|
if (process.env.GITHUB_ENV) await fs.writeFile(path.resolve(process.env.GITHUB_ENV), `VERSION=${remoteURL.version.split(".").join("_")}\nUPLOAD=true`);
|
||||||
|
versions.set(remoteURL.version, {
|
||||||
|
date: remoteURL.date,
|
||||||
|
release: remoteURL.release,
|
||||||
|
url: remoteURL.url
|
||||||
});
|
});
|
||||||
|
await fs.writeFile(allPath, JSON.stringify(Array.from(versions.keys()).sort(compareVersions).map(version => Object.assign({ version }, versions.get(version))), null, 2));
|
||||||
}
|
}
|
||||||
|
|
||||||
const vers = Array.from(versions.keys()).sort((b, a) => compareVersions(a, b)).map(v => ({ version: v, ...(versions.get(v)) }));
|
await Promise.all(Array.from(versions.keys()).map(async key => fs.writeFile(path.join(versionPath, key + ".json"), JSON.stringify(Object.assign({ version: key }, versions.get(key)), null, 2))));
|
||||||
await fs.writeFile(allPath, JSON.stringify(vers, null, 2));
|
|
||||||
await Promise.all(Array.from(versions.keys()).map(async ver => fs.writeFile(path.join(versionPath, `${ver}.json`), JSON.stringify({ version: ver, ...(versions.get(ver)) }, null, 2))));
|
|
17
versions/1.20.10.23.json
Normal file
17
versions/1.20.10.23.json
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"version": "1.20.10.23",
|
||||||
|
"date": "2023-06-12T23:31:06.000Z",
|
||||||
|
"release": "preview",
|
||||||
|
"url": {
|
||||||
|
"linux": {
|
||||||
|
"x64": {
|
||||||
|
"zip": "/tmp/linux_x64_bedrock-server-1.20.10.23.zip"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"win32": {
|
||||||
|
"x64": {
|
||||||
|
"zip": "/tmp/win32_x64_bedrock-server-1.20.10.23.zip"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
4095
versions/all.json
4095
versions/all.json
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user