From aa651568afa935f942e118a43ee12d015e3ecf1f Mon Sep 17 00:00:00 2001 From: hermes-explorigin Date: Sun, 30 Aug 2026 19:12:19 +0000 Subject: [PATCH] Add CI workflow + baked commit hash - .gitea/workflows/deploy.yml: test+build on every push; auto-deploy dist/index.html to /password_manager via WebDAV on push to main (DELETE- then-PUT to bypass stale-file cache), verifying deployed bytes match. - Build injects __VAULT_COMMIT__ (from VITE_COMMIT_HASH=github.sha in CI, git HEAD locally) and main.js logs console.info({ commit_hash }) on startup so a deploy is verifiable against its source commit. --- .gitea/workflows/deploy.yml | 97 +++++++++++++++++++++++++++++++++++++ dist/index.html | 3 ++ src/main.js | 3 ++ vite.config.js | 16 ++++++ 4 files changed, 119 insertions(+) create mode 100644 .gitea/workflows/deploy.yml diff --git a/.gitea/workflows/deploy.yml b/.gitea/workflows/deploy.yml new file mode 100644 index 0000000..f17aa6f --- /dev/null +++ b/.gitea/workflows/deploy.yml @@ -0,0 +1,97 @@ +name: Test, Build & Deploy + +# Tests + build run on every push/PR; the deploy (WebDAV publish of the +# single-file dist/index.html) runs only on the default branch (main). +"on": + push: + branches: + - '**' + pull_request: + +jobs: + test-and-build: + runs-on: host + steps: + - uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Run tests + run: npm run test:run + + - name: Build (single-file bundle) + env: + VITE_COMMIT_HASH: ${{ github.sha }} + run: npm run build + + - name: Verify build output + run: test -f dist/index.html + + deploy: + # Release the built app only when a commit lands on the default branch. + needs: test-and-build + if: github.ref == 'refs/heads/main' + runs-on: host + steps: + - uses: actions/checkout@v4 + + - name: Setup Node + uses: actions/setup-node@v4 + with: + node-version: '20' + cache: 'npm' + + - name: Install dependencies + run: npm ci + + - name: Build (single-file bundle) + env: + VITE_COMMIT_HASH: ${{ github.sha }} + run: npm run build + + - name: Verify build output + run: test -f dist/index.html + + # Publish dist/index.html to the WebDAV mirror (/password_manager). + # The pretty URL (…/password_manager/index.html) 401s without auth; the + # file is the full www/static/password_manager/index.html with basic auth. + - name: Publish to WebDAV (/password_manager) + env: + WEBDAV_USER: ${{ secrets.WEBDAV_USER }} + WEBDAV_PASS: ${{ secrets.WEBDAV_PASS }} + WEBDAV_URL: https://files.thecookiejar.me/www/static/password_manager/index.html + run: | + if [ -z "$WEBDAV_USER" ] || [ -z "$WEBDAV_PASS" ]; then + echo "::error::WEBDAV_USER / WEBDAV_PASS repo secrets are not set." + echo "::error::Add them under Settings -> Actions -> Secrets, then re-run this job." + exit 1 + fi + # DELETE-then-PUT: the serving layer caches uploaded files, so a plain + # PUT over an existing file returns 201 but keeps serving the OLD copy. + # Deleting first guarantees the new build is actually served. (Each curl + # is a single line -- YAML block scalars don't convert backslash-nl.) + curl -sS -u "$WEBDAV_USER:$WEBDAV_PASS" -X DELETE "$WEBDAV_URL" || echo "(DELETE returned non-zero; file may not exist yet -- continuing)" + curl -sS --fail -u "$WEBDAV_USER:$WEBDAV_PASS" -X PUT -T dist/index.html -H 'Content-Type: text/html' "$WEBDAV_URL" + echo "Published to $WEBDAV_URL" + + # Pull the freshly uploaded file back and compare it to our build, so a + # successful deploy isn't just "curl returned 0" but bytes actually match. + - name: Verify deployed file matches build + env: + WEBDAV_USER: ${{ secrets.WEBDAV_USER }} + WEBDAV_PASS: ${{ secrets.WEBDAV_PASS }} + WEBDAV_URL: https://files.thecookiejar.me/www/static/password_manager/index.html + run: | + curl -sS --fail -u "$WEBDAV_USER:$WEBDAV_PASS" "$WEBDAV_URL" -o /tmp/deployed.html + sha1sum dist/index.html /tmp/deployed.html + test "$(sha1sum dist/index.html | cut -d' ' -f1)" = \ + "$(sha1sum /tmp/deployed.html | cut -d' ' -f1)" \ + && echo "Deploy verified: bytes match" \ + || { echo "::error::Deployed file does not match build"; exit 1; } diff --git a/dist/index.html b/dist/index.html index 4f375ec..dc923bb 100644 --- a/dist/index.html +++ b/dist/index.html @@ -8091,6 +8091,9 @@ function App($$anchor, $$props) { append($$anchor, fragment_1); pop(); } +//#endregion +//#region src/main.js +console.info({ commit_hash: "d72f41418cca3982459ec874565f6671a5620dc6" }); mount(App, { target: document.getElementById("app") }); //#endregion