Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Playnite Web components as HASS addons #328

Merged
merged 16 commits into from
Jun 4, 2024
16 changes: 4 additions & 12 deletions .github/workflows/pull-request-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ jobs:
- name: Run all unit tests
run: yarn nx affected --base=origin/main --head=HEAD --target=test/unit --parallel --verbose --exclude='*,!tag:windows'

package:
name: Package extension
build_extension:
name: Build extension
runs-on: windows-latest
permissions:
packages: write
Expand All @@ -127,9 +127,6 @@ jobs:
fetch-depth: 0
- name: Add msbuild to PATH
uses: microsoft/setup-msbuild@v2
- name: Download Playnite Toolbox
run: |-
mkdir -p .tools/Playnite && curl "${{ secrets.PLAYNITE_TOOLBOX_URL }}" -o Playnite.zip && unzip Playnite.zip -d .tools/Playnite
- name: Install jq
run: curl -L -o jq.exe https://github.com/stedolan/jq/releases/latest/download/jq-win64.exe
- name: Read Node version
Expand All @@ -149,12 +146,7 @@ jobs:
- run: corepack prepare --activate yarn@${{ steps.yarn_version.outputs.value }}
- name: Install deps
run: yarn
- name: Package extension
run: yarn nx affected --base=origin/main --head=HEAD --target=package --parallel --verbose --exclude='*,!tag:windows'
- name: Build extension
run: yarn nx affected --base=origin/main --head=HEAD --target=build --parallel --verbose --exclude='*,!tag:windows'
env:
NODE_ENV: production
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: playnite-extension
path: apps/*/_packaged/**
3,117 changes: 1,585 additions & 1,532 deletions .pnp.cjs
100644 → 100755

Large diffs are not rendered by default.

Binary file modified .yarn/install-state.gz
100644 → 100755
Binary file not shown.
Empty file modified apps/game-db-updater/package.json
100644 → 100755
Empty file.
Empty file modified apps/playnite-web/package.json
100644 → 100755
Empty file.
14 changes: 14 additions & 0 deletions hass-game-db-updater/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
ARG VERSION
FROM ghcr.io/andrew-codes/playnite-web-game-db-updater:$VERSION

ENV BASHIO_VERSION="0.16.2"
RUN mkdir -p /tmp/bashio && \
curl -sSL "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio && \
mv /tmp/bashio/lib /usr/lib/bashio && \
ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \
rm -rf /tmp/bashio

COPY src/run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]
35 changes: 35 additions & 0 deletions hass-game-db-updater/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"name": "Playnite Web Game DB Updater",
"url": "https://github.com/andrew-codes/playnite-web",
"version": "dev",
"slug": "playnite-web-game-db-updater",
"description": "An add-on to synchronize Playnite Web game database using MQTT and MongoDB.",
"icon": "playnite-icon.png",
"arch": ["aarch64", "amd64"],
"startup": "services",
"boot": "auto",
"options": {
"MQTT_HOST": "localhost",
"MQTT_PORT": 1883,
"MQTT_USERNAME": "",
"MQTT_PASSWORD": "",
"DB_HOST": "localhost",
"DB_PORT": 27017,
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DEBUG": "game-db-updater/*"
},
"schema": {
"MQTT_HOST": "str",
"MQTT_PORT": "int",
"MQTT_USERNAME": "str?",
"MQTT_PASSWORD": "str?",
"DB_HOST": "str",
"DB_PORT": "int",
"DB_USERNAME": "str?",
"DB_PASSWORD": "str?",
"DEBUG": "str"
},
"image": "ghcr.io/andrew-codes/playnite-web-game-db-updater-hass-addon",
"map": ["config:rw"]
}
Binary file added hass-game-db-updater/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions hass-game-db-updater/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "playnite-web-game-db-updater-hass-addon",
"version": "3.1.4",
"dependencies": {
"playnite-web-game-db-updater": "workspace:*"
},
"devDependencies": {
"@types/lodash": "^4.17.4",
"@types/shelljs": "^0.8.15",
"esbuild": "^0.21.4",
"esbuild-register": "^3.5.0",
"lodash": "^4.17.21",
"nx": "^19.1.1",
"shelljs": "^0.8.5",
"versioning": "workspace:*"
}
}
30 changes: 30 additions & 0 deletions hass-game-db-updater/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "hass-game-db-updater",
"sourceRoot": "hass-game-db-updater/src",
"projectType": "application",
"targets": {
"package": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/package.ts"],
"cwd": "{projectRoot}"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/publish.ts"],
"cwd": "{projectRoot}"
}
},
"version": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/version.ts"],
"cwd": "{projectRoot}"
}
}
},
"tags": ["linux"],
"implicitDependencies": []
}
23 changes: 23 additions & 0 deletions hass-game-db-updater/scripts/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sh from 'shelljs'
import { getDockerTags } from 'versioning'
import pkg from '../package.json'

async function run() {
sh.cp('-R', '.dist/', '_packaged/')

const { REGISTRY, OWNER, GITHUB_REF } = process.env

if (!REGISTRY || !OWNER || !GITHUB_REF) {
throw new Error('Missing environment variables')
}

let tags = await getDockerTags(pkg.version, GITHUB_REF)

for (const tag of tags) {
sh.exec(
`docker build --tag "${REGISTRY}/${OWNER}/${pkg.name}:${tag}" --file Dockerfile --build-arg VERSION=${tag} .`,
)
}
}

run()
19 changes: 19 additions & 0 deletions hass-game-db-updater/scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sh from 'shelljs'
import { getDockerTags } from 'versioning'
import pkg from '../package.json'

async function run() {
const { REGISTRY, OWNER, GITHUB_REF } = process.env

if (!REGISTRY || !OWNER || !GITHUB_REF) {
throw new Error('Missing environment variables')
}

let tags = await getDockerTags(pkg.version, GITHUB_REF)

for (const tag of tags) {
sh.exec(`docker push "${REGISTRY}/${OWNER}/${pkg.name}:${tag}"`)
}
}

run()
14 changes: 14 additions & 0 deletions hass-game-db-updater/scripts/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'fs'
import { merge } from 'lodash'
import path from 'path'
import sh from 'shelljs'
import config from '../config.json'
import pkg from '../package.json'

const newConfig = merge({}, config, { version: pkg.version })

fs.writeFileSync(
path.join(__dirname, '..', 'config.json'),
JSON.stringify(newConfig, null, 2),
)
sh.exec(`git add . && git commit --amend --no-edit`)
25 changes: 25 additions & 0 deletions hass-game-db-updater/src/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
#!/usr/bin/env bash
set -e

source /usr/lib/bashio/bashio.sh
export MQTT_HOST=$(bashio::config 'MQTT_HOST')
export MQTT_PORT=$(bashio::config 'MQTT_PORT')
export MQTT_USERNAME=$(bashio::config 'MQTT_USERNAME')
export MQTT_PASSWORD=$(bashio::config 'MQTT_PASSWORD')
export DB_HOST=$(bashio::config 'DB_HOST')
export DB_PORT=$(bashio::config 'DB_PORT')
export DB_USERNAME=$(bashio::config 'DB_USERNAME')
export DB_PASSWORD=$(bashio::config 'DB_PASSWORD')
export DEBUG=$(bashio::config 'DEBUG')

echo "Configuration loaded:"
echo "MQTT_HOST: $MQTT_HOST"
echo "MQTT_PORT: $MQTT_PORT"
echo "MQTT_USERNAME: $MQTT_USERNAME"
echo "DB_HOST: $DB_HOST"
echo "DB_PORT: $DB_PORT"
echo "DB_USERNAME: $DB_USERNAME"
echo "DEBUG: $DEBUG"

echo "Starting Playnite Web Game Updater application..."
node index.js
13 changes: 13 additions & 0 deletions hass-playnite-web/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
FROM ghcr.io/andrew-codes/playnite-web-app:3-dev

ENV BASHIO_VERSION="0.16.2"
RUN mkdir -p /tmp/bashio && \
curl -sSL "https://github.com/hassio-addons/bashio/archive/v${BASHIO_VERSION}.tar.gz" | tar -xzf - --strip 1 -C /tmp/bashio && \
mv /tmp/bashio/lib /usr/lib/bashio && \
ln -s /usr/lib/bashio/bashio /usr/bin/bashio && \
rm -rf /tmp/bashio

COPY src/run.sh /
RUN chmod a+x /run.sh

CMD [ "/run.sh" ]
48 changes: 48 additions & 0 deletions hass-playnite-web/config.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "Playnite Web App",
"url": "https://github.com/andrew-codes/playnite-web",
"version": "dev",
"slug": "playnite-web-app",
"description": "An add-on to provide web interface and API for Playnite.",
"arch": ["aarch64", "amd64"],
"webui": "http://[HOST]:[PORT:3000]",
"startup": "services",
"boot": "auto",
"options": {
"PORT": 3000,
"DB_HOST": "localhost",
"DB_PORT": 27017,
"DB_USERNAME": "",
"DB_PASSWORD": "",
"DEBUG": "playnite-web/*",
"USERNAME": "",
"PASSWORD": "",
"SECRET": "",
"MQTT_HOST": "localhost",
"MQTT_PORT": 1883,
"MQTT_USERNAME": "",
"MQTT_PASSWORD": ""
},
"schema": {
"PORT": "int",
"DB_HOST": "str",
"DB_PORT": "int",
"DB_USERNAME": "str?",
"DB_PASSWORD": "str?",
"DEBUG": "str?",
"USERNAME": "str?",
"PASSWORD": "str?",
"SECRET": "str?",
"MQTT_HOST": "str",
"MQTT_PORT": "int",
"MQTT_USERNAME": "str?",
"MQTT_PASSWORD": "str?"
},
"ingress": true,
"ingress_port": "[PORT]",
"ingress_entry": "/",
"ingress_stream": false,
"image": "ghcr.io/andrew-codes/playnite-web-app-hass-addon",
"map": ["config:rw"],
"icon": "playnite-icon.png"
}
Binary file added hass-playnite-web/icon.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
17 changes: 17 additions & 0 deletions hass-playnite-web/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"name": "playnite-web-app-hass-addon",
"version": "3.1.4",
"dependencies": {
"playnite-web-app": "workspace:*"
},
"devDependencies": {
"@types/lodash": "^4.17.4",
"@types/shelljs": "^0.8.15",
"esbuild": "^0.21.4",
"esbuild-register": "^3.5.0",
"lodash": "^4.17.21",
"nx": "^19.1.1",
"shelljs": "^0.8.5",
"versioning": "workspace:*"
}
}
30 changes: 30 additions & 0 deletions hass-playnite-web/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "hass-playnite-web",
"sourceRoot": "hass-playnite-web/src",
"projectType": "application",
"targets": {
"package": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/package.ts"],
"cwd": "{projectRoot}"
}
},
"publish": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/publish.ts"],
"cwd": "{projectRoot}"
}
},
"version": {
"executor": "nx:run-commands",
"options": {
"commands": ["yarn node --require=esbuild-register scripts/version.ts"],
"cwd": "{projectRoot}"
}
}
},
"tags": ["linux"],
"implicitDependencies": []
}
23 changes: 23 additions & 0 deletions hass-playnite-web/scripts/package.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import sh from 'shelljs'
import { getDockerTags } from 'versioning'
import pkg from '../package.json'

async function run() {
sh.cp('-R', '.dist/', '_packaged/')

const { REGISTRY, OWNER, GITHUB_REF } = process.env

if (!REGISTRY || !OWNER || !GITHUB_REF) {
throw new Error('Missing environment variables')
}

let tags = await getDockerTags(pkg.version, GITHUB_REF)

for (const tag of tags) {
sh.exec(
`docker build --tag "${REGISTRY}/${OWNER}/${pkg.name}:${tag}" --file Dockerfile --build-arg VERSION=${tag} .`,
)
}
}

run()
19 changes: 19 additions & 0 deletions hass-playnite-web/scripts/publish.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import sh from 'shelljs'
import { getDockerTags } from 'versioning'
import pkg from '../package.json'

async function run() {
const { REGISTRY, OWNER, GITHUB_REF } = process.env

if (!REGISTRY || !OWNER || !GITHUB_REF) {
throw new Error('Missing environment variables')
}

let tags = await getDockerTags(pkg.version, GITHUB_REF)

for (const tag of tags) {
sh.exec(`docker push "${REGISTRY}/${OWNER}/${pkg.name}:${tag}"`)
}
}

run()
14 changes: 14 additions & 0 deletions hass-playnite-web/scripts/version.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import fs from 'fs'
import { merge } from 'lodash'
import path from 'path'
import sh from 'shelljs'
import config from '../config.json'
import pkg from '../package.json'

const newConfig = merge({}, config, { version: pkg.version })

fs.writeFileSync(
path.join(__dirname, '..', 'config.json'),
JSON.stringify(newConfig, null, 2),
)
sh.exec(`git add . && git commit --amend --no-edit`)
Loading