From d2021779eb3fb909135705326051c006e1591f05 Mon Sep 17 00:00:00 2001 From: vemv Date: Tue, 22 Feb 2022 17:03:18 +0100 Subject: [PATCH] Setup deployments in CI Modelled after https://github.com/clojure-emacs/cider-nrepl/pull/745 --- .circleci/config.yml | 31 +++++++++++++++++++++-- .circleci/deploy/deploy_release.clj | 35 ++++++++++++++++++++++++++ Makefile | 38 +++++++++++------------------ README.md | 21 +++++++++++++++- project.clj | 9 ++++--- 5 files changed, 103 insertions(+), 31 deletions(-) create mode 100644 .circleci/deploy/deploy_release.clj diff --git a/.circleci/config.yml b/.circleci/config.yml index 0971f347..d713e8a7 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -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 @@ -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: | @@ -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 @@ -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+)?$/ diff --git a/.circleci/deploy/deploy_release.clj b/.circleci/deploy/deploy_release.clj new file mode 100644 index 00000000..abc7bcbe --- /dev/null +++ b/.circleci/deploy/deploy_release.clj @@ -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))))))) diff --git a/Makefile b/Makefile index 2c064fe2..78738d25 100644 --- a/Makefile +++ b/Makefile @@ -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 @@ -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 @@ -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 diff --git a/README.md b/README.md index 33cc9f4a..3c6df588 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/project.clj b/project.clj index c2dc0d92..c64702a2 100644 --- a/project.clj +++ b/project.clj @@ -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" @@ -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"] @@ -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"]}})