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:
|
||||
- main
|
||||
|
||||
permissions:
|
||||
contents: read
|
||||
pages: write
|
||||
id-token: write
|
||||
permissions: write-all
|
||||
|
||||
jobs:
|
||||
findVersion:
|
||||
runs-on: ubuntu-latest
|
||||
name: "server ${{ matrix.platform }}"
|
||||
environment:
|
||||
name: github-pages
|
||||
url: ${{ steps.deployment.outputs.page_url }}
|
||||
|
12
.github/workflows/find.yaml
vendored
12
.github/workflows/find.yaml
vendored
@ -10,13 +10,14 @@ on:
|
||||
jobs:
|
||||
findVersion:
|
||||
runs-on: ubuntu-latest
|
||||
env:
|
||||
UPLOAD: "false"
|
||||
VERSION: "0.1.0"
|
||||
permissions:
|
||||
id-token: write
|
||||
pull-requests: write
|
||||
issues: write
|
||||
contents: write
|
||||
env:
|
||||
UPLOAD: "false"
|
||||
VERSION: "0.1.0"
|
||||
steps:
|
||||
- uses: actions/checkout@v3
|
||||
name: Checkout code
|
||||
@ -39,11 +40,11 @@ jobs:
|
||||
run: npm run updateVesion
|
||||
env:
|
||||
GITHUB_SECRET: ${{ secrets.GITHUB_TOKEN }}
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
|
||||
# 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
|
||||
continue-on-error: true
|
||||
if: env.UPLOAD == 'true'
|
||||
with:
|
||||
commit-message: New Minecraft bedrock server release (${{ env.VERSION }})
|
||||
@ -53,3 +54,4 @@ jobs:
|
||||
branch: version_update_${{ env.VERSION }}
|
||||
title: new release version v${{ env.VERSION }}
|
||||
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": {
|
||||
"@types/adm-zip": "^0.5.0",
|
||||
"@types/node": "^20.2.5",
|
||||
"@types/node": "^20.3.1",
|
||||
"@types/tar": "^6.1.5",
|
||||
"ts-node": "^10.9.1",
|
||||
"typescript": "^4.9.5"
|
||||
"typescript": "^5.1.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"@actions/github": "^5.1.1",
|
||||
"@sirherobrine23/http": "^3.6.11",
|
||||
"@sirherobrine23/http": "^3.6.12",
|
||||
"adm-zip": "^0.5.10",
|
||||
"compare-versions": "^6.0.0-rc.1",
|
||||
"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 { compareVersions } from "compare-versions";
|
||||
import { createWriteStream } from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import { tmpdir } from "node:os";
|
||||
import path from "node:path";
|
||||
import streamConsumer from "node:stream/promises";
|
||||
import tar from "tar";
|
||||
|
||||
export type bedrockSchema = {
|
||||
version: string,
|
||||
@ -63,28 +61,21 @@ export async function find() {
|
||||
return mount;
|
||||
}, {});
|
||||
const data: bedrockSchema[] = [];
|
||||
|
||||
await Promise.all(Object.keys(objURLs).map(async version => {
|
||||
let release: any;
|
||||
const versionData = objURLs[version];
|
||||
await Promise.all(keys(versionData).map(platform => keys(versionData[platform]).map(async arch => {
|
||||
const fileUrl = new URL(versionData[platform][arch].zip);
|
||||
const tmpFile = versionData[platform][arch].zip = path.join(tmpdir(), `${platform}_${arch}_` + path.basename(fileUrl.pathname));
|
||||
const folderPath = tmpFile.slice(0, -(path.extname(tmpFile).length));
|
||||
const tgzPath = versionData[platform][arch].tgz = folderPath + ".tgz";
|
||||
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 });
|
||||
const filePath = versionData[platform][arch].zip = path.join(tmpdir(), `${platform}_${arch}_` + path.basename(fileUrl.pathname));
|
||||
console.log("Downloading %O on %O path", fileUrl.toString(), filePath);
|
||||
await streamConsumer.pipeline(await http.streamRequest(fileUrl), createWriteStream(filePath));
|
||||
release = ((/preview/).test(fileUrl.toString())) ? "preview" : "oficial";
|
||||
})).flat(2));
|
||||
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 bedrockInfo = zip.getEntries().find(file => file.name.startsWith("bedrock_server"));
|
||||
data.push({
|
||||
if (bedrockInfo) data.push({
|
||||
version: version,
|
||||
date: bedrockInfo.header.time,
|
||||
release,
|
||||
|
97
src/index.ts
97
src/index.ts
@ -1,57 +1,80 @@
|
||||
#!/usr/bin/env node
|
||||
import { Github } from "@sirherobrine23/http";
|
||||
import AdmZip from "adm-zip";
|
||||
import { compareVersions } from "compare-versions";
|
||||
import { createReadStream } from "node:fs";
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { finished } from "node:stream/promises";
|
||||
import { pipeline } from "node:stream/promises";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import tar from "tar";
|
||||
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 versionPath = path.resolve(__dirname, "../versions");
|
||||
const allPath = path.join(versionPath, "all.json");
|
||||
let __versions: bedrockSchema[] = JSON.parse(await fs.readFile(allPath, "utf8"));
|
||||
__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 gh = await Github.repositoryManeger("Sirherobrine23", "BedrockFetch", { token: process.env.GITHUB_TOKEN });
|
||||
|
||||
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");
|
||||
const newVersions = await find();
|
||||
let upload = false;
|
||||
for (const rel of newVersions) {
|
||||
if (versions.has(rel.version)) {
|
||||
console.log("%s are added in database", rel.version);
|
||||
const remoteURLs = await find();
|
||||
|
||||
for (const remoteURL of remoteURLs) {
|
||||
if (versions.has(remoteURL.version)) {
|
||||
console.log("Skiping %s so added to Releases and Versions!");
|
||||
continue;
|
||||
}
|
||||
const release = await gh.release.manegerRelease(rel.version, {
|
||||
type: rel.release === "preview" ? "preRelease" : undefined,
|
||||
releaseName: rel.version,
|
||||
releaseBody: ([
|
||||
`# ${rel.release} ${rel.version} ${rel.date.toUTCString()}`,
|
||||
"",
|
||||
`Auto fetch Minecraft bedrock server and release to Public, By @Sirherobrine23 and Github actions`
|
||||
]).join("\n"),
|
||||
|
||||
console.log("Creating %s release", remoteURL.version);
|
||||
const release = await gh.release.manegerRelease(remoteURL.version, {
|
||||
type: remoteURL.release === "preview" ? "preRelease" : undefined,
|
||||
releaseName: remoteURL.version,
|
||||
releaseBody: ([`# ${remoteURL.date.toUTCString()} ${remoteURL.version}`, "",]).join("\n"),
|
||||
});
|
||||
console.log("Add %s to versions", rel.version);
|
||||
if (!upload && process.env.GITHUB_ENV) {
|
||||
const githubEnv = path.resolve(process.env.GITHUB_ENV);
|
||||
upload = true;
|
||||
await fs.writeFile(githubEnv, `VERSION=${rel.version}\nUPLOAD=true`);
|
||||
}
|
||||
await Promise.all(keys(rel.url).map(platform => keys(rel.url[platform]).map(arch => keys(rel.url[platform][arch]).map(async file => {
|
||||
const basename = path.basename(rel.url[platform][arch][file]);
|
||||
const fileStats = await fs.lstat(rel.url[platform][arch][file]);
|
||||
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}`;
|
||||
}))).flat(3));
|
||||
versions.set(rel.version, {
|
||||
date: rel.date,
|
||||
release: rel.release,
|
||||
url: rel.url
|
||||
console.log("Created %s", remoteURL.version);
|
||||
|
||||
await Promise.all(keys(remoteURL.url).map(platform => keys(remoteURL.url[platform]).map(async (arch) => {
|
||||
let remoteName = `${platform}_${arch}.zip`;
|
||||
const filePath = remoteURL.url[platform][arch].zip;
|
||||
const zipStats = await fs.lstat(filePath);
|
||||
console.log("Uploading %s %O", remoteURL.version, remoteName);
|
||||
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));
|
||||
console.log("done uploaded %s %O", remoteURL.version, remoteName);
|
||||
|
||||
const folderPath = filePath.slice(0, -4);
|
||||
const tgzPath = folderPath + ".tgz";
|
||||
await new Promise<void>((done, reject) => (new AdmZip(filePath)).extractAllToAsync(folderPath, true, true, err => err ? reject(err) : done()));
|
||||
await tar.create({
|
||||
gzip: true,
|
||||
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 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))));
|
||||
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))));
|
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