Add forgejo build workflow
This commit is contained in:
parent
21e8c4b334
commit
8332fec4a1
1 changed files with 116 additions and 0 deletions
116
.forgejo/workflows/build.yaml
Normal file
116
.forgejo/workflows/build.yaml
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
name: WebUI CI
|
||||||
|
|
||||||
|
on: [push]
|
||||||
|
|
||||||
|
env:
|
||||||
|
PUBLIC_BASE_URL: ''
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
- 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: docker
|
||||||
|
container:
|
||||||
|
image: ghcr.io/catthehacker/ubuntu:js-22.04
|
||||||
|
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@v3
|
||||||
|
with:
|
||||||
|
node-version: lts/*
|
||||||
|
cache: yarn
|
||||||
|
cache-dependency-path: '**/yarn.lock'
|
||||||
|
- uses: actions/cache@v3
|
||||||
|
with:
|
||||||
|
path: |
|
||||||
|
~/.cache/pip
|
||||||
|
~/node_modules
|
||||||
|
key: ${{ runner.os }}-pio
|
||||||
|
- uses: actions/setup-python@v4
|
||||||
|
with:
|
||||||
|
python-version: '>=3.10'
|
||||||
|
- 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: 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: |
|
||||||
|
THRESHOLD=409600
|
||||||
|
DIRECTORY_SIZE=$(du -b -s build_gz | awk '{print $1}')
|
||||||
|
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"
|
||||||
|
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: https://code.forgejo.org/forgejo/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: '${{ github.repository }}'
|
||||||
|
direction: upload
|
||||||
|
tag: ${{ steps.getBlockHeight.outputs.blockHeight }}
|
||||||
|
sha: '${{ github.sha }}'
|
||||||
|
release-dir: output
|
||||||
|
token: ${{ secrets.TOKEN }}
|
||||||
|
override: false
|
||||||
|
verbose: false
|
||||||
|
release-notes-assistant: false
|
Loading…
Reference in a new issue