Skip to content

Commit

Permalink
Merge pull request #11 from wizzomafizzo/wizzo/build-scripts
Browse files Browse the repository at this point in the history
Update build scripts
  • Loading branch information
wizzomafizzo committed Jan 21, 2024
2 parents 367bda0 + 253a160 commit 842477d
Show file tree
Hide file tree
Showing 8 changed files with 133 additions and 179 deletions.
32 changes: 32 additions & 0 deletions .github/workflows/mister_repo.yml
@@ -0,0 +1,32 @@
name: Generate MiSTer latest repo
on:
workflow_dispatch:

permissions: write-all
jobs:
mister-repo:
runs-on: ubuntu-latest
env:
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
steps:
- uses: actions/checkout@v2
- name: Get latest TapTo release
id: taptoreleaseinfo
uses: cardinalby/git-get-release-action@v1
with:
latest: true
repo: wizzomafizzo/tapto
ref: main
- name: Download release files
run: |
DL_URL=https://github.com/wizzomafizzo/tapto/releases/download/${{ steps.taptoreleaseinfo.outputs.tag_name }}
mkdir -p _bin/releases
curl -L ${DL_URL}/tapto.sh -o _bin/releases/tapto.sh
curl -L ${DL_URL}/taptui.sh -o _bin/releases/taptui.sh
- name: Create databases
run: |
python scripts/mister/repo/generate.py ${{ steps.taptoreleaseinfo.outputs.tag_name }}
- name: Commit databases
uses: EndBug/add-and-commit@v9
with:
add: scripts/mister/repo/tapto.json -f -A
2 changes: 1 addition & 1 deletion .gitignore
Expand Up @@ -14,5 +14,5 @@ go.work
/bin
/_bin
/out
scripts/misterbuild/_build
scripts/mister/build/_build
.DS_Store
6 changes: 3 additions & 3 deletions magefile.go
Expand Up @@ -39,8 +39,8 @@ var (
binReleasesDir = filepath.Join(binDir, "releases")
upxBin = os.Getenv("UPX_BIN")
// docker mister arm build
misterBuild = filepath.Join(cwd, "scripts", "misterbuild")
misterBuildImageName = "tapto/misterbuild"
misterBuild = filepath.Join(cwd, "scripts", "mister", "build")
misterBuildImageName = "tapto/mister-build"
misterBuildCache = filepath.Join(os.TempDir(), "tapto-mister-buildcache")
misterModCache = filepath.Join(os.TempDir(), "tapto-mister-modcache")
)
Expand All @@ -63,7 +63,7 @@ var apps = []app{
bin: "tapto.sh",
releaseId: "mrext/tapto",
ldFlags: "-lnfc -lusb -lcurses",
releaseFiles: []string{filepath.Join(cwd, "scripts", "nfcui", "nfcui.sh")},
releaseFiles: []string{filepath.Join(cwd, "scripts", "taptui", "taptui.sh")},
},
}

Expand Down
175 changes: 0 additions & 175 deletions scripts/generate_repo.py

This file was deleted.

File renamed without changes.
File renamed without changes.
97 changes: 97 additions & 0 deletions scripts/mister/repo/generate.py
@@ -0,0 +1,97 @@
#!/usr/bin/env python3

import os
import json
import hashlib
import sys
import time
from pathlib import Path
from zipfile import ZipFile
from typing import TypedDict, Union, Optional, List

DB_ID = "mrext/tapto"
DL_URL = "https://github.com/wizzomafizzo/tapto/releases/download/{}"
RELEASES_FOLDER = "_bin/releases"
REPO_FOLDER = "scripts/mister/repo"
FILES = [
"tapto.sh",
"taptui.sh",
]


class RepoDbFilesItem(TypedDict):
hash: str
size: int
url: Optional[str]
overwrite: Optional[bool]
reboot: Optional[bool]
tags: List[str]


RepoDbFiles = dict[str, RepoDbFilesItem]


class RepoDbFoldersItem(TypedDict):
tags: Optional[list[Union[str, int]]]


RepoDbFolders = dict[str, RepoDbFoldersItem]


class RepoDb(TypedDict):
db_id: str
timestamp: int
files: RepoDbFiles
folders: RepoDbFolders
base_files_url: Optional[str]


def create_tapto_db(tag: str) -> RepoDb:
folders: RepoDbFolders = {
"Scripts/": RepoDbFoldersItem(tags=None),
}

files: RepoDbFiles = {}
for file in FILES:
local_path = os.path.join(RELEASES_FOLDER, file)

key = "Scripts/{}".format(os.path.basename(local_path))
size = os.stat(local_path).st_size
md5 = hashlib.md5(open(local_path, "rb").read()).hexdigest()
url = "{}/{}".format(DL_URL.format(tag), os.path.basename(local_path))

file_entry = RepoDbFilesItem(
hash=md5, size=size, url=url, overwrite=None, reboot=None, tags=[Path(local_path).stem]
)

files[key] = file_entry

return RepoDb(
db_id=DB_ID,
timestamp=int(time.time()),
files=files,
folders=folders,
base_files_url=None,
)


def remove_nulls(v: any) -> any:
if isinstance(v, dict):
return {key: remove_nulls(val) for key, val in v.items() if val is not None}
else:
return v


def generate_json(repo_db: RepoDb) -> str:
return json.dumps(remove_nulls(repo_db), indent=4)


def main():
tag = sys.argv[1]

repo_db = create_tapto_db(tag)
with open("{}/tapto.json".format(REPO_FOLDER), "w") as f:
f.write(generate_json(repo_db))

if __name__ == "__main__":
main()

0 comments on commit 842477d

Please sign in to comment.