btclock-webui/.github/workflows/workflow.yml

137 lines
4.7 KiB
YAML
Raw Normal View History

2023-11-19 15:08:26 +01:00
name: BTClock WebUI CI
on: [push]
env:
2023-11-19 20:27:22 +01:00
PUBLIC_BASE_URL: ''
2023-11-19 15:08:26 +01:00
jobs:
2023-11-19 15:54:44 +01:00
check-changes:
runs-on: ubuntu-latest
2023-11-19 16:09:04 +01:00
outputs:
all_changed_and_modified_files_count: ${{ steps.changed-files.outputs.all_changed_and_modified_files_count }}
2023-11-19 15:54:44 +01:00
steps:
- name: Checkout code
2023-11-19 20:27:22 +01:00
uses: actions/checkout@v4
2023-11-19 15:54:44 +01:00
- name: Get changed files count
id: changed-files
uses: tj-actions/changed-files@v45
2023-11-19 16:25:31 +01:00
with:
2023-11-19 20:27:22 +01:00
files_ignore: 'doc/**,README.md,Dockerfile,.*'
2023-11-19 16:25:31 +01:00
files_ignore_separator: ','
2023-11-19 15:54:44 +01:00
- name: Print changed files count
2023-11-19 16:02:06 +01:00
run: >
echo "Changed files count: ${{
2023-11-19 16:09:04 +01:00
steps.changed-files.outputs.all_changed_and_modified_files_count }}"
2023-11-19 15:54:44 +01:00
2023-11-19 15:08:26 +01:00
build:
2023-11-19 15:54:44 +01:00
needs: check-changes
2023-11-19 15:08:26 +01:00
runs-on: ubuntu-latest
2023-11-19 18:31:06 +01:00
if: ${{ needs.check-changes.outputs.all_changed_and_modified_files_count >= 1 }}
2023-11-19 15:08:26 +01:00
permissions:
contents: write
steps:
2023-11-19 20:27:22 +01:00
- uses: actions/checkout@v4
2023-11-19 15:08:26 +01:00
with:
submodules: recursive
2024-06-09 00:23:39 +02:00
- uses: actions/setup-node@v4
2023-11-19 15:08:26 +01:00
with:
node-version: lts/*
cache: yarn
cache-dependency-path: '**/yarn.lock'
- uses: actions/cache@v4
2023-11-19 15:08:26 +01:00
with:
path: |
~/.cache/pip
~/node_modules
key: ${{ runner.os }}-pio
2024-06-09 00:23:39 +02:00
- uses: actions/setup-python@v5
2023-11-19 15:08:26 +01:00
with:
python-version: '3.9'
- name: Get current date
id: dateAndTime
2023-11-19 15:21:38 +01:00
run: echo "dateAndTime=$(date +'%Y-%m-%d-%H:%M')" >> $GITHUB_OUTPUT
2023-11-19 15:08:26 +01:00
- name: Install mklittlefs
run: >
2023-11-19 15:12:14 +01:00
git clone https://github.com/earlephilhower/mklittlefs.git /tmp/mklittlefs &&
cd /tmp/mklittlefs &&
git submodule update --init &&
2023-11-19 15:08:26 +01:00
make dist
- name: Install yarn
2023-11-19 15:18:37 +01:00
run: yarn && yarn postinstall
2023-11-21 21:22:29 +01:00
- name: Run linter
run: yarn lint
2023-11-23 02:04:20 +01:00
- name: Run vitest tests
2023-11-23 02:46:41 +01:00
run: yarn vitest run
2023-11-23 02:04:20 +01:00
- name: Install Playwright Browsers
run: npx playwright install --with-deps
- name: Run Playwright tests
run: npx playwright test
2023-11-21 21:33:34 +01:00
- name: Build WebUI
run: yarn build
2023-11-19 15:36:25 +01:00
- name: Get current block
id: getBlockHeight
run: echo "blockHeight=$(curl -s https://mempool.space/api/blocks/tip/height)" >> $GITHUB_OUTPUT
2023-11-26 02:01:50 +01:00
- name: Write block height to file
env:
BLOCK_HEIGHT: ${{ steps.getBlockHeight.outputs.blockHeight }}
2023-11-26 02:06:24 +01:00
run: mkdir -p output && echo "$BLOCK_HEIGHT" > output/version.txt
2023-11-19 15:08:26 +01:00
- 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
2024-06-29 16:39:43 +02:00
run: echo "$GITHUB_SHA" > build_gz/fs_hash.txt && echo "$GITHUB_SHA" > output/commit.txt
2023-11-21 20:44:00 +01:00
- 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"
2023-11-21 20:44:00 +01:00
fi
2023-11-19 15:08:26 +01:00
- name: Create tarball
run: tar czf webui.tgz --strip-components=1 dist
- name: Build LittleFS
2024-09-03 12:37:35 +02:00
run: |
set -e
/tmp/mklittlefs/mklittlefs -c build_gz -s 409600 output/littlefs.bin
2023-11-19 15:08:26 +01:00
- name: Upload artifacts
uses: actions/upload-artifact@v4
2023-11-19 15:08:26 +01:00
with:
path: |
webui.tgz
2023-11-25 22:56:20 +01:00
output/littlefs.bin
2023-11-19 15:08:26 +01:00
- name: Create release
2024-09-03 11:37:34 +02:00
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
2023-11-19 15:08:26 +01:00
uses: ncipollo/release-action@v1
with:
2023-11-19 15:40:41 +01:00
tag: ${{ steps.getBlockHeight.outputs.blockHeight }}
2023-11-19 15:18:37 +01:00
commit: main
2023-11-19 15:36:25 +01:00
name: release-${{ steps.getBlockHeight.outputs.blockHeight }}
2023-11-25 22:56:20 +01:00
artifacts: 'output/littlefs.bin,webui.tgz'
2023-11-19 15:08:26 +01:00
allowUpdates: true
removeArtifacts: true
2023-11-19 20:27:22 +01:00
makeLatest: true
2023-11-25 22:56:20 +01:00
- name: Pushes littlefs.bin to web flasher
2024-09-03 11:37:34 +02:00
if: github.event_name == 'push' && github.ref == 'refs/heads/main'
2023-11-25 22:56:20 +01:00
id: push_directory
uses: cpina/github-action-push-to-another-repository@main
env:
SSH_DEPLOY_KEY: ${{ secrets.SSH_DEPLOY_KEY }}
with:
source-directory: output/
target-directory: webui/
destination-github-username: 'btclock'
destination-repository-name: 'web-flasher'
2024-06-29 16:39:43 +02:00
target-branch: main
2023-11-25 22:56:20 +01:00
user-name: ${{github.actor}}
user-email: ${{github.actor}}@users.noreply.github.com