Skip to content

Commit

Permalink
Merge pull request #388 from CameronRP/update-prod
Browse files Browse the repository at this point in the history
Update prod
  • Loading branch information
CameronRP authored Sep 11, 2024
2 parents 05c1294 + 74ef86d commit e17828c
Show file tree
Hide file tree
Showing 14 changed files with 133 additions and 105 deletions.
156 changes: 67 additions & 89 deletions .github/workflows/aggregate-versions.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,13 @@ const repo = args[2];

const getFilesWithExtension = (path, ext) => {
const items = fs.readdirSync(path)
.filter(item => (
!item.startsWith(".") &&
!item.startsWith("_") &&
(item.endsWith(`.${ext}`) || fs.lstatSync(`${path}/${item}`).isDirectory())
))
.map(item => ({ name: item, isDir: fs.lstatSync(`${path}/${item}`).isDirectory() }));
.filter(item => (
!item.startsWith(".") &&
!item.startsWith("_") &&
(item.endsWith(`.${ext}`) || fs.lstatSync(`${path}/${item}`).isDirectory())
))
.map(item => ({ name: item, isDir: fs.lstatSync(`${path}/${item}`).isDirectory() }));

let files = [];
for (const item of items) {
if (item.isDir) {
Expand All @@ -38,103 +39,80 @@ const findKeyInObject = (obj, key) => {
}
return false;
}
const formatDate = date => {
const dateString = date.toLocaleString("en-NZ", {timeZone: "Pacific/Auckland"});
// Node on github actions only has US localization, so we need to swap day and month:
const firstPart = dateString.split(",")[0];
const pieces = firstPart.split("/");
return `${pieces[1]}/${pieces[0]}/${pieces[2]},${dateString.split(',')[1]}`;
}

const branches = ["prod", "test", "dev"];
const models = ["pi", "tc2"];
const versionsAreEqual = (prev, next) => {
for (const branch of branches) {
if (!prev[branch] || !next[branch]) {
return false;
}
for (const model of models) {
for (const softwarePackage of Object.keys(prev[branch][model])) {
if (!next[branch][model][softwarePackage]) {
return false;
}
if (next[branch][model][softwarePackage] !== prev[branch][model][softwarePackage]) {
return false;
}
}
for (const softwarePackage of Object.keys(next[branch][model])) {
if (!prev[branch][model][softwarePackage]) {
return false;
}
if (next[branch][model][softwarePackage] !== prev[branch][model][softwarePackage]) {
return false;
}
}
}
}
return true;
};
(async function () {
const versionData = {};
const now = new Date();
const separator = "____\n";
let versionOutput = "";

console.log(process.cwd());
process.chdir("../../../");
// For each branch:
const branches = ["prod", "test", "dev"];
const releaseNotesLinks = {
prod: "https://docs.cacophony.org.nz/home/release-notes-2020",
dev: "https://docs.cacophony.org.nz/home/release-notes-2"
};
console.log(process.cwd());

for (const branch of branches) {
process.chdir(`./${branch}`);
const slsFiles = getFilesWithExtension(".", "sls");
// For each branch:
versionData[branch] = {};
for (const path of slsFiles) {
const data = fs.readFileSync(path, "utf8");
try {
const yamlData = yaml.parse(data);
const versionInfo = findKeyInObject(yamlData, "cacophony.pkg_installed_from_github");
const name = versionInfo.find(item => item.hasOwnProperty("name")).name;
const version = versionInfo.find(item => item.hasOwnProperty("version")).version;
versionData[branch][name] = version;
} catch (e) {
process.chdir(`./${branch}`);
for (const model of models) {
// For each camera model:
process.chdir(`./${model}`);
const slsFiles = getFilesWithExtension(".", "sls");
versionData[branch][model] = {};
for (const path of slsFiles) {
const data = fs.readFileSync(path, "utf8");
try {
const yamlData = yaml.parse(data);
const versionInfo = findKeyInObject(yamlData, "cacophony.pkg_installed_from_github");
const name = versionInfo.find(item => item.hasOwnProperty("name")).name;
const version = versionInfo.find(item => item.hasOwnProperty("version")).version;
versionData[branch][model][name] = version;
} catch (e) {
}
}
process.chdir("../");
}
process.chdir("../");
}

// Output the text to the README.md file, if the version info has changed since last time.
for (const branch of branches) {
versionOutput += `#### Branch \`${branch}\`\n`;
for (const [key, val] of Object.entries(versionData[branch])) {
versionOutput += ` * ${key}: ${val}\n`;
}
if (releaseNotesLinks[branch]) {
versionOutput += `\n[Release notes](${releaseNotesLinks[branch]})\n`;
}
}

// Just write out on the dev branch.
const branch = "dev";
let prevVersionOutput = "";
process.chdir(`./${branch}`);
const readme = fs.readFileSync("README.md", "utf8");
const versionInfoStart = readme.indexOf("\n\n#### Version information");
let output;
if (versionInfoStart !== -1) {
output = readme.substring(0, versionInfoStart);
prevVersionOutput = readme.substring(readme.indexOf(separator) + separator.length);
} else {
output = readme;
process.chdir("./salt-version-info");
let prevVersionData;
try {
const prevVersionInfo = fs.readFileSync("./salt-version-info.json", "utf8");
prevVersionData = JSON.parse(prevVersionInfo);
} catch (e) {
console.log(e);
}
output += "\n\n#### Version information ";
output += `(_Updated ${formatDate(now)}_):\n`;
output += separator;
output += versionOutput;
if (versionOutput !== prevVersionOutput) {
fs.writeFileSync("README.md", output);
if ((prevVersionData && !versionsAreEqual(prevVersionData, versionData)) || !prevVersionData) {
versionData.updated = new Date().toISOString();
console.log("version info updated", JSON.stringify(versionData, null, '\t'));
if (repo === "TheCacophonyProject/saltops") {
console.log("Committing changes for branch", branch);
{
const {stderr, stdout} = await exec("git config user.name cacophony-bot");
console.log("1:", stderr, stdout);
}
{
const {stderr, stdout} = await exec("git config user.email bot@cacophony.org.nz");
console.log("2:", stderr, stdout);
}
{
const {stderr, stdout} = await exec("git add .");
console.log("3:", stderr, stdout);
}
{
const {stderr, stdout} = await exec("git commit -m \"updated version information\"");
console.log("4:", stderr, stdout);
}
{
console.log("Pushing");
const {stderr, stdout} = await exec("git push --force");
console.log("5:", stderr, stdout);
}
fs.writeFileSync("./salt-version-info.json", JSON.stringify(versionData, null, '\t'));
}
} else {
// Version info is unchanged.
console.log("version information unchanged");
}
process.chdir("../");

}());
51 changes: 46 additions & 5 deletions .github/workflows/aggregate-versions.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,63 @@
# to each branch if any of the version information in any branch has changed.

name: aggregate-version-info
env:
GITHUB_TOKEN: ${{ secrets.CACOPHONY_BOT_TOKEN }}
on: [push, workflow_dispatch]
env:
HAS_CHANGES: ${{ false }}
jobs:
aggregate-version-info:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Checkout
uses: actions/checkout@v4
with:
path: dev
ref: dev
- name: Checkout
uses: actions/checkout@v4
with:
path: prod
ref: prod
- name: Checkout
uses: actions/checkout@v4
with:
path: test
ref: test
- name: Checkout
uses: actions/checkout@v4
with:
repository: TheCacophonyProject/salt-version-info
path: salt-version-info
token: ${{ secrets.WRITE_VERSION_INFO_TOKEN }}
persist-credentials: true
- uses: actions/setup-node@v2.1.2
with:
node-version: 12.x
- shell: bash
node-version: 20.x
- name: Run version-check script
shell: bash
run: |
cd dev/.github/workflows
npm i
npm run aggregate-versions ${{ github.repository }}
- name: Check for new files
id: newFiles
shell: bash
working-directory: salt-version-info
run: |
git add -A
git status --porcelain | wc -l
if [[ $(git status --porcelain | wc -l) -gt 0 ]]; then
echo "HAS_CHANGES=true" >> "$GITHUB_ENV"
else
echo "HAS_CHANGES=false" >> "$GITHUB_ENV"
fi
- name: Push new files
if: env.HAS_CHANGES == 'true'
shell: bash
working-directory: salt-version-info
run: |
git config --global user.name "cacophony-bot"
git config --global user.email "bot@cacophony.org.nz"
git commit -m "updated version information"
git push
2 changes: 2 additions & 0 deletions check-for-updates.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
#!/bin/python

import requests
import os
import yaml
Expand Down
9 changes: 8 additions & 1 deletion tc2/config/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
cacophony-config-pkg:
cacophony.pkg_installed_from_github:
- name: go-config
- version: "1.18.0"
- version: "1.20.4"
- pkg_name: cacophony-config
- branch: master

cacophony-config-sync-service:
service.running:
- name: cacophony-config-sync
- enable: True
- watch:
- cacophony-config-pkg
2 changes: 1 addition & 1 deletion tc2/device-register/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
device-register-pkg:
cacophony.pkg_installed_from_github:
- name: device-register
- version: "1.5.2"
- version: "1.5.4"
- branch: master

/etc/systemd/system/device-register.service.d:
Expand Down
2 changes: 1 addition & 1 deletion tc2/event-reporter/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
event-reporter-pkg:
cacophony.pkg_installed_from_github:
- name: event-reporter
- version: "3.7.0"
- version: "3.8.1"
- branch: "master"

event-reporter-service:
Expand Down
2 changes: 1 addition & 1 deletion tc2/management-interface/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
management-interface-pkg:
cacophony.pkg_installed_from_github:
- name: management-interface
- version: "1.28.0-tc2"
- version: "1.31.1-tc2"
- branch: tc2

managementd-service:
Expand Down
2 changes: 1 addition & 1 deletion tc2/modemd/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ stop_modem_manager:
modemd-pkg:
cacophony.pkg_installed_from_github:
- name: modemd
- version: "1.9.1-tc2"
- version: "1.10.1-tc2"
- branch: "tc2"

modemd:
Expand Down
2 changes: 1 addition & 1 deletion tc2/rpi-net-manager/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
rpi-net-manager-pkg:
cacophony.pkg_installed_from_github:
- name: rpi-net-manager
- version: "0.5.3"
- version: "0.5.4"
- architecture: "arm64"

rpi-net-manager-service:
Expand Down
2 changes: 1 addition & 1 deletion tc2/salt-updater/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
salt-updater-pkg:
cacophony.pkg_installed_from_github:
- name: salt-updater
- version: "0.8.2"
- version: "0.8.5"

salt-updater:
service.running:
Expand Down
2 changes: 1 addition & 1 deletion tc2/tc2-agent/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tc2-agent-pkg:
cacophony.pkg_installed_from_github:
- name: tc2-agent
- version: "0.2.8"
- version: "0.3.14"
- architecture: "arm64"
- branch: "main"

Expand Down
2 changes: 1 addition & 1 deletion tc2/tc2-hat-controller/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
tc2-hat-controller-pkg:
cacophony.pkg_installed_from_github:
- name: tc2-hat-controller
- version: "0.10.1"
- version: "0.11.1"
- architecture: "arm64"
- branch: "main"

Expand Down
2 changes: 1 addition & 1 deletion tc2/thermal-recorder-py/init.sls
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ classifier-env:
classifier-pipeline-pip:
cacophony.pkg_installed_from_pypi:
- name: classifier-pipeline
- version: "0.0.15"
- version: "0.0.16"
- venv: /home/pi/.venv/classifier/bin/

thermal-recorder-py-service:
Expand Down
2 changes: 1 addition & 1 deletion tc2/thermal-uploader/init.sls
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
thermal-uploader-pkg:
cacophony.pkg_installed_from_github:
- name: thermal-uploader
- version: "2.6.1"
- version: "2.6.3"
- branch: master

thermal-uploader-service:
Expand Down

0 comments on commit e17828c

Please sign in to comment.