Skip to content

Commit

Permalink
Setup deployments in CI
Browse files Browse the repository at this point in the history
  • Loading branch information
vemv committed Feb 22, 2022
1 parent cadfe55 commit d202177
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 31 deletions.
31 changes: 29 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@ env_defaults: &env_defaults
LEIN_ROOT: "true" # we intended to run lein as root

jdk8_env_defaults: &jdk8_env_defaults
JVM_OPTS: -Xmx3200m
JVM_OPTS: -Xmx3200m -Dclojure.main.report=stderr

newer_jdk_env_defaults: &newer_jdk_env_defaults
JVM_OPTS: -Xmx3200m --illegal-access=deny
JVM_OPTS: -Xmx3200m --illegal-access=deny -Dclojure.main.report=stderr

# Runners for OpenJDK 8 and 11

Expand Down Expand Up @@ -133,6 +133,14 @@ jobs:
clojure_version: "1.10"
steps: << parameters.steps >>

deploy:
executor: openjdk8
steps:
- checkout
- run:
name: Deploy
command: |
TEST_PROFILES= lein with-profile -user,+deploy run -m deploy-release make deploy
test_code:
description: |
Expand Down Expand Up @@ -191,6 +199,11 @@ workflows:
jdk_version: [openjdk8, openjdk11, openjdk16, openjdk17]
clojure_version: ["1.8", "1.9", "1.10", "master"]
test_profiles: ["+test,-provided", "+test,+provided", "+test,+provided,+enrich-classpath"]
filters:
branches:
only: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
- util_job:
name: Code Linting, (latest LTS JDK)
jdk_version: openjdk17
Expand All @@ -203,3 +216,17 @@ workflows:
name: Running clj-kondo
command: |
make kondo
filters:
branches:
only: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
- deploy:
requires:
- test_code
- "Code Linting, (latest LTS JDK)"
filters:
branches:
ignore: /.*/
tags:
only: /^v\d+\.\d+\.\d+(-alpha\d+)?$/
35 changes: 35 additions & 0 deletions .circleci/deploy/deploy_release.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
(ns deploy-release
(:require
[clojure.java.shell :refer [sh]]
[clojure.string :as str]))

(def release-marker "v")

(defn make-version [tag]
(str/replace-first tag release-marker ""))

(defn log-result [m]
(println m)
m)

(defn -main [& _]
(let [tag (System/getenv "CIRCLE_TAG")]
(if-not tag
(do
(println "No CIRCLE_TAG found.")
(System/exit 1))
(if-not (re-find (re-pattern release-marker) tag)
(do
(println (format "The `%s` marker was not found in %s." release-marker tag))
(System/exit 1))
(let [version (make-version tag)]
(apply println "Executing" *command-line-args*)
(->> [:env (-> {}
(into (System/getenv))
(assoc "PROJECT_VERSION" version)
(dissoc "CLASSPATH"))]
(into (vec *command-line-args*))
(apply sh)
log-result
:exit
(System/exit)))))))
38 changes: 14 additions & 24 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: test docs eastwood cljfmt release deploy clean .EXPORT_ALL_VARIABLES
.PHONY: test docs eastwood cljfmt deploy clean .EXPORT_ALL_VARIABLES

VERSION ?= 1.10

Expand All @@ -12,33 +12,18 @@ test: clean .EXPORT_ALL_VARIABLES
lein with-profile -user,-dev,+$(VERSION),$(TEST_PROFILES) test

eastwood:
lein with-profile -user,-dev,+$(VERSION),+eastwood,$(TEST_PROFILES) eastwood
lein with-profile -user,-dev,+$(VERSION),+eastwood,+deploy,$(TEST_PROFILES) eastwood

cljfmt:
lein with-profile -user,-dev,+$(VERSION),+cljfmt cljfmt check
lein with-profile -user,-dev,+$(VERSION),+deploy,+cljfmt cljfmt check

kondo:
lein with-profile -user,-dev,+clj-kondo run -m clj-kondo.main --lint src test src-jdk8 src-newer-jdks test-newer-jdks test-cljs
lein with-profile -user,-dev,+clj-kondo run -m clj-kondo.main --lint src test src-jdk8 src-newer-jdks test-newer-jdks test-cljs .circleci/deploy

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

BUMP ?= patch

release: clean
lein with-profile -user,-dev,+$(VERSION),-provided release $(BUMP)

# Deploying requires the caller to set environment variables as
# specified in project.clj to provide a login and password to the
# artifact repository.
# Example:
# GIT_TAG=v0.9.0 CLOJARS_USERNAME=$USER CLOJARS_PASSWORD=$(pbpaste) make deploy
deploy: clean
# Deployment is performed via CI by creating a git tag prefixed with "v".
# Please do not deploy locally as it skips various measures.
deploy: check-env clean
lein with-profile -user,-dev,+$(VERSION),-provided deploy clojars
git tag -a "$$GIT_TAG" -m "$$GIT_TAG"
git push
git push --tags

install: clean
lein with-profile -user,-dev,+$(VERSION),-provided install
Expand All @@ -53,6 +38,11 @@ endif
ifndef CLOJARS_PASSWORD
$(error CLOJARS_PASSWORD is undefined)
endif
ifndef GIT_TAG
$(error GIT_TAG is undefined)
ifndef CIRCLE_TAG
$(error CIRCLE_TAG is undefined. Please only perform deployments by publishing git tags. CI will do the rest.)
endif

check-install-env:
ifndef PROJECT_VERSION
$(error Please set PROJECT_VERSION as an env var beforehand.)
endif
21 changes: 20 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,28 @@ past - `cider-nrepl` was split into two libraries, so that non-nREPL
clients can make of use of the general functionality contained in
`cider-nrepl` (e.g. things like `apropos`, `inspect`, etc).

### Development

You can install Orchard locally like this:

```
PROJECT_VERSION=0.9.2 make install
```

...note that projects such as cider-nrepl or refactor-nrepl use copies of Orchard that are inlined with [mranderson](https://github.com/benedekfazekas/mranderson),
so a local Orchard install won't automatically update those.

For releasing to [Clojars](https://clojars.org/):

```
git tag -a v0.9.2 -m "0.9.2"
git push --tags
git push
```

## License

Copyright © 2018-2021 Bozhidar Batsov & contributors
Copyright © 2018-2022 Bozhidar Batsov & contributors

Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.
Expand Down
9 changes: 5 additions & 4 deletions project.clj
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
(def jdk8? (->> "java.version" System/getProperty (re-find #"^1.8.")))

(defproject cider/orchard "0.9.1"
(defproject cider/orchard (or (not-empty (System/getenv "PROJECT_VERSION"))
"0.0.0")
:description "A fertile ground for Clojure tooling"
:url "https://github.com/clojure-emacs/orchard"
:license {:name "Eclipse Public License"
Expand All @@ -10,8 +11,6 @@
:exclusions [org.clojure/clojure ; see versions matrix below
org.clojure/clojurescript]

:aliases {"bump-version" ["change" "version" "leiningen.release/bump-version"]}

:release-tasks [["vcs" "assert-committed"]
["bump-version" "release"]
["vcs" "commit" "Release %s"]
Expand Down Expand Up @@ -86,4 +85,6 @@
System/getenv
(doto assert)
(.contains "enrich-classpath"))))
(conj 'orchard.java.legacy-parser))}}})
(conj 'orchard.java.legacy-parser))}}

:deploy {:source-paths [".circleci/deploy"]}})

0 comments on commit d202177

Please sign in to comment.