mirror of
https://github.com/the-draupnir-project/Draupnir.git
synced 2026-03-30 11:00:13 +00:00
Include version information in !draupnir status.
This commit is contained in:
2
.github/workflows/docker-hub-develop.yml
vendored
2
.github/workflows/docker-hub-develop.yml
vendored
@@ -19,6 +19,8 @@ jobs:
|
||||
steps:
|
||||
- name: Check out
|
||||
uses: actions/checkout@v2
|
||||
- name: Prepare version file
|
||||
run: git describe > src/version.txt
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
|
||||
2
.github/workflows/docker-hub-release.yml
vendored
2
.github/workflows/docker-hub-release.yml
vendored
@@ -18,6 +18,8 @@ jobs:
|
||||
uses: actions/checkout@v2
|
||||
- name: Get release tag
|
||||
run: echo "RELEASE_VERSION=${GITHUB_REF#refs/*/}" >> $GITHUB_ENV
|
||||
- name: Prepare version file
|
||||
run: git describe > src/version.txt
|
||||
- name: Log in to Docker Hub
|
||||
uses: docker/login-action@v1
|
||||
with:
|
||||
|
||||
2
.gitignore
vendored
2
.gitignore
vendored
@@ -8,6 +8,8 @@ venv/
|
||||
|
||||
/db
|
||||
|
||||
# version file generated from yarn build
|
||||
src/version.txt
|
||||
# Logs
|
||||
logs
|
||||
*.log
|
||||
|
||||
@@ -7,6 +7,7 @@ RUN cd /tmp/src \
|
||||
&& mv lib/ /mjolnir/ \
|
||||
&& mv node_modules / \
|
||||
&& mv mjolnir-entrypoint.sh / \
|
||||
&& mv package.json / \
|
||||
&& cd / \
|
||||
&& rm -rf /tmp/*
|
||||
|
||||
|
||||
10
package.json
10
package.json
@@ -1,14 +1,14 @@
|
||||
{
|
||||
"name": "mjolnir",
|
||||
"name": "draupnir",
|
||||
"version": "1.80.0-beta.0",
|
||||
"description": "A moderation tool for Matrix",
|
||||
"main": "lib/index.js",
|
||||
"repository": "git@github.com:matrix-org/mjolnir.git",
|
||||
"author": "The Matrix.org Foundation C.I.C.",
|
||||
"license": "Apache-2.0",
|
||||
"repository": "git@github.com:Gnuxie/Draupnir.git",
|
||||
"author": "Gnuxie",
|
||||
"license": "SEE LICENSE IN LICENSE",
|
||||
"private": true,
|
||||
"scripts": {
|
||||
"build": "tsc",
|
||||
"build": "tsc && (git describe > src/version.txt || true)",
|
||||
"postbuild": "rm -rf lib/test/ && cp -r lib/src/* lib/ && rm -rf lib/src/",
|
||||
"lint": "tslint --project ./tsconfig.json -t stylish",
|
||||
"start:dev": "yarn build && node --async-stack-traces lib/index.js",
|
||||
|
||||
@@ -30,6 +30,7 @@ import { RichReply } from "matrix-bot-sdk";
|
||||
import { htmlEscape, parseDuration } from "../utils";
|
||||
import { HumanizeDurationLanguage, HumanizeDuration } from "humanize-duration-ts";
|
||||
import PolicyList from "../models/PolicyList";
|
||||
import { PACKAGE_JSON, SOFTWARE_VERSION } from "../config";
|
||||
|
||||
const HUMANIZE_LAG_SERVICE: HumanizeDurationLanguage = new HumanizeDurationLanguage();
|
||||
const HUMANIZER: HumanizeDuration = new HumanizeDuration(HUMANIZE_LAG_SERVICE);
|
||||
@@ -102,6 +103,12 @@ async function showMjolnirStatus(roomId: string, event: any, mjolnir: Mjolnir) {
|
||||
const subscribedAndProtectedLists = mjolnir.policyListManager.lists.filter(list => mjolnir.explicitlyProtectedRooms.includes(list.roomId));
|
||||
renderPolicyLists("Subscribed and protected policy lists", subscribedAndProtectedLists);
|
||||
|
||||
html += `<b>Version:</b> ${SOFTWARE_VERSION}<br/>`;
|
||||
text += `Version: ${SOFTWARE_VERSION}\n`;
|
||||
|
||||
html += `<b>Repository:</b> <code>${PACKAGE_JSON['repository'] ?? 'Unknown'}</code>`;
|
||||
text += `Repository: ${PACKAGE_JSON['repository'] ?? 'Unknown'}`;
|
||||
|
||||
const reply = RichReply.createFor(roomId, event, text, html);
|
||||
reply["msgtype"] = "m.notice";
|
||||
return mjolnir.client.sendMessage(roomId, reply);
|
||||
|
||||
@@ -29,6 +29,7 @@ import * as fs from "fs";
|
||||
import { load } from "js-yaml";
|
||||
import { MatrixClient, LogService } from "matrix-bot-sdk";
|
||||
import Config from "config";
|
||||
import path from "path";
|
||||
|
||||
/**
|
||||
* The configuration, as read from production.yaml
|
||||
@@ -283,3 +284,21 @@ export function getProvisionedMjolnirConfig(managementRoomId: string): IConfig {
|
||||
config.protectedRooms = [];
|
||||
return config;
|
||||
}
|
||||
|
||||
export const SOFTWARE_VERSION = (() => {
|
||||
try {
|
||||
return fs.readFileSync(path.join(__dirname, 'version.txt'), 'utf-8')
|
||||
} catch (e) {
|
||||
LogService.error("config", "Could not read Draupnir version", e);
|
||||
return "A version was either not provided when building Draupnir or could not be read."
|
||||
}
|
||||
})();
|
||||
|
||||
export const PACKAGE_JSON = (() => {
|
||||
try {
|
||||
return JSON.parse(fs.readFileSync(path.join(__dirname, '../package.json'), 'utf-8'));
|
||||
} catch (e) {
|
||||
LogService.error("config", "Could not read Draupnir package.json", e);
|
||||
return {};
|
||||
}
|
||||
})();
|
||||
|
||||
Reference in New Issue
Block a user