Skip to content

Commit

Permalink
New versioning scheme
Browse files Browse the repository at this point in the history
  • Loading branch information
MineGame159 committed Jan 8, 2025
1 parent 401d3b0 commit b279889
Show file tree
Hide file tree
Showing 17 changed files with 123 additions and 262 deletions.
25 changes: 25 additions & 0 deletions .github/builds/get_number.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

const { getMcVersion } = require("./mc_version")

const mcVersion = await getMcVersion();

fetch("https://meteorclient.com/api/stats")
.then(async res => {
let stats = await res.json()
let build = 0

if (mcVersion in stats.builds) {
build = parseInt(stats.builds[mcVersion])
}

console.log("number=" + (build + 1))
})
.catch(err => {
console.log("Failed to fetch stats:")
console.log(err)
process.exit(1)
})
63 changes: 20 additions & 43 deletions .github/devbuilds/index.js → .github/builds/index.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
const fs = require("fs");
const path = require("path");
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

const branch = process.argv[2];
const compareUrl = process.argv[3];
const success = process.argv[4] === "true";
const { getMcVersion } = require("./mc_version")

function send(version, number) {
const buildNumber = process.argv[2];
const branch = process.argv[3];
const compareUrl = process.argv[4];
const success = process.argv[5] === "true";

const mcVersion = await getMcVersion();

function sendDiscordWebhook() {
fetch(compareUrl)
.then(res => res.json())
.then(res => {
Expand All @@ -24,16 +31,12 @@ function send(version, number) {
}
if (hasChanges) description += changes;

if (success) {
description += "\n\n**Download:** [meteor-client-" + version + "-" + number + "](https://meteorclient.com/download?devBuild=" + number + ")";
}

const webhook = {
username: "Dev Builds",
username: "Builds",
avatar_url: "https://meteorclient.com/icon.png",
embeds: [
{
title: "meteor client v" + version + " build #" + number,
title: "Meteor Client " + mcVersion + " build #" + buildNumber,
description: description,
url: "https://meteorclient.com",
color: success ? 2672680 : 13117480
Expand All @@ -52,38 +55,12 @@ function send(version, number) {
}

if (success) {
let jar = "";
fs.readdirSync("../../build/libs").forEach(file => {
if (!file.endsWith("-all.jar") && !file.endsWith("-sources.jar")) jar = "../../build/libs/" + file;
});

let form = new FormData();
form.set(
"file",
new Blob([fs.readFileSync(jar)], { type: "application/java-archive" }),
path.basename(jar)
);

fetch("https://meteorclient.com/api/uploadDevBuild", {
fetch("https://meteorclient.com/api/recheckMaven", {
method: "POST",
headers: {
"Authorization": process.env.SERVER_TOKEN
},
body: form
})
.then(async res => {
let data = await res.json();

if (res.ok) {
send(data.version, data.number);
}
else {
console.log("Failed to upload dev build: " + data.error);
}
});
}
else {
fetch("https://meteorclient.com/api/stats")
.then(res => res.json())
.then(res => send(res.dev_build_version, parseInt(res.devBuild) + 1));
}
});
}

sendDiscordWebhook()
30 changes: 30 additions & 0 deletions .github/builds/mc_version.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* This file is part of the Meteor Client distribution (https://github.com/MeteorDevelopment/meteor-client).
* Copyright (c) Meteor Development.
*/

const fs = require("fs")
const readline = require("readline")

export async function getMcVersion() {
let lines = readline.createInterface({
input: fs.createReadStream("../../gradle.properties"),
crlfDelay: Infinity
})

let mcVersion = ""

for await (const line of lines) {
if (line.startsWith("minecraft_version")) {
mcVersion = line.substring(0, line.indexOf("="))
break
}
}

if (mcVersion === "") {
console.log("Failed to read minecraft_version")
process.exit(1)
}

return mcVersion
}
13 changes: 13 additions & 0 deletions .github/builds/package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,5 @@
"scripts": {
"get_number": "node get_number.js",
"start": "node index.js"
},
"dependencies": {}
}
}
3 changes: 0 additions & 3 deletions .github/devbuilds/get_number.js

This file was deleted.

158 changes: 0 additions & 158 deletions .github/devbuilds/package-lock.json

This file was deleted.

24 changes: 12 additions & 12 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,38 +29,38 @@ jobs:
java-version: '21'

- name: Set up Node JS
uses: actions/setup-node@v3
uses: actions/setup-node@v4
with:
node-version: latest
node-version: 22

- name: Get current dev build number
id: dev-build
- name: Get current build number
id: build-number
run: |
cd .github/devbuilds
cd .github/builds
npm install
node get_number.js >> $GITHUB_OUTPUT
- name: Build
run: ./gradlew build -Pcommit=${{ github.sha }} -Pdevbuild=${{ steps.dev-build.outputs.number }}
run: ./gradlew build -Pcommit=${{ github.sha }} -Pbuild_number=${{ steps.build-number.outputs.number }}

- name: Webhook Failure
if: ${{ failure() }}
run: |
cd .github/devbuilds
npm start ${{ github.ref_name }} https://api.github.com/repos/MeteorDevelopment/meteor-client/compare/${{ github.event.before }}...${{ github.event.after }} false
cd .github/builds
npm start ${{ steps.build-number.outputs.number }} ${{ github.ref_name }} https://api.github.com/repos/MeteorDevelopment/meteor-client/compare/${{ github.event.before }}...${{ github.event.after }} false
env:
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}

- name: Publish
run: ./gradlew publish -Pcommit=${{ github.sha }} -Pdevbuild=${{ steps.dev-build.outputs.number }}
run: ./gradlew publish -Pcommit=${{ github.sha }} -Pbuild_number=${{ steps.build-number.outputs.number }}
env:
MAVEN_METEOR_ALIAS: ${{ secrets.MAVEN_METEOR_ALIAS }}
MAVEN_METEOR_TOKEN: ${{ secrets.MAVEN_METEOR_TOKEN }}

- name: Upload file & Discord webhook
- name: Discord webhook
run: |
cd .github/devbuilds
npm start ${{ github.ref_name }} https://api.github.com/repos/MeteorDevelopment/meteor-client/compare/${{ github.event.before }}...${{ github.event.after }} true
cd .github/builds
npm start ${{ steps.build-number.outputs.number }} ${{ github.ref_name }} https://api.github.com/repos/MeteorDevelopment/meteor-client/compare/${{ github.event.before }}...${{ github.event.after }} true
env:
SERVER_TOKEN: ${{ secrets.SERVER_TOKEN }}
DISCORD_WEBHOOK: ${{ secrets.DISCORD_WEBHOOK }}
Loading

0 comments on commit b279889

Please sign in to comment.