forked from clan/clan-core
Added assets CI
This commit is contained in:
parent
93f501bfbe
commit
e6733bcb6b
45
.gitea/workflows/ui_assets.yaml
Normal file
45
.gitea/workflows/ui_assets.yaml
Normal file
@ -0,0 +1,45 @@
|
|||||||
|
name: assets
|
||||||
|
on:
|
||||||
|
pull_request:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- main
|
||||||
|
- Qubasa-main
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
runs-on: nix
|
||||||
|
steps:
|
||||||
|
- name: Checkout code
|
||||||
|
uses: actions/checkout@v3
|
||||||
|
|
||||||
|
- name: Get changed files using defaults
|
||||||
|
id: changed-files
|
||||||
|
uses: tj-actions/changed-files@v32
|
||||||
|
with:
|
||||||
|
fetch-depth: 2
|
||||||
|
|
||||||
|
- name: Check if UI files are in the list of modified files
|
||||||
|
run: |
|
||||||
|
set -xeuo pipefail
|
||||||
|
echo "Modified files: $MODIFIED_FILES"
|
||||||
|
if echo "$MODIFIED_FILES" | grep -q "pkgs/ui/" \
|
||||||
|
|| echo "$MODIFIED_FILES" | grep -q ".gitea/workflows/ui_assets.yaml"; then
|
||||||
|
|
||||||
|
echo "UI files have changed"
|
||||||
|
./pkgs/ui/nix/update-ui-assets.sh
|
||||||
|
|
||||||
|
|
||||||
|
# git push if we have a diff
|
||||||
|
if [[ -n $(git diff) ]]; then
|
||||||
|
git config --global user.email "ui_assets[bot]@mail.clan.lol"
|
||||||
|
git config --global user.name "ui_assets[bot]"
|
||||||
|
git commit -am "update ui-assets.nix"
|
||||||
|
echo "Current branch: $GITHUB_REF_NAME"
|
||||||
|
git push origin HEAD:$GITHUB_REF_NAME
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
echo "No UI files changed. Skipping asset build and push"
|
||||||
|
fi
|
||||||
|
env:
|
||||||
|
MODIFIED_FILES: ${{ steps.changed-files.outputs.modified_files }}
|
||||||
|
GITEA_TOKEN: ${{ secrets.TEA_TOKEN_QUBASA }}
|
@ -1,5 +1,5 @@
|
|||||||
{ fetchzip }:
|
{ fetchzip }:
|
||||||
fetchzip {
|
fetchzip {
|
||||||
url = "https://git.clan.lol/api/packages/clan/generic/ui/1cf814b4c19a9c30d19061417bc9cb85d7518c0d/assets.tar.gz?token=35dcd15cf8b707f4436a766f955c75a805132ea0";
|
url = "https://git.clan.lol/api/packages/clan/generic/ui/0p4yzm4rj954lfqw3fwd93lijs3658ml2q47f6h1hl9jzsb4hmg3/assets.tar.gz";
|
||||||
sha256 = "18cgzf01f3pw6ck3mllgy6l5szfz0ggiyd42crf02nc66drajzg4";
|
sha256 = "0p4yzm4rj954lfqw3fwd93lijs3658ml2q47f6h1hl9jzsb4hmg3";
|
||||||
}
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
# shellcheck shell=bash
|
# shellcheck shell=bash
|
||||||
|
set -xeuo pipefail
|
||||||
|
|
||||||
# GITEA_TOKEN
|
# GITEA_TOKEN
|
||||||
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
||||||
@ -6,20 +7,37 @@ if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
|||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
sha=$(git rev-parse HEAD)
|
DEPS=$(nix shell --inputs-from '.#' "nixpkgs#gnutar" "nixpkgs#curl" "nixpkgs#gzip" -c bash -c "echo \$PATH")
|
||||||
|
export PATH=$PATH:$DEPS
|
||||||
|
|
||||||
|
|
||||||
PROJECT_DIR=$(git rev-parse --show-toplevel)
|
PROJECT_DIR=$(git rev-parse --show-toplevel)
|
||||||
tmpdir=$(mktemp -d)
|
tmpdir=$(mktemp -d)
|
||||||
cleanup() { rm -rf "$tmpdir"; }
|
cleanup() { rm -rf "$tmpdir"; }
|
||||||
trap cleanup EXIT
|
trap cleanup EXIT
|
||||||
|
|
||||||
nix build '.#ui' --out-link "$tmpdir/result"
|
nix build '.#ui' --out-link "$tmpdir/result"
|
||||||
|
|
||||||
tar --transform 's,^\.,assets,' -czvf "$tmpdir/assets.tar.gz" -C "$tmpdir"/result/lib/node_modules/*/out .
|
tar --transform 's,^\.,assets,' -czvf "$tmpdir/assets.tar.gz" -C "$tmpdir"/result/lib/node_modules/*/out .
|
||||||
url="https://git.clan.lol/api/packages/clan/generic/ui/$sha/assets.tar.gz?token=$GITEA_TOKEN"
|
NAR_HASH=$(nix-prefetch-url --unpack file://<(cat "$tmpdir/assets.tar.gz"))
|
||||||
curl --upload-file "$tmpdir/assets.tar.gz" -X PUT "$url"
|
|
||||||
hash=$(nix-prefetch-url --unpack "$url")
|
|
||||||
|
url="https://git.clan.lol/api/packages/clan/generic/ui/$NAR_HASH/assets.tar.gz"
|
||||||
|
curl -v --upload-file "$tmpdir/assets.tar.gz" -X PUT "$url?token=$GITEA_TOKEN"
|
||||||
|
|
||||||
|
TEST_URL=$(nix-prefetch-url --unpack "$url")
|
||||||
|
if [[ $TEST_URL != "$NAR_HASH" ]]; then
|
||||||
|
echo "Prefetch failed. Expected $NAR_HASH, got $TEST_URL"
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
cat > "$PROJECT_DIR/pkgs/ui/nix/ui-assets.nix" <<EOF
|
cat > "$PROJECT_DIR/pkgs/ui/nix/ui-assets.nix" <<EOF
|
||||||
{ fetchzip }:
|
{ fetchzip }:
|
||||||
fetchzip {
|
fetchzip {
|
||||||
url = "$url";
|
url = "$url";
|
||||||
sha256 = "$hash";
|
sha256 = "$NAR_HASH";
|
||||||
}
|
}
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user