From e7d8d632a009924f8a8c8159787c8a7f3bb96da3 Mon Sep 17 00:00:00 2001 From: ck Date: Mon, 5 Feb 2024 09:30:49 -0500 Subject: [PATCH] Add publish workflow and update display layout --- .github/workflows/publish.yml | 188 +++++++++++++++++++++++++++++ pwnagotchi/ui/hw/waveshare3in52.py | 42 ++++--- 2 files changed, 211 insertions(+), 19 deletions(-) create mode 100644 .github/workflows/publish.yml diff --git a/.github/workflows/publish.yml b/.github/workflows/publish.yml new file mode 100644 index 00000000..ef7173de --- /dev/null +++ b/.github/workflows/publish.yml @@ -0,0 +1,188 @@ +name: Publish + +on: + workflow_dispatch: + inputs: + version: + description: 'Version number' + required: true + +jobs: + + publish: + runs-on: ubuntu-latest + steps: + + - name: Remove unnecessary directories + run: | + sudo rm -rf /usr/share/dotnet + sudo rm -rf /opt/ghc + sudo rm -rf /usr/local/share/boost + sudo rm -rf "$AGENT_TOOLSDIRECTORY" + + - name: Check disk space + run: df -BG + + - name: Checkout code + uses: actions/checkout@v4 + + - name: Validate tag + id: tag-setter + run: | + TAG=${{ github.event.inputs.version }} + if [[ $TAG =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then + echo "Tag $TAG is valid." + echo "TAG=$TAG" >> $GITHUB_OUTPUT + else + echo "Tag $TAG is not a valid semantic version. Aborting." + exit 1 + fi + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: 3.9 + + - name: Install dependencies + run: | + sudo apt-get update && sudo apt-get install -y libdbus-1-dev curl unzip gettext qemu-utils qemu qemu-user-static binfmt-support + pip install -r requirements.txt + + - name: Update QEMU + run: | + sudo update-binfmts --enable qemu-arm + sudo update-binfmts --enable qemu-aarch64 + + - name: Restart binfmt-support + run: sudo service binfmt-support restart + + - name: Mount binfmt_misc + run: | + if ! grep -qs '/proc/sys/fs/binfmt_misc ' /proc/mounts; then + sudo mount binfmt_misc -t binfmt_misc /proc/sys/fs/binfmt_misc + fi + + - name: Restart binfmt-support + run: sudo service binfmt-support restart + + - name: Update Languages + run: make update_langs + + - name: Compile Languages + run: make compile_langs + + - name: Check disk space + run: df -BG + + - name: Run Makefile + run: make + env: + PWN_VERSION: ${{ steps.tag-setter.outputs.TAG }} + + - name: Compress .img files + run: | + find /home/runner/work/ -type f -name "*.img" -exec xz --no-warn {} \; + + - name: Create tag + uses: actions/github-script@v7 + with: + script: | + const version = "${{ steps.tag-setter.outputs.TAG }}" + console.log(`Creating tag ${version}`) + await github.rest.git.createRef({ + owner: context.repo.owner, + repo: context.repo.repo, + ref: `refs/tags/${version}`, + sha: context.sha + }) + + - name: Create Release + id: create_release + uses: actions/github-script@v7 + with: + script: | + const tag = "${{ steps.tag-setter.outputs.TAG }}" + console.log(`Creating release with tag: ${tag}`) + const release = await github.rest.repos.createRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + tag_name: tag, + name: tag, + draft: false, + prerelease: true, + generate_release_notes: true + }) + console.log(`Created release with id: ${release.data.id}`) + return release.data.id + + - name: Upload Release Asset + id: upload-release-asset + uses: actions/github-script@v7 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + script: | + const fs = require('fs'); + const path = require('path'); + const release_id = "${{ steps.create_release.outputs.result }}"; + const asset_content_type = 'application/octet-stream'; + const distDir = '/home/runner/work/pwnagotchi/'; + + const uploadFile = async (filePath) => { + if (fs.lstatSync(filePath).isDirectory()) { + const files = fs.readdirSync(filePath); + for (const file of files) { + await uploadFile(path.join(filePath, file)); + } + } else { + // Check if the file has a .xz extension + if (path.extname(filePath) === '.xz') { + console.log(`Uploading ${filePath}...`); + + const asset_name = path.basename(filePath); + const asset_size = fs.statSync(filePath).size; + const asset = fs.createReadStream(filePath); + + const response = await github.rest.repos.uploadReleaseAsset({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release_id, + name: asset_name, + data: asset, + headers: { + 'content-type': asset_content_type, + 'content-length': asset_size + } + }); + + console.log(`Uploaded ${filePath}: ${response.data.browser_download_url}`); + } + } + } + + await uploadFile(distDir); + + - name: Update Release + uses: actions/github-script@v7 + with: + script: | + const release_id = "${{ steps.create_release.outputs.result }}" + console.log(`Updating release with id: ${release_id}`) + github.rest.repos.updateRelease({ + owner: context.repo.owner, + repo: context.repo.repo, + release_id: release_id, + tag_name: "${{ steps.tag-setter.outputs.TAG }}", + name: "${{ steps.tag-setter.outputs.TAG }}", + draft: false, + prerelease: false + }) + + - name: Save environment variable + run: echo "${{ steps.tag-setter.outputs.TAG }}" > env_var.txt + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: env-var + path: env_var.txt \ No newline at end of file diff --git a/pwnagotchi/ui/hw/waveshare3in52.py b/pwnagotchi/ui/hw/waveshare3in52.py index b2252a0b..95120fc6 100644 --- a/pwnagotchi/ui/hw/waveshare3in52.py +++ b/pwnagotchi/ui/hw/waveshare3in52.py @@ -9,36 +9,40 @@ class Waveshare3in52(DisplayImpl): super(Waveshare3in52, self).__init__(config, 'waveshare3in52') def layout(self): - fonts.setup(10, 8, 10, 18, 25, 9) - self._layout['width'] = 240 - self._layout['height'] = 360 - self._layout['face'] = (0, 43) - self._layout['name'] = (0, 14) - self._layout['channel'] = (0, 0) - self._layout['aps'] = (0, 71) - self._layout['uptime'] = (0, 25) - self._layout['line1'] = [0, 12, 240, 12] - self._layout['line2'] = [0, 116, 240, 116] - self._layout['friend_face'] = (12, 88) - self._layout['friend_name'] = (1, 103) - self._layout['shakes'] = (26, 117) - self._layout['mode'] = (0, 117) + fonts.setup(16, 14, 16, 100, 31, 15) + self._layout['width'] = 360 + self._layout['height'] = 240 + self._layout['face'] = (0, 40) + self._layout['name'] = (0, 0) + self._layout['channel'] = (300, 0) + self._layout['aps'] = (0, 220) + self._layout['uptime'] = (120, 0) + self._layout['line1'] = [0, 24, 360, 24] + self._layout['line2'] = [0, 220, 360, 220] + self._layout['friend_face'] = (0, 195) + self._layout['friend_name'] = (0, 185) + self._layout['shakes'] = (100, 220) + self._layout['mode'] = (0,200) self._layout['status'] = { - 'pos': (65, 26), + 'pos': (3, 170), 'font': fonts.status_font(fonts.Small), - 'max': 12 + 'max': 100 } return self._layout def initialize(self): - logging.info("initializing waveshare 3.52 inch lcd display") + logging.info("initializing waveshare 3.52 inch display") from pwnagotchi.ui.hw.libs.waveshare.v3in52.epd3in52 import EPD self._display = EPD() self._display.init() self._display.Clear() def render(self, canvas): - self._display.display(canvas) + self._display.Clear() + buf = self._display.getbuffer(canvas) + self._display.display(buf) + self._display.refresh() + def clear(self): - self._display.Clear() + self._display.Clear() \ No newline at end of file