From dceab1a75a0c7f3ee1d53610649319d25c9a616e Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 16:50:46 +0100 Subject: [PATCH 1/7] Add Forgejo action --- .forgejo/workflows/build.yaml | 117 ++++++++++++++++++++++++++++++++++ 1 file changed, 117 insertions(+) create mode 100644 .forgejo/workflows/build.yaml diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml new file mode 100644 index 0000000..d386a7d --- /dev/null +++ b/.forgejo/workflows/build.yaml @@ -0,0 +1,117 @@ +on: [push] +jobs: + check-changes: + runs-on: docker + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Get changed files count + id: changed-files + uses: tj-actions/changed-files@v45 + with: + files_ignore: 'doc/**,README.md,Dockerfile,.*' + files_ignore_separator: ',' + - name: Print changed files count + run: > + echo "Changed files count: ${{ + steps.changed-files.outputs.all_changed_and_modified_files_count }}" + + build: + needs: check-changes + runs-on: ubuntu-latest + if: ${{ needs.check-changes.outputs.all_changed_and_modified_files_count >= 1 }} + permissions: + contents: write + + steps: + - uses: actions/checkout@v4 + with: + submodules: recursive + - uses: actions/setup-node@v4 + with: + node-version: lts/* + cache: yarn + cache-dependency-path: '**/yarn.lock' + - uses: actions/cache@v4 + with: + path: | + ~/.cache/pip + ~/node_modules + key: ${{ runner.os }}-pio + - uses: actions/setup-python@v5 + with: + python-version: '3.9' + - name: Get current date + id: dateAndTime + run: echo "dateAndTime=$(date +'%Y-%m-%d-%H:%M')" >> $GITHUB_OUTPUT + - name: Install mklittlefs + run: > + git clone https://github.com/earlephilhower/mklittlefs.git /tmp/mklittlefs && + cd /tmp/mklittlefs && + git submodule update --init && + make dist + - name: Install yarn + run: yarn && yarn postinstall + - name: Run linter + run: yarn lint + - name: Run vitest tests + run: yarn vitest run + - name: Install Playwright Browsers + run: npx playwright install --with-deps + - name: Run Playwright tests + run: npx playwright test + - name: Build WebUI + run: yarn build + - name: Get current block + id: getBlockHeight + run: echo "blockHeight=$(curl -s https://mempool.space/api/blocks/tip/height)" >> $GITHUB_OUTPUT + - name: Write block height to file + env: + BLOCK_HEIGHT: ${{ steps.getBlockHeight.outputs.blockHeight }} + run: mkdir -p output && echo "$BLOCK_HEIGHT" > output/version.txt + - name: gzip build for LittleFS + run: find dist -type f ! -name ".*" -exec sh -c 'mkdir -p "build_gz/$(dirname "${1#dist/}")" && gzip -k "$1" -c > "build_gz/${1#dist/}".gz' _ {} \; + - name: Write git rev to file + run: echo "$GITHUB_SHA" > build_gz/fs_hash.txt && echo "$GITHUB_SHA" > output/commit.txt + - name: Check GZipped directory size + run: | + # Set the threshold size in bytes + THRESHOLD=409600 + + # Calculate the total size of files in the directory + DIRECTORY_SIZE=$(du -b -s build_gz | awk '{print $1}') + + # Fail the workflow if the size exceeds the threshold + if [ "$DIRECTORY_SIZE" -gt "$THRESHOLD" ]; then + echo "Directory size exceeds the threshold of $THRESHOLD bytes" + exit 1 + else + echo "Directory size is within the threshold $DIRECTORY_SIZE" + fi + - name: Create tarball + run: tar czf webui.tgz --strip-components=1 dist + - name: Build LittleFS + run: | + set -e + /tmp/mklittlefs/mklittlefs -c build_gz -s 409600 output/littlefs.bin + - name: Upload artifacts + uses: actions/upload-artifact@v4 + with: + path: | + webui.tgz + output/littlefs.bin + - name: Create release + if: github.event_name == 'push' && github.ref == 'refs/heads/main' + uses: https://code.forgejo.org/actions/forgejo-release@v2.4.0 + with: + url: "https://git.btclock.dev/" + repo: "btclock/webui" + direction: upload + tag: ${{ steps.getBlockHeight.outputs.blockHeight }} + sha: "${{ github.sha }}" + release-dir: output + token: ${{ secrets.TOKEN }} + override: false + verbose: false + release-notes-assistant: false \ No newline at end of file From 0b3f6d3de17ceeb498bd5578f0d9dcff0077e098 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 16:55:42 +0100 Subject: [PATCH 2/7] Fix forgejo workflow --- .forgejo/workflows/build.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index d386a7d..129385e 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -19,7 +19,7 @@ jobs: build: needs: check-changes - runs-on: ubuntu-latest + runs-on: docker if: ${{ needs.check-changes.outputs.all_changed_and_modified_files_count >= 1 }} permissions: contents: write @@ -106,7 +106,7 @@ jobs: uses: https://code.forgejo.org/actions/forgejo-release@v2.4.0 with: url: "https://git.btclock.dev/" - repo: "btclock/webui" + repo: "${{ github.repository }}" direction: upload tag: ${{ steps.getBlockHeight.outputs.blockHeight }} sha: "${{ github.sha }}" From 6028268227943f4a391f697a3771098ef9bd093d Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 16:57:33 +0100 Subject: [PATCH 3/7] Fix workflow --- .forgejo/workflows/build.yaml | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 129385e..0d8651a 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -2,6 +2,8 @@ on: [push] jobs: check-changes: runs-on: docker + outputs: + all_changed_and_modified_files_count: ${{ steps.changed-files.outputs.all_changed_and_modified_files_count }} steps: - name: Checkout code uses: actions/checkout@v4 @@ -105,13 +107,13 @@ jobs: if: github.event_name == 'push' && github.ref == 'refs/heads/main' uses: https://code.forgejo.org/actions/forgejo-release@v2.4.0 with: - url: "https://git.btclock.dev/" - repo: "${{ github.repository }}" + url: 'https://git.btclock.dev/' + repo: '${{ github.repository }}' direction: upload tag: ${{ steps.getBlockHeight.outputs.blockHeight }} - sha: "${{ github.sha }}" + sha: '${{ github.sha }}' release-dir: output token: ${{ secrets.TOKEN }} override: false verbose: false - release-notes-assistant: false \ No newline at end of file + release-notes-assistant: false From 55859cf8d4c9522f4ebc3f217254886e61afc926 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 17:04:51 +0100 Subject: [PATCH 4/7] Fix workflow python version --- .forgejo/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 0d8651a..4a06721 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -43,7 +43,7 @@ jobs: key: ${{ runner.os }}-pio - uses: actions/setup-python@v5 with: - python-version: '3.9' + python-version: '>=3.10' - name: Get current date id: dateAndTime run: echo "dateAndTime=$(date +'%Y-%m-%d-%H:%M')" >> $GITHUB_OUTPUT From a891529cdc92d4b2a9aadf76a5ac6624d16afeb3 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 17:14:57 +0100 Subject: [PATCH 5/7] Fix workflow container --- .forgejo/workflows/build.yaml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 4a06721..0f088ee 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -22,6 +22,8 @@ jobs: build: needs: check-changes runs-on: docker + container: + image: catthehacker/ubuntu:act-22.04 if: ${{ needs.check-changes.outputs.all_changed_and_modified_files_count >= 1 }} permissions: contents: write From 81238e57edbde561b48c38c25dda60638943c515 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 17:19:29 +0100 Subject: [PATCH 6/7] Forgejo js image --- .forgejo/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 0f088ee..1f64a5c 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -23,7 +23,7 @@ jobs: needs: check-changes runs-on: docker container: - image: catthehacker/ubuntu:act-22.04 + image: ghcr.io/catthehacker/ubuntu:js-22.04 if: ${{ needs.check-changes.outputs.all_changed_and_modified_files_count >= 1 }} permissions: contents: write From 1bac10e4ef1f88b0d98fdfd351dd593c4e80fc03 Mon Sep 17 00:00:00 2001 From: Djuri Baars Date: Tue, 26 Nov 2024 17:27:22 +0100 Subject: [PATCH 7/7] use upload artifacts fork --- .forgejo/workflows/build.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.forgejo/workflows/build.yaml b/.forgejo/workflows/build.yaml index 1f64a5c..fe38500 100644 --- a/.forgejo/workflows/build.yaml +++ b/.forgejo/workflows/build.yaml @@ -100,7 +100,7 @@ jobs: set -e /tmp/mklittlefs/mklittlefs -c build_gz -s 409600 output/littlefs.bin - name: Upload artifacts - uses: actions/upload-artifact@v4 + uses: https://code.forgejo.org/forgejo/upload-artifact@v4 with: path: | webui.tgz