forked from clan/clan-core
Merge pull request 'Added assets CI' (#284) from Qubasa-main into main
Reviewed-on: clan/clan-core#284
This commit is contained in:
commit
e8e5375600
44
.gitea/workflows/ui_assets.yaml
Normal file
44
.gitea/workflows/ui_assets.yaml
Normal file
@ -0,0 +1,44 @@
|
||||
name: assets
|
||||
on:
|
||||
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 {
|
||||
url = "https://git.clan.lol/api/packages/clan/generic/ui/1cf814b4c19a9c30d19061417bc9cb85d7518c0d/assets.tar.gz?token=35dcd15cf8b707f4436a766f955c75a805132ea0";
|
||||
sha256 = "18cgzf01f3pw6ck3mllgy6l5szfz0ggiyd42crf02nc66drajzg4";
|
||||
url = "https://git.clan.lol/api/packages/clan/generic/ui/1w5dz4lmk0xm0cvz9g07a9i1xdjj8pfj486s9w0a0qd4s3jj3rpr/assets.tar.gz";
|
||||
sha256 = "1w5dz4lmk0xm0cvz9g07a9i1xdjj8pfj486s9w0a0qd4s3jj3rpr";
|
||||
}
|
||||
|
@ -1,4 +1,5 @@
|
||||
# shellcheck shell=bash
|
||||
set -xeuo pipefail
|
||||
|
||||
# GITEA_TOKEN
|
||||
if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
||||
@ -6,20 +7,37 @@ if [[ -z "${GITEA_TOKEN:-}" ]]; then
|
||||
exit 1
|
||||
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)
|
||||
tmpdir=$(mktemp -d)
|
||||
cleanup() { rm -rf "$tmpdir"; }
|
||||
trap cleanup EXIT
|
||||
|
||||
nix build '.#ui' --out-link "$tmpdir/result"
|
||||
|
||||
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"
|
||||
curl --upload-file "$tmpdir/assets.tar.gz" -X PUT "$url"
|
||||
hash=$(nix-prefetch-url --unpack "$url")
|
||||
NAR_HASH=$(nix-prefetch-url --unpack file://<(cat "$tmpdir/assets.tar.gz"))
|
||||
|
||||
|
||||
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
|
||||
{ fetchzip }:
|
||||
fetchzip {
|
||||
url = "$url";
|
||||
sha256 = "$hash";
|
||||
sha256 = "$NAR_HASH";
|
||||
}
|
||||
EOF
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user