diff --git a/.forgejo/workflows/ci.yml b/.forgejo/workflows/ci.yml new file mode 100644 index 0000000..c7557e3 --- /dev/null +++ b/.forgejo/workflows/ci.yml @@ -0,0 +1,70 @@ +name: 'CI' + +on: + push: + branches: + - 'main' + pull_request: + +jobs: + test: + runs-on: docker + + strategy: + matrix: + lisp: + - sbcl-bin + + steps: + - uses: actions/checkout@v4 + + - name: Restore cache + id: restore-cache + uses: actions/cache/restore@v4 + with: + path: | + ~/.roswell + /usr/local/bin/ros + /usr/local/etc/roswell/ + qlfile + qlfile.lock + .qlot + ~/.cache/common-lisp/ + key: roswell-${{ runner.os }}-${{ matrix.lisp }}-${{ hashFiles('qlfile', 'qlfile.lock', '*.asd') }} + + - name: Install Roswell + if: steps.restore-cache.outputs.cache-hit != 'true' + env: + LISP: ${{ matrix.lisp }} + run: | + curl -L https://raw.githubusercontent.com/roswell/roswell/master/scripts/install-for-ci.sh | sh + + - name: Install Qlot + if: steps.restore-cache.outputs.cache-hit != 'true' + run: | + ros install fukamachi/qlot + + - name: Install dependencies + if: steps.restore-cache.outputs.cache-hit != 'true' + run: | + PATH="~/.roswell/bin:$PATH" + qlot install + qlot exec ros install ningle-fbr + + - name: Save cache + id: save-cache + uses: actions/cache/save@v4 + if: steps.restore-cache.outputs.cache-hit != 'true' + with: + path: | + ~/.roswell + /usr/local/bin/ros + /usr/local/etc/roswell/ + qlfile + qlfile.lock + .qlot + ~/.cache/common-lisp/ + key: ${{ steps.restore-cache.outputs.cache-primary-key }} + + - name: Run tests + run: .qlot/bin/rove ningle-fbr.asd diff --git a/.github/workflows/test.yml b/.github/workflows/ci.yml similarity index 91% rename from .github/workflows/test.yml rename to .github/workflows/ci.yml index 2c2a54a..a3a8ce0 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/ci.yml @@ -1,4 +1,4 @@ -name: 'test' +name: 'CI' on: push: @@ -7,15 +7,15 @@ on: pull_request: jobs: - tests: + test: runs-on: ubuntu-latest - + strategy: matrix: lisp: - sbcl-bin - ccl-bin - + env: LISP: ${{ matrix.lisp }} diff --git a/LICENSE b/LICENSE index 454f5aa..3fa96da 100644 --- a/LICENSE +++ b/LICENSE @@ -1,6 +1,6 @@ MIT License -Copyright (c) 2024 skyizwhite +Copyright (c) 2024 Akira Tempaku Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/README.md b/README.md index 0b2d284..7e5f4c6 100644 --- a/README.md +++ b/README.md @@ -14,6 +14,8 @@ File-based routing automatically creates URL routes based on a project’s file ## Usage +[Practical usage example](https://github.com/skyizwhite/website) + To use ningle-fbr, set up your project using the [package-inferred-system](https://asdf.common-lisp.dev/asdf/The-package_002dinferred_002dsystem-extension.html) style. **Example directory structure**: @@ -119,4 +121,4 @@ To handle 404 (Not Found) errors, create a special package named `:example/route Licensed under the MIT License. -© 2024, skyizwhite. \ No newline at end of file +© 2024 Akira Tempaku \ No newline at end of file diff --git a/ningle-fbr.asd b/ningle-fbr.asd index a567398..adda2ba 100644 --- a/ningle-fbr.asd +++ b/ningle-fbr.asd @@ -1,10 +1,10 @@ (defsystem "ningle-fbr" - :version "0.1.0" + :version "0.1.2" :description "File-based router for Ningle" :long-description #.(uiop:read-file-string (uiop:subpathname *load-pathname* "README.md")) - :author "skyizwhite" - :maintainer "skyizwhite <paku@skyizwhite.dev>" + :author "Akira Tempaku" + :maintainer "Akira Tempaku <paku@skyizwhite.dev>" :license "MIT" :class :package-inferred-system :pathname "src" diff --git a/qlfile b/qlfile index 548652c..b44b6df 100644 --- a/qlfile +++ b/qlfile @@ -2,5 +2,7 @@ ql ningle ql lack ql cl-ppcre ql alexandria -github rove fukamachi/rove -github dissect shinmera/dissect +ql trivial-system-loader + +git rove https://github.com/fukamachi/rove +git dissect https://github.com/shinmera/dissect diff --git a/qlfile.lock b/qlfile.lock index 003a88d..a25f779 100644 --- a/qlfile.lock +++ b/qlfile.lock @@ -18,11 +18,15 @@ (:class qlot/source/ql:source-ql :initargs (:%version :latest) :version "ql-2024-10-12")) +("trivial-system-loader" . + (:class qlot/source/ql:source-ql + :initargs (:%version :latest) + :version "ql-2024-10-12")) ("rove" . - (:class qlot/source/github:source-github - :initargs (:repos "fukamachi/rove" :ref nil :branch nil :tag nil) - :version "github-cacea7331c10fe9d8398d104b2dfd579bf7ea353")) + (:class qlot/source/git:source-git + :initargs (:remote-url "https://github.com/fukamachi/rove") + :version "git-cacea7331c10fe9d8398d104b2dfd579bf7ea353")) ("dissect" . - (:class qlot/source/github:source-github - :initargs (:repos "shinmera/dissect" :ref nil :branch nil :tag nil) - :version "github-a70cabcd748cf7c041196efd711e2dcca2bbbb2c")) + (:class qlot/source/git:source-git + :initargs (:remote-url "https://github.com/shinmera/dissect") + :version "git-a70cabcd748cf7c041196efd711e2dcca2bbbb2c")) diff --git a/src/router.lisp b/src/router.lisp index 9f974c3..e6ab39a 100644 --- a/src/router.lisp +++ b/src/router.lisp @@ -7,6 +7,10 @@ #:regex-replace #:regex-replace-all) (:import-from #:ningle) + (:import-from #:lack/response + #:response-status) + (:import-from #:trivial-system-loader + #:load-system) (:export #:pathname->path #:path->uri #:path-package @@ -54,10 +58,11 @@ :for path :in (detect-paths system target-dir-path) :for uri := (path->uri path) :for pkg := (path->package path system target-dir-path) - :do (ql:quickload pkg) + :do (load-system pkg) (if (string= uri "/not-found") (let ((handler (find-symbol "HANDLE-NOT-FOUND" pkg))) - (defmethod ningle:not-found ((app ningle:app)) + (defmethod ningle:not-found ((app (eql app))) + (setf (response-status ningle:*response*) 404) (funcall handler)))) (loop :for method :in *http-request-methods* diff --git a/tests/routes/not-found.lisp b/tests/routes/not-found.lisp index 5392fd8..a1b259d 100644 --- a/tests/routes/not-found.lisp +++ b/tests/routes/not-found.lisp @@ -1,11 +1,7 @@ (defpackage #:ningle-fbr-test/routes/not-found (:use #:cl) - (:import-from #:lack/response) - (:import-from #:ningle) (:export #:handle-not-found)) (in-package #:ningle-fbr-test/routes/not-found) (defun handle-not-found () - (setf (lack/response:response-status ningle:*response*) - 404) "Not Found")