schildi-web/.github/workflows/update-topics.yaml

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

96 lines
4.1 KiB
YAML
Raw Normal View History

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 }}
jobs:
bot:
name: Release topic update
runs-on: ubuntu-latest
environment: Matrix
steps:
- uses: actions/github-script@v6
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 07:21:41 -04:00
RELEASE_STATUS: "Release status: ${{ inputs.expected_status }} expected ${{ inputs.expected_date }}"
with:
script: |
2023-07-13 07:21:41 -04: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 07:23:30 -04:00
const { data } = await github.rest.repos.getLatestRelease({
2023-07-13 07:21:41 -04:00
owner: repo.owner,
repo: repo.repo,
});
2023-07-13 07:26:02 -04:00
console.log("Found latest version: " + data.tag_name);
2023-07-13 07:21:41 -04:00
2023-07-13 07:23:30 -04:00
const releaseTopic = `Stable: ${data.tag_name} | ${RELEASE_STATUS}`;
2023-07-13 07:26:02 -04:00
console.log("Release topic: " + releaseTopic);
2023-07-13 07:31:39 -04:00
const regex = /Stable: v(.+) \| Release status: (\w+) expected (\w+ \d+\w\w)/gm;
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 06:49:38 -04:00
await fetch(`${HS_URL}/_matrix/client/v3/rooms/${roomId}/join`, {
method: "POST",
headers,
body: "{}",
});
2023-07-10 06:16:18 -04:00
let res = await fetch(apiUrl, {
method: "GET",
headers,
});
const data = await res.json();
2023-07-13 07:21:41 -04:00
const topic = data.topic.replace(regex, releaseTopic);
if (topic === data.topic) {
console.log(roomId, "nothing to do");
2023-07-10 06:12:17 -04:00
return;
}
2023-07-10 06:27:41 -04:00
if (data["org.matrix.msc3765.topic"]) {
data["org.matrix.msc3765.topic"].forEach(d => {
2023-07-13 07:21:41 -04:00
d.body = d.body.replace(regex, releaseTopic);
2023-07-10 06:27:41 -04:00
});
}
2023-07-10 06:16:18 -04:00
res = await fetch(apiUrl, {
method: "PUT",
2023-07-10 06:18:28 -04:00
body: JSON.stringify({
...data,
topic,
2023-07-10 06:18:28 -04:00
}),
headers,
});
2023-07-10 06:14:03 -04:00
if (res.ok) {
console.log(roomId, "topic updated:", topic);
} else {
console.log(roomId, await res.text());
}
}
await updateReleaseInTopic(LOBBY_ROOM_ID);
2023-07-10 06:36:28 -04:00
await updateReleaseInTopic(PUBLIC_ROOM_ID);
await updateReleaseInTopic(ANNOUNCEMENT_ROOM_ID);