2023-07-10 12:06:05 +02:00
|
|
|
name: Update release topics
|
|
|
|
on:
|
|
|
|
workflow_dispatch:
|
|
|
|
inputs:
|
|
|
|
expected_status:
|
|
|
|
description: What type of release is the next expected release
|
|
|
|
required: true
|
|
|
|
default: RC
|
|
|
|
type: choice
|
|
|
|
options:
|
|
|
|
- RC
|
|
|
|
- Release
|
|
|
|
expected_date:
|
|
|
|
description: Expected release date e.g. July 11th
|
|
|
|
required: true
|
|
|
|
type: string
|
|
|
|
concurrency: ${{ github.workflow }}
|
2024-11-20 16:44:02 +01:00
|
|
|
permissions: {} # No permissions required
|
2023-07-10 12:06:05 +02:00
|
|
|
jobs:
|
|
|
|
bot:
|
|
|
|
name: Release topic update
|
2024-10-17 12:10:32 +02:00
|
|
|
runs-on: ubuntu-24.04
|
2023-07-10 12:06:05 +02:00
|
|
|
environment: Matrix
|
|
|
|
steps:
|
2023-11-15 23:29:06 +01:00
|
|
|
- uses: actions/github-script@v7
|
2023-07-10 12:06:05 +02:00
|
|
|
env:
|
|
|
|
HS_URL: ${{ secrets.BETABOT_HS_URL }}
|
|
|
|
LOBBY_ROOM_ID: ${{ secrets.ROOM_ID }}
|
|
|
|
PUBLIC_ROOM_ID: "!YTvKGNlinIzlkMTVRl:matrix.org"
|
|
|
|
ANNOUNCEMENT_ROOM_ID: "!bijaLdadorKgNGtHdA:matrix.org"
|
|
|
|
TOKEN: ${{ secrets.BETABOT_ACCESS_TOKEN }}
|
2023-07-13 13:21:41 +02:00
|
|
|
RELEASE_STATUS: "Release status: ${{ inputs.expected_status }} expected ${{ inputs.expected_date }}"
|
2023-07-10 12:06:05 +02:00
|
|
|
with:
|
|
|
|
script: |
|
2023-07-13 13:21:41 +02:00
|
|
|
const { HS_URL, TOKEN, RELEASE_STATUS, LOBBY_ROOM_ID, PUBLIC_ROOM_ID, ANNOUNCEMENT_ROOM_ID } = process.env;
|
|
|
|
|
|
|
|
const repo = context.repo;
|
2023-07-13 13:23:30 +02:00
|
|
|
const { data } = await github.rest.repos.getLatestRelease({
|
2023-07-13 13:21:41 +02:00
|
|
|
owner: repo.owner,
|
|
|
|
repo: repo.repo,
|
|
|
|
});
|
2023-07-13 13:26:02 +02:00
|
|
|
console.log("Found latest version: " + data.tag_name);
|
2023-07-13 13:21:41 +02:00
|
|
|
|
2023-07-13 13:23:30 +02:00
|
|
|
const releaseTopic = `Stable: ${data.tag_name} | ${RELEASE_STATUS}`;
|
2023-07-13 13:26:02 +02:00
|
|
|
console.log("Release topic: " + releaseTopic);
|
2023-07-10 12:06:05 +02:00
|
|
|
|
2023-07-13 13:31:39 +02:00
|
|
|
const regex = /Stable: v(.+) \| Release status: (\w+) expected (\w+ \d+\w\w)/gm;
|
2023-07-10 12:06:05 +02:00
|
|
|
|
|
|
|
async function updateReleaseInTopic(roomId) {
|
|
|
|
const apiUrl = `${HS_URL}/_matrix/client/v3/rooms/${roomId}/state/m.room.topic/`;
|
|
|
|
const headers = {
|
|
|
|
"Content-Type": "application/json",
|
|
|
|
"Authorization": `Bearer ${TOKEN}`,
|
|
|
|
};
|
2023-07-10 12:49:38 +02:00
|
|
|
await fetch(`${HS_URL}/_matrix/client/v3/rooms/${roomId}/join`, {
|
|
|
|
method: "POST",
|
|
|
|
headers,
|
|
|
|
body: "{}",
|
|
|
|
});
|
2024-10-17 12:10:32 +02:00
|
|
|
|
2023-07-10 12:16:18 +02:00
|
|
|
let res = await fetch(apiUrl, {
|
2023-07-10 12:06:05 +02:00
|
|
|
method: "GET",
|
|
|
|
headers,
|
|
|
|
});
|
|
|
|
|
2023-10-25 15:00:06 +02:00
|
|
|
if (!res.ok) {
|
|
|
|
console.log(roomId, "failed to fetch", await res.text());
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2023-07-10 12:06:05 +02:00
|
|
|
const data = await res.json();
|
2023-10-25 15:09:28 +02:00
|
|
|
console.log(roomId, "got event", data);
|
2024-10-17 12:10:32 +02:00
|
|
|
|
2023-07-13 13:21:41 +02:00
|
|
|
const topic = data.topic.replace(regex, releaseTopic);
|
2023-07-10 12:06:05 +02:00
|
|
|
if (topic === data.topic) {
|
|
|
|
console.log(roomId, "nothing to do");
|
2023-07-10 12:12:17 +02:00
|
|
|
return;
|
2023-07-10 12:06:05 +02:00
|
|
|
}
|
2023-07-10 12:27:41 +02:00
|
|
|
if (data["org.matrix.msc3765.topic"]) {
|
|
|
|
data["org.matrix.msc3765.topic"].forEach(d => {
|
2023-07-13 13:21:41 +02:00
|
|
|
d.body = d.body.replace(regex, releaseTopic);
|
2023-07-10 12:27:41 +02:00
|
|
|
});
|
|
|
|
}
|
2023-07-10 12:06:05 +02:00
|
|
|
|
2023-07-10 12:16:18 +02:00
|
|
|
res = await fetch(apiUrl, {
|
2023-07-10 12:06:05 +02:00
|
|
|
method: "PUT",
|
2023-07-10 12:18:28 +02:00
|
|
|
body: JSON.stringify({
|
2023-07-10 12:06:05 +02:00
|
|
|
...data,
|
|
|
|
topic,
|
2023-07-10 12:18:28 +02:00
|
|
|
}),
|
2023-07-10 12:06:05 +02:00
|
|
|
headers,
|
|
|
|
});
|
2024-10-17 12:10:32 +02:00
|
|
|
|
2023-07-10 12:14:03 +02:00
|
|
|
if (res.ok) {
|
|
|
|
console.log(roomId, "topic updated:", topic);
|
|
|
|
} else {
|
|
|
|
console.log(roomId, await res.text());
|
|
|
|
}
|
2023-07-10 12:06:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
await updateReleaseInTopic(LOBBY_ROOM_ID);
|
2023-07-10 12:36:28 +02:00
|
|
|
await updateReleaseInTopic(PUBLIC_ROOM_ID);
|
|
|
|
await updateReleaseInTopic(ANNOUNCEMENT_ROOM_ID);
|