[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[nongnu] elpa/request d00e522 4/5: makes test and github actions
From: |
ELPA Syncer |
Subject: |
[nongnu] elpa/request d00e522 4/5: makes test and github actions |
Date: |
Fri, 12 Feb 2021 00:57:09 -0500 (EST) |
branch: elpa/request
commit d00e522252f0f8405308844c30b4c8d708e22d8d
Author: dickmao <none>
Commit: dickmao <none>
makes test and github actions
---
.github/workflows/test.yml | 102 +++++++++++++++++++++++++++
.travis.yml | 60 ----------------
Makefile | 78 ++++++++++++---------
request.el | 167 ++++++++++++++++-----------------------------
tests/test-request.el | 2 +-
tools/recipe | 1 +
6 files changed, 205 insertions(+), 205 deletions(-)
diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml
new file mode 100644
index 0000000..62e2690
--- /dev/null
+++ b/.github/workflows/test.yml
@@ -0,0 +1,102 @@
+name: CI
+
+on:
+ pull_request:
+ paths-ignore:
+ - '**.md'
+ - '**.markdown'
+ push:
+ paths-ignore:
+ - '**.md'
+ branches-ignore:
+ - 'master'
+ - 'main'
+
+jobs:
+ build:
+ runs-on: ${{ matrix.os }}
+ strategy:
+ matrix:
+ os: [ubuntu-latest, macos-latest]
+ emacs_version: [24.5, 25.3, 26.3, 27.1]
+ python_version: [2.7]
+
+ steps:
+ - uses: actions/checkout@v1
+
+ - uses: actions/setup-python@v1
+ with:
+ python-version: ${{ matrix.python_version }}
+
+ - uses: purcell/setup-emacs@master
+ with:
+ version: ${{ matrix.emacs_version }}
+
+ - uses: actions/cache@v1
+ if: startsWith(runner.os, 'Linux')
+ with:
+ path: ~/.cache/pip
+ key: ${{ runner.os }}-pip-000
+
+ - uses: actions/cache@v1
+ if: startsWith(runner.os, 'macOS')
+ with:
+ path: ~/Library/Caches/pip
+ key: ${{ runner.os }}-pip-000
+
+ - uses: actions/cache@v1
+ with:
+ path: ~/local
+ key: ${{ runner.os }}-local-000
+
+ - uses: actions/cache@v1
+ with:
+ path: ~/.emacs.d
+ key: emacs.d
+
+ - uses: actions/cache@v1
+ with:
+ path: ~/.cask
+ key: cask-000
+
+ - name: paths
+ run: |
+ echo "$HOME/local/bin" >> $GITHUB_PATH
+ echo "$HOME/local/cask/bin" >> $GITHUB_PATH
+ echo "$HOME/.local/bin" >> $GITHUB_PATH
+ echo "LD_LIBRARY_PATH=$HOME/.local/lib" >> $GITHUB_ENV
+
+ - name: apt-get
+ if: startsWith(runner.os, 'Linux')
+ run: |
+ sudo apt-get -yq update
+ DEBIAN_FRONTEND=noninteractive sudo apt-get -yq install gnutls-bin
sharutils gnupg2 dirmngr libreadline-dev libcurl4-openssl-dev virtualenv
+
+ - name: gnupg
+ if: startsWith(runner.os, 'macOS')
+ run: brew list gnupg &>/dev/null || HOMEBREW_NO_AUTO_UPDATE=1 brew
install gnupg
+
+ - name: dependencies
+ run: |
+ pip install yq setuptools wheel
+ pip install Flask==1.0.2 tornado==5.1.1
+ pip uninstall -y Werkzeug
+ pip install Werkzeug==0.14.1
+
+ - name: versions
+ run: |
+ curl --version
+ emacs --version
+ gpg --version
+ python --version
+
+ - name: cask
+ run: |
+ sh tools/install-cask.sh
+ cask link list
+
+ - name: test
+ run: |
+ make test-install
+ make test
+ continue-on-error: ${{ matrix.emacs_version == 'snapshot' }}
diff --git a/.travis.yml b/.travis.yml
deleted file mode 100644
index 67e1765..0000000
--- a/.travis.yml
+++ /dev/null
@@ -1,60 +0,0 @@
-language: python
-python: 2.7
-dist: trusty
-sudo: false
-
-addons:
- apt:
- packages:
- - gnutls-bin
- - sharutils
- - git
- - gnupg2
-
-cache:
- directories:
- - $HOME/nix.store
- - $HOME/local
- - $HOME/.cask
- - $HOME/node_modules
- - $HOME/.cache/pip
- - $HOME/.evm
- - $HOME/.emacs.d
- - $HOME/Library/Caches/Homebrew
- - $HOME/.pyenv
- - $HOME/Library/Caches/pip
-
-env:
- global:
- - PATH=$HOME/local/bin:$HOME/local/evm/bin:$HOME/local/cask/bin:$PATH
-
-matrix:
- include:
- - env: EVM_EMACS=emacs-24.4-travis
- - env: EVM_EMACS=emacs-24.5-travis
- - env: EVM_EMACS=emacs-25.1-travis
- - env: EVM_EMACS=emacs-25.2-travis
- - env: EVM_EMACS=emacs-25.3-travis
- - env: EVM_EMACS=emacs-26.1-travis
- - env: EVM_EMACS=emacs-26.2-travis
- - env: EVM_EMACS=emacs-26.3-travis
- - env: EVM_EMACS=emacs-git-snapshot-travis
-
- allow_failures:
- - env: EVM_EMACS=emacs-git-snapshot-travis
-
-before_install:
- - pip install -q Flask==1.0.2 tornado==5.1.1
- - pip uninstall -y Werkzeug
- - pip install -q Werkzeug==0.14.1
- - sh tools/install-evm.sh
- - evm config path /tmp
- - evm install $EVM_EMACS --use --skip
- - sh tools/install-cask.sh
- - cask --version
- - emacs --version
- - curl --version
-
-script:
- - make test-install
- - make test
diff --git a/Makefile b/Makefile
index 67f38d1..0a29ad0 100644
--- a/Makefile
+++ b/Makefile
@@ -3,22 +3,6 @@ export EMACS ?= $(shell which emacs)
export CASK_DIR := $(shell EMACS=$(EMACS) $(CASK) package-directory)
PKBUILD=2.3
-ifeq ($(TRAVIS_PULL_REQUEST_BRANCH),)
-TRAVIS_PULL_REQUEST_BRANCH := $(shell git rev-parse --abbrev-ref HEAD)
-endif
-ifeq ($(TRAVIS_PULL_REQUEST_SLUG),)
-ifeq ($(TRAVIS_PULL_REQUEST_BRANCH),HEAD)
-TRAVIS_PULL_REQUEST_SLUG := $(TRAVIS_REPO_SLUG)
-else
-TRAVIS_PULL_REQUEST_SLUG := $(shell git config --global user.name)/$(shell
basename `git rev-parse --show-toplevel`)
-endif
-endif
-ifeq ($(TRAVIS),true)
-ifeq ($(TRAVIS_PULL_REQUEST_SHA),)
-TRAVIS_PULL_REQUEST_SHA := $(shell git rev-parse
origin/$(TRAVIS_PULL_REQUEST_BRANCH))
-endif
-endif
-
TESTSSRC = $(shell ls tests/*.el)
ELCTESTS = $(TESTSSRC:.el=.elc)
.DEFAULT_GOAL := compile
@@ -69,8 +53,47 @@ clean:
$(CASK) clean-elc
make -C doc clean
+
+.PHONY: dist-clean
+dist-clean:
+ rm -rf dist
+
+.PHONY: dist
+dist: dist-clean
+ $(CASK) package
+
+.PHONY: install
+install: compile dist
+ $(EMACS) -Q --batch --eval "(package-initialize)" \
+ --eval "(package-install-file \"dist/request-$(shell $(CASK)
version).tar\")"
+
+define SET_GITHUB_REPOSITORY =
+ifeq ($(GITHUB_REPOSITORY),)
+ GITHUB_REPOSITORY := $(shell git config user.name)/$(shell basename
`git rev-parse --show-toplevel`)
+endif
+endef
+
+define SET_GITHUB_HEAD_REF =
+ifeq ($(GITHUB_HEAD_REF),)
+GITHUB_HEAD_REF := $(shell git rev-parse --abbrev-ref HEAD)
+endif
+endef
+
+define SET_GITHUB_SHA =
+ifeq ($(GITHUB_SHA),)
+GITHUB_SHA := $(shell if git show-ref --quiet --verify
origin/$(GITHUB_HEAD_REF) ; then git rev-parse origin/$(GITHUB_HEAD_REF) ; fi)
+endif
+endef
+
+.PHONY: test-install-vars
+test-install-vars:
+ $(eval $(call SET_GITHUB_REPOSITORY))
+ $(eval $(call SET_GITHUB_HEAD_REF))
+ $(eval $(call SET_GITHUB_SHA))
+ @true
+
.PHONY: test-install
-test-install:
+test-install: test-install-vars
mkdir -p tests/test-install
if [ ! -s "tests/test-install/$(PKBUILD).tar.gz" ] ; then \
cd tests/test-install ; curl -sLOk
https://github.com/melpa/package-build/archive/$(PKBUILD).tar.gz ; fi
@@ -88,24 +111,11 @@ test-install:
--eval "(setq rcp (package-recipe-lookup \"request\"))" \
--eval "(unless (file-exists-p package-build-archive-dir) \
(make-directory package-build-archive-dir))" \
- --eval "(let* ((my-repo \"$(TRAVIS_PULL_REQUEST_SLUG)\") \
- (my-branch \"$(TRAVIS_PULL_REQUEST_BRANCH)\") \
- (my-commit \"$(TRAVIS_PULL_REQUEST_SHA)\")) \
+ --eval "(let* ((my-repo \"$(GITHUB_REPOSITORY)\") \
+ (my-branch \"$(GITHUB_HEAD_REF)\") \
+ (my-commit \"$(GITHUB_SHA)\")) \
(oset rcp :repo my-repo) \
(oset rcp :branch my-branch) \
(oset rcp :commit my-commit))" \
--eval "(package-build--package rcp (package-build--checkout rcp))" \
- --eval "(package-install-file (concat package-build-archive-dir
\"request.el\"))" 2>&1 | egrep -ia "error: |warning: |fatal" )
-
-.PHONY: dist-clean
-dist-clean:
- rm -rf dist
-
-.PHONY: dist
-dist: dist-clean
- $(CASK) package
-
-.PHONY: install
-install: compile dist
- $(EMACS) -Q --batch --eval "(package-initialize)" \
- --eval "(package-install-file \"dist/request-$(shell $(CASK)
version).tar\")"
+ --eval "(package-install-file (car (file-expand-wildcards (concat
package-build-archive-dir \"request*.tar\"))))" 2>&1 | egrep -ia "error:
|fatal" )
diff --git a/request.el b/request.el
index 3b94ce2..25b8008 100644
--- a/request.el
+++ b/request.el
@@ -7,7 +7,7 @@
;; Author: Takafumi Arakaki <aka.tkf at gmail.com>
;; URL: https://github.com/tkf/emacs-request
;; Package-Requires: ((emacs "24.4"))
-;; Version: 0.3.2
+;; Version: 0.3.3
;; This file is NOT part of GNU Emacs.
@@ -56,12 +56,7 @@
:group 'comm
:prefix "request-")
-(defconst request-version "0.3.0")
-
-(defconst request--curl-form-stdin "--data-binary @-")
-
-
-;;; Customize variables
+(defconst request-version "0.3.3")
(defcustom request-storage-directory
(concat (file-name-as-directory user-emacs-directory) "request")
@@ -93,10 +88,7 @@ Automatically set to `curl' if curl command is found."
:type '(choice (integer :tag "Request timeout seconds")
(boolean :tag "No timeout" nil)))
-(defcustom request-temp-prefix "emacs-request"
- "Prefix for temporary files created by Request."
- :type 'string
- :risky t)
+(make-obsolete-variable 'request-temp-prefix nil "0.3.3")
(defcustom request-log-level -1
"Logging level for request.
@@ -244,7 +236,7 @@ for older Emacs versions.")
status-code history data error-thrown symbol-status url
done-p settings
;; internal variables
- -buffer -raw-header -timer -backend -tempfiles)
+ -buffer -raw-header -timer -backend)
(defmacro request--document-response (function docstring)
(declare (indent defun)
@@ -705,12 +697,7 @@ then send to PARSER."
(request-log 'debug "request--callback: executing complete")
(request--safe-apply complete args)))
- (setq done-p t)
-
- ;; Remove temporary files
- ;; FIXME: Make tempfile cleanup more reliable. It is possible
- ;; callback is never called.
- (request--safe-delete-files (request-response--tempfiles response))))
+ (setq done-p t)))
(cl-defun request-response--timeout-callback (response)
(setf (request-response-symbol-status response) 'timeout)
@@ -903,7 +890,7 @@ Currently it is used only for testing.")
(make-directory (file-name-directory (request--curl-cookie-jar)) t)))
(cl-defun request--curl-command
- (url &key type data headers files* unix-socket auth
+ (url &key type data headers files unix-socket auth
&allow-other-keys
&aux (cookie-jar (convert-standard-filename
(expand-file-name (request--curl-cookie-jar)))))
@@ -930,15 +917,34 @@ Currently it is used only for testing.")
request-curl-options
(when (plist-get (request--curl-capabilities) :compression) (list
"--compressed"))
(when unix-socket (list "--unix-socket" unix-socket))
- (cl-loop for (name filename path mime-type) in files*
+ (cl-loop with stdin-p = data
+ for (name . item) in files
collect "--form"
- collect (format "%s=@%s;filename=%s%s" name
- (request-untrampify-filename path) filename
- (if mime-type
- (format ";type=%s" mime-type)
- "")))
+ collect
+ (apply #'format "%s=@%s;filename=%s%s"
+ (cond ((stringp item)
+ (list name item (file-name-nondirectory item) ""))
+ ((bufferp item)
+ (if stdin-p
+ (error (concat "request--curl-command: "
+ "only one buffer or data entry
permitted"))
+ (setq stdin-p t))
+ (list name "-" (buffer-name item) ""))
+ ((listp item)
+ (unless (plist-get (cdr item) :file)
+ (if stdin-p
+ (error (concat "request--curl-command: "
+ "only one buffer or data entry
permitted"))
+ (setq stdin-p t)))
+ (list name (or (plist-get (cdr item) :file) "-")
(car item)
+ (if (plist-get item :mime-type)
+ (format ";type=%s" (plist-get item
:mime-type))
+ "")))
+ (t (error (concat "request--curl-command: "
+ "%S not string, buffer, or list")
+ item)))))
(when data
- (split-string request--curl-form-stdin))
+ (split-string "--data-binary @-"))
(when type (if (equal "head" (downcase type))
(list "--head")
(list "--request" type)))
@@ -947,74 +953,6 @@ Currently it is used only for testing.")
collect (format "%s: %s" k v))
(list url)))
-(defun request--curl-normalize-files-1 (files get-temp-file)
- (cl-loop for (name . item) in files
- collect
- (cl-destructuring-bind
- (filename &key file buffer data mime-type)
- (cond
- ((stringp item) (list (file-name-nondirectory item) :file
item))
- ((bufferp item) (list (buffer-name item) :buffer item))
- (t item))
- (unless (= (cl-loop for v in (list file buffer data) if v sum 1)
1)
- (error "Only one of :file/:buffer/:data must be given. Got: %S"
- (cons name item)))
- (cond
- (file
- (list name filename file mime-type))
- (buffer
- (let ((tf (funcall get-temp-file)))
- (with-current-buffer buffer
- (write-region (point-min) (point-max) tf nil 'silent))
- (list name filename tf mime-type)))
- (data
- (let ((tf (funcall get-temp-file)))
- (with-temp-buffer
- (erase-buffer)
- (insert data)
- (write-region (point-min) (point-max) tf nil 'silent))
- (list name filename tf mime-type)))))))
-
-
-(declare-function tramp-get-remote-tmpdir "tramp")
-(declare-function tramp-dissect-file-name "tramp")
-
-(defun request--make-temp-file ()
- "Create a temporary file."
- (if (file-remote-p default-directory)
- (let ((temporary-file-directory
- (tramp-get-remote-tmpdir (tramp-dissect-file-name
default-directory))))
- (make-temp-file request-temp-prefix))
- (make-temp-file request-temp-prefix)))
-
-(defun request--curl-normalize-files (files)
- "Change FILES into a list of (NAME FILENAME PATH MIME-TYPE).
-This is to make `request--curl-command' cleaner by converting
-FILES to a homogeneous list. It returns a list (FILES* TEMPFILES)
-where FILES* is a converted FILES and TEMPFILES is a list of
-temporary file paths."
- (let (tempfiles noerror)
- (unwind-protect
- (let* ((get-temp-file (lambda ()
- (let ((tf (request--make-temp-file)))
- (push tf tempfiles)
- tf)))
- (files* (request--curl-normalize-files-1 files get-temp-file)))
- (setq noerror t)
- (list files* tempfiles))
- (unless noerror
- ;; Remove temporary files only when an error occurs
- (request--safe-delete-files tempfiles)))))
-
-(defun request--safe-delete-files (files)
- "Remove FILES but do not raise error when failed to do so."
- (mapc (lambda (f) (condition-case err
- (delete-file f)
- (error (request-log 'error
- "request--safe-delete-files: %s %s"
- f (error-message-string err)))))
- files))
-
(defun request--install-timeout (timeout response)
"Out-of-band trigger after TIMEOUT seconds to prevent hangs."
(when (numberp timeout)
@@ -1049,20 +987,25 @@ Sexp at the end of buffer and extra headers for
redirects are
removed from the buffer before it is shown to the parser function.
"
(request--curl-mkdir-for-cookie-jar)
- (let* (;; Use pipe instead of pty. Otherwise, curl process hangs.
- (process-connection-type nil)
- ;; Avoid starting program in non-existing directory.
+ (let* (process-connection-type ;; pipe, not pty, else curl hangs
(home-directory (or (file-remote-p default-directory) "~/"))
(default-directory (expand-file-name home-directory))
(buffer (generate-new-buffer " *request curl*"))
- (command (cl-destructuring-bind
- (files* tempfiles)
- (request--curl-normalize-files files)
- (setf (request-response--tempfiles response) tempfiles)
- (apply #'request--curl-command url :files* files*
- :response response :encoding encoding settings)))
+ (command (apply #'request--curl-command url settings))
(proc (apply #'start-process "request curl" buffer command))
- (scommand (mapconcat 'identity command " ")))
+ (scommand (mapconcat 'identity command " "))
+ (file-items (mapcar #'cdr files))
+ (file-buffer (or (cl-some (lambda (item)
+ (when (bufferp item) item))
+ file-items)
+ (cl-some (lambda (item)
+ (and (listp item)
+ (plist-get (cdr item) :buffer)))
+ file-items)))
+ (file-data (cl-some (lambda (item)
+ (and (listp item)
+ (plist-get (cdr item) :data)))
+ file-items)))
(request--install-timeout timeout response)
(request-log 'debug "request--curl: %s"
(request--curl-occlude-secret scommand))
@@ -1070,21 +1013,25 @@ removed from the buffer before it is shown to the
parser function.
(process-put proc :request-response response)
(set-process-coding-system proc 'no-conversion 'no-conversion)
(set-process-query-on-exit-flag proc nil)
- (when (and data (cl-search request--curl-form-stdin scommand))
+ (when (or data file-buffer file-data)
;; We dynamic-let the global `buffer-file-coding-system' to
`no-conversion'
;; in case the user-configured `encoding' doesn't fly.
;; If we do not dynamic-let the global, `select-safe-coding-system' would
;; plunge us into an undesirable interactive dialogue.
- (let ((buffer-file-coding-system-orig
- (default-value 'buffer-file-coding-system))
- (select-safe-coding-system-accept-default-p
- (lambda (&rest _) t)))
+ (let* ((buffer-file-coding-system-orig
+ (default-value 'buffer-file-coding-system))
+ (select-safe-coding-system-accept-default-p
+ (lambda (&rest _) t)))
(unwind-protect
(progn
(setf (default-value 'buffer-file-coding-system) 'no-conversion)
(with-temp-buffer
(setq-local buffer-file-coding-system encoding)
- (save-excursion (insert data))
+ (insert (or data
+ (when file-buffer
+ (with-current-buffer file-buffer
+ (buffer-substring-no-properties (point-min)
(point-max))))
+ file-data))
(process-send-region proc (point-min) (point-max))
(process-send-eof proc)))
(setf (default-value 'buffer-file-coding-system)
diff --git a/tests/test-request.el b/tests/test-request.el
index f1c6201..9d9ab9c 100644
--- a/tests/test-request.el
+++ b/tests/test-request.el
@@ -631,7 +631,7 @@ based backends (e.g., `curl') should avoid this problem."
(ert-deftest request--file-url ()
"What happens when url is not HTTP."
- (let ((tempfile (request--make-temp-file))
+ (let ((tempfile (make-temp-file "test-request"))
(body "hello, world\r\n")
(utf-8-body "hello, world\n")
(no-conversion-body "hello, world\r\n"))
diff --git a/tools/recipe b/tools/recipe
new file mode 100644
index 0000000..4f4bce4
--- /dev/null
+++ b/tools/recipe
@@ -0,0 +1 @@
+(request :repo "tkf/emacs-request" :fetcher github :files ("request.el"))