Skip to content

Commit 20c939f

Browse files
authored
Setup deployments on CI (#360)
* Setup deployments on CI * Upgrade Orchard, nrepl, Eastwood * Adapt `make install` task * Discard `release` Make task
1 parent 8bf4724 commit 20c939f

File tree

9 files changed

+125
-45
lines changed

9 files changed

+125
-45
lines changed

.circleci/config.yml

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,20 +21,34 @@ executors:
2121
LEIN_ROOT: "true" # we intended to run lein as root
2222
JVM_OPTS: -Xmx3200m # limit the maximum heap size to prevent out of memory errors
2323
<<: *defaults
24+
25+
# JDK 8 is preferred for deployments (https://github.com/benedekfazekas/mranderson/issues/57)
26+
# Parallelism is disabled, at least for now (https://github.com/benedekfazekas/mranderson/issues/56)
27+
openjdk8_deploy:
28+
docker:
29+
- image: circleci/clojure:openjdk-8-lein-2.9.1-node
30+
environment:
31+
LEIN_ROOT: "true" # we intended to run lein as root
32+
LEIN_JVM_OPTS: -Dmranderson.internal.no-parallelism=true
33+
JVM_OPTS: -Xmx3200m # limit the maximum heap size to prevent out of memory errors
34+
<<: *defaults
35+
2436
openjdk11:
2537
docker:
2638
- image: circleci/clojure:openjdk-11-lein-2.9.3-buster-node
2739
environment:
2840
LEIN_ROOT: "true" # we intended to run lein as root
2941
JVM_OPTS: -Xmx3200m --illegal-access=deny # forbid reflective access (this flag doesn't exist for JDK8 or JDK17+)
3042
<<: *defaults
43+
3144
openjdk16:
3245
docker:
3346
- image: circleci/clojure:openjdk-16-lein-2.9.5-buster-node
3447
environment:
3548
LEIN_ROOT: "true" # we intended to run lein as root
3649
JVM_OPTS: -Xmx3200m --illegal-access=deny # forbid reflective access (this flag doesn't exist for JDK8 or JDK17+)
3750
<<: *defaults
51+
3852
openjdk17:
3953
docker:
4054
- image: circleci/clojure:openjdk-17-lein-2.9.5-buster-node
@@ -112,6 +126,24 @@ jobs:
112126
cache_version: "1.10"
113127
steps: << parameters.steps >>
114128

129+
deploy:
130+
executor: openjdk8_deploy
131+
steps:
132+
- checkout
133+
- restore_cache:
134+
keys:
135+
- v2-dependencies-{{ checksum "project.clj" }}
136+
# fallback to using the latest cache if no exact match is found
137+
- v2-dependencies-
138+
- run: lein with-profile -user,+test deps
139+
- save_cache:
140+
paths:
141+
- ~/.m2
142+
key: v2-dependencies-{{ checksum "project.clj" }}
143+
- run:
144+
name: Deploy
145+
command: |
146+
lein with-profile -user,+deploy run -m deploy-relase make deploy
115147
116148
test_code:
117149
description: |
@@ -165,8 +197,18 @@ workflows:
165197
parameters:
166198
clojure_version: ["1.8", "1.9", "1.10", "master"]
167199
jdk_version: [openjdk8, openjdk11, openjdk16, openjdk17]
200+
filters:
201+
branches:
202+
only: /.*/
203+
tags:
204+
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
168205
- util_job:
169206
name: Code Linting
207+
filters:
208+
branches:
209+
only: /.*/
210+
tags:
211+
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
170212
steps:
171213
- run:
172214
name: Running cljfmt
@@ -180,3 +222,12 @@ workflows:
180222
name: Running Eastwood
181223
command: |
182224
make eastwood
225+
- deploy:
226+
requires:
227+
- test_code
228+
- "Code Linting"
229+
filters:
230+
branches:
231+
ignore: /.*/
232+
tags:
233+
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/

.circleci/deploy/deploy_release.clj

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
(ns deploy-release
2+
(:require
3+
[clojure.java.io :as io]
4+
[clojure.java.shell :refer [sh]]
5+
[clojure.string :as str]))
6+
7+
(def release-marker "v")
8+
9+
(defn make-version [tag]
10+
(str/replace-first tag release-marker ""))
11+
12+
(defn log-result [m]
13+
(println m)
14+
m)
15+
16+
(defn -main [& _]
17+
(let [tag (System/getenv "CIRCLE_TAG")]
18+
(if-not tag
19+
(System/exit 1)
20+
(if-not (re-find (re-pattern release-marker) tag)
21+
(System/exit 1)
22+
(let [version (make-version tag)]
23+
(spit (io/file "resources" "refactor_nrepl" "version.edn")
24+
(pr-str version))
25+
(apply println "Executing" *command-line-args*)
26+
(->> [:env (assoc (into {} (System/getenv))
27+
"PROJECT_VERSION" (make-version tag))]
28+
(into (vec *command-line-args*))
29+
(apply sh)
30+
log-result
31+
:exit
32+
(System/exit)))))))

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
## Unreleased
44

5+
## 3.2.1 (2022-01-21)
6+
7+
* Upgrade Orchard.
8+
59
## 3.2.0 (2022-01-09)
610

711
### Changes

Makefile

Lines changed: 13 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
.PHONY: inline-deps test release deploy clean
1+
.PHONY: inline-deps test deploy clean
22

33
VERSION ?= 1.10
44

@@ -30,30 +30,18 @@ eastwood:
3030
kondo:
3131
lein with-profile -dev,+$(VERSION),+clj-kondo run -m clj-kondo.main --lint src test
3232

33-
# When releasing, the BUMP variable controls which field in the
34-
# version string will be incremented in the *next* snapshot
35-
# version. Typically this is either "major", "minor", or "patch".
3633

37-
BUMP ?= patch
38-
39-
release:
40-
lein with-profile -user,+$(VERSION) release $(BUMP)
41-
42-
# Deploying requires the caller to set environment variables as
43-
# specified in project.clj to provide a login and password to the
44-
# artifact repository.
45-
46-
# GIT_TAG=v3.2.0 CLOJARS_USERNAME=$USER CLOJARS_PASSWORD=$(pbpaste) make deploy
34+
# Deployment is performed via CI by creating a git tag prefixed with "v".
35+
# Please do not deploy locally as it skips various measures (particularly around mranderson).
4736
deploy: check-env .inline-deps
4837
lein with-profile -user,+$(VERSION),+plugin.mranderson/config deploy clojars
49-
git tag -a "$$GIT_TAG" -m "$$GIT_TAG"
50-
git push
51-
git push --tags
5238

5339
jar: .inline-deps
5440
lein with-profile -user,+$(VERSION),+plugin.mranderson/config jar
5541

56-
install: .inline-deps
42+
# Usage: PROJECT_VERSION=3.2.1 make install
43+
# PROJECT_VERSION is needed because it's not computed dynamically
44+
install: check-install-env .inline-deps
5745
lein with-profile -user,+$(VERSION),+plugin.mranderson/config install
5846

5947
check-env:
@@ -63,6 +51,11 @@ endif
6351
ifndef CLOJARS_PASSWORD
6452
$(error CLOJARS_PASSWORD is undefined)
6553
endif
66-
ifndef GIT_TAG
67-
$(error GIT_TAG is undefined)
54+
ifndef CIRCLE_TAG
55+
$(error CIRCLE_TAG is undefined)
56+
endif
57+
58+
check-install-env:
59+
ifndef PROJECT_VERSION
60+
$(error Please set PROJECT_VERSION as an env var beforehand.)
6861
endif

README.md

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ Be aware that this isn't the case if you connect to an already running REPL proc
2525
Add the following, either in your project's `project.clj`, or in the `:user` profile found at `~/.lein/profiles.clj`:
2626

2727
```clojure
28-
:plugins [[refactor-nrepl "3.2.0"]
28+
:plugins [[refactor-nrepl "3.2.1"]
2929
[cider/cider-nrepl "0.25.9"]]
3030
```
3131

@@ -37,7 +37,7 @@ Add the following in `~/.boot/profile.boot`:
3737
(require 'boot.repl)
3838

3939
(swap! boot.repl/*default-dependencies* conj
40-
'[refactor-nrepl "3.2.0"]
40+
'[refactor-nrepl "3.2.1"]
4141
'[cider/cider-nrepl "0.25.9"])
4242

4343
(swap! boot.repl/*default-middleware* conj
@@ -370,21 +370,14 @@ If you want to use `mranderson` while developing locally with the REPL, the sour
370370

371371
When you want to release locally to the following:
372372

373-
lein with-profile plugin.mranderson/config install
373+
PROJECT_VERSION=3.2.1 make install
374374

375375
And here's how to deploy to Clojars:
376376

377-
lein with-profile plugin.mranderson/config deploy clojars
378-
379-
Alternatively you can leverage the bundled `Makefile`:
380-
381-
make install
382-
make deploy
383-
384-
You might also want to do a `make test` prior to deploying anything to Clojars.
385-
386-
**Note:** You'll need to run `make clean test` if you changed any of the project's dependencies,
387-
as those will need to be inlined first.
377+
```bash
378+
git tag -a v3.2.1 -m "3.2.1"
379+
git push --tags
380+
```
388381

389382
## Changelog
390383

project.clj

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,19 @@
1-
(defproject refactor-nrepl "3.2.0"
1+
;; PROJECT_VERSION is set by .circleci/deploy/deploy_release.clj,
2+
;; whenever we perform a deployment.
3+
(defproject refactor-nrepl (or (not-empty (System/getenv "PROJECT_VERSION"))
4+
"0.0.0")
25
:description "nREPL middleware to support editor-agnostic refactoring"
36
:url "https://github.com/clojure-emacs/refactor-nrepl"
47
:license {:name "Eclipse Public License"
58
:url "https://www.eclipse.org/legal/epl-v10.html"}
6-
:dependencies [[nrepl "0.9.0-beta3"]
9+
:dependencies [[nrepl "0.9.0"]
710
^:inline-dep [compliment "0.3.12"]
811
^:inline-dep [http-kit "2.5.3"]
912
^:inline-dep [org.clojure/data.json "2.3.1"]
1013
^:inline-dep [org.clojure/tools.analyzer.jvm "1.2.2"]
1114
^:inline-dep [org.clojure/tools.namespace "1.1.0" :exclusions [org.clojure/tools.reader]]
1215
^:inline-dep [org.clojure/tools.reader "1.3.6"]
13-
^:inline-dep [cider/orchard "0.8.0"]
16+
^:inline-dep [cider/orchard "0.9.1"]
1417
^:inline-dep [cljfmt "0.8.0" :exclusions [rewrite-clj rewrite-cljs]]
1518
^:inline-dep [clj-commons/fs "1.6.310"]
1619
^:inline-dep [rewrite-clj "1.0.699-alpha"]
@@ -25,7 +28,7 @@
2528
:username :env/clojars_username
2629
:password :env/clojars_password
2730
:sign-releases false}]]
28-
:plugins [[thomasa/mranderson "0.5.3"]]
31+
:plugins [[thomasa/mranderson "0.5.4-SNAPSHOT"]]
2932
:mranderson {:project-prefix "refactor-nrepl.inlined-deps"
3033
:expositions [[org.clojure/tools.analyzer.jvm org.clojure/tools.analyzer]]
3134
:unresolved-tree false}
@@ -66,15 +69,17 @@
6669
with-debug-bindings [[:inner 0]]
6770
merge-meta [[:inner 0]]
6871
try-if-let [[:block 1]]}}}]
69-
:eastwood {:plugins [[jonase/eastwood "1.1.0"]]
72+
:eastwood {:plugins [[jonase/eastwood "1.1.1"]]
7073
:eastwood {;; :implicit-dependencies would fail spuriously when the CI matrix runs for Clojure < 1.10,
7174
;; because :implicit-dependencies can only work for a certain corner case starting from 1.10.
7275
:exclude-linters [:implicit-dependencies]
7376
:exclude-namespaces [refactor-nrepl.plugin]
7477
:add-linters [:performance :boxed-math]
7578
:config-files ["eastwood.clj"]}}
7679
:clj-kondo [:test
77-
{:dependencies [[clj-kondo "2021.12.19"]]}]}
80+
{:dependencies [[clj-kondo "2021.12.19"]]}]
81+
82+
:deploy {:source-paths [".circleci/deploy"]}}
7883

7984
:jvm-opts ~(cond-> []
8085
(System/getenv "CI")

resources/refactor_nrepl/version.edn

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
;; This file is automatically overwriten from .circleci/deploy/deploy_release.clj,
2+
;; whenever we perform a deployment.
3+
"0.0.0"

src/refactor_nrepl/core.clj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,10 @@
1717
(require '[me.raynes.fs :as fs])
1818

1919
(defn version []
20-
(let [v (-> (or (io/resource "refactor-nrepl/refactor-nrepl/project.clj")
21-
"project.clj")
20+
(let [v (-> "refactor_nrepl/version.edn"
21+
io/resource
2222
slurp
23-
read-string
24-
(nth 2))]
23+
read-string)]
2524
(assert (string? v)
2625
(str "Something went wrong, version is not a string: "
2726
v))

test/refactor_nrepl/ns/class_search_test.clj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
"jdk."
3131
;; Odd stuff brought in by the `fs` dependency:
3232
"Implementing class"
33-
"class org.apache.commons.compress.harmony.pack200.Segment can not implement org.objectweb.asm.ClassVisitor"])
33+
"org.apache.commons.compress.harmony.pack200.Segment can not implement"])
3434
(do
3535
(.printStackTrace e)
3636
false))

0 commit comments

Comments
 (0)