-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathtest-hdl-setup-straight.el
93 lines (71 loc) · 3.4 KB
/
test-hdl-setup-straight.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
;;; test-hdl-setup-straight.el --- straight.el common setup for tests-*- lexical-binding: t -*-
;; Copyright (C) 2022-2024 Gonzalo Larumbe
;; Author: Gonzalo Larumbe <gonzalomlarumbe@gmail.com>
;; URL: https://github.com/gmlarumbe/test-hdl
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; straight.el common setup for tests
;;
;;; Code:
;; Straight bootstrap
(message "Bootstraping straight")
(defvar bootstrap-version)
(let ((bootstrap-file
(expand-file-name
"straight/repos/straight.el/bootstrap.el"
(or (bound-and-true-p straight-base-dir)
user-emacs-directory)))
(bootstrap-version 7))
(unless (file-exists-p bootstrap-file)
(with-current-buffer
(url-retrieve-synchronously
"https://raw.githubusercontent.com/radian-software/straight.el/develop/install.el"
'silent 'inhibit-cookies)
(goto-char (point-max))
(eval-print-last-sexp)))
(load bootstrap-file nil 'nomessage))
(message "Bootstraped straight")
;; Integration of use-package
(message "Installing use-package")
(straight-use-package 'use-package)
(setq straight-use-package-by-default t)
;; Force re-download and use of new/clean straight directory inside /tmp/ (or equivalent)
(when (getenv "TESTS_CLEAN_ENV")
(let ((dir (file-name-concat temporary-file-directory (make-temp-name "straight-"))))
(if (file-exists-p dir)
(error "File already exists: %s" dir)
(message "Using `straight-base-dir': %s" dir)
(make-directory dir :parents))
(setq straight-base-dir dir)))
(defmacro test-hdl-when-github-action (&rest body)
"BODY should be a use-package form with :straight nil clause.
This is done in order to shadow fresh downloaded repos by straight.el with local
repos with or without changes.
This is needed in GitHub Actions since the correct revision of the repo is
downloaded by actions/checkout, for PRs and pushes to specific branches.
Otherwise the wrong version in master/main from MELPA recipe would be always
used with straight."
(declare (indent 0) (debug t))
`(when (getenv "GITHUB_ACTION")
;; For GitHub Actions use checked out repo instead of downloading one new with straight
(message "Env var GITHUB_ACTION set, using already checked out repo...")
(message "GITHUB_REPOSITORY = %s" (getenv "GITHUB_REPOSITORY"))
(message "GITHUB_REF = %s" (getenv "GITHUB_REF"))
(message "GITHUB_REF_NAME = %s" (getenv "GITHUB_REF_NAME"))
(message "Testing on branch: %s\n" (car (split-string (shell-command-to-string "git rev-parse --abbrev-ref HEAD") "\n")))
;; Build current directory instead of downloaded copy
;; This will automatically set the host and branch for pull requests
(add-to-list 'load-path default-directory)
,@body))
(provide 'test-hdl-setup-straight)
;;; test-hdl-setup-straight.el ends here