Skip to content

Commit

Permalink
use tools.build to build and deploy
Browse files Browse the repository at this point in the history
- also adds a github workflow to do deployments on pushes to master
  • Loading branch information
escherize committed Feb 28, 2024
1 parent c54bf21 commit 5f104ec
Show file tree
Hide file tree
Showing 3 changed files with 114 additions and 31 deletions.
37 changes: 22 additions & 15 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,29 @@ on:
- master

jobs:
Deploy:
deploy:
runs-on: ubuntu-latest
environment: Deployment
timeout-minutes: 10
steps:
- uses: actions/checkout@v3.2.0
- uses: ./.github/actions/setup
with:
cache-key: "deploy"
- name: Build JAR
shell: bash
run: >-
set -x;
clojure -X:jar :version "\"$(cat VERSION.txt)\""
- name: Upload JAR to Clojars
run: clojure -X:deploy :artifact '"target/saml20-clj.jar"'
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
- uses: actions/checkout@v4.1.0
with:
fetch-depth: 0
- name: Prepare JDK 17
uses: actions/setup-java@v3
with:
java-version: 17
distribution: 'temurin'
- name: Setup Clojure
uses: DeLaGuardo/setup-clojure@12.1
with:
cli: 1.11.1.1413
- name: Build saml20
run: clojure -T:build build
env:
GITHUB_SHA: ${{ env.GITHUB_SHA }}
- name: Deploy saml20
run: clojure -T:build deploy
env:
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }}
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }}
86 changes: 86 additions & 0 deletions build.clj
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
(ns build
(:require [clojure.java.shell :as sh]
[clojure.pprint :as pprint]
[clojure.string :as str]
[clojure.tools.build.api :as b]
[deps-deploy.deps-deploy :as dd]))

(def scm-url "git@github.com:metabase/saml20-clj.git")
(def github-url "https://github.com/metabase/saml20-clj/")
(def lib 'metabase/saml20-clj)

(def major-minor-version (str/trim (slurp "VERSION.txt")))

(defn commit-number []
(or (-> (sh/sh "git" "rev-list" "HEAD" "--count")
:out
str/trim
parse-long)
"9999-SNAPSHOT"))

(def version (str major-minor-version \. (commit-number)))

(def target "target")
(def class-dir "target/classes")
(def jar-file (format "target/%s-%s.jar" lib version))


(def sha
(or (not-empty (System/getenv "GITHUB_SHA"))
(not-empty (-> (sh/sh "git" "rev-parse" "HEAD")
:out
str/trim))))

(def pom-template
[[:description "A library for delightful database interaction."]
[:url github-url]
[:licenses
[:license
[:name "Eclipse Public License"]
[:url "http://www.eclipse.org/legal/epl-v10.html"]]]
[:developers
[:developer
[:name "Cam Saul"]]]
[:scm
[:url github-url]
[:connection (str "scm:git:" scm-url)]
[:developerConnection (str "scm:git:" scm-url)]
[:tag sha]]])

(def default-options
{:lib lib
:version version
:jar-file jar-file
:basis (b/create-basis {})
:class-dir class-dir
:target target
:src-dirs ["src"]
:pom-data pom-template})

(defn build [opts]
(let [opts (merge default-options opts)]
(b/delete {:path target})
(println "\nWriting pom.xml...")
(b/write-pom opts)
(println "\nCopying source...")
(b/copy-dir {:src-dirs ["src" "resources"]
:target-dir class-dir})
(printf "\nBuilding %s...\n" jar-file)
(b/jar opts)
(println "Done.")))

(defn install [opts]
(printf "Installing %s to local Maven repository...\n" version)
(b/install (merge default-options opts)))

(defn build-and-install [opts]
(build opts)
(install opts))

(defn deploy [opts]
(let [opts (merge default-options opts)]
(printf "Deploying %s...\n" jar-file)
(dd/deploy {:installer :remote
:artifact (b/resolve-path jar-file)
:pom-file (b/pom-path (select-keys opts [:lib :class-dir]))})
(println "Done.")))
22 changes: 6 additions & 16 deletions deps.edn
Original file line number Diff line number Diff line change
Expand Up @@ -88,19 +88,9 @@
:include-license
{:extra-paths ["license"]}

;; clojure -X:jar :version "\"$(cat VERSION.txt)\""
:jar
{:replace-deps {com.github.seancorfield/depstar {:mvn/version "2.1.303"}}
:exec-fn hf.depstar/jar
:exec-args {:group-id "metabase"
:artifact-id "saml20-clj"
:jar "target/saml20-clj.jar"
:sync-pom true
:paths-only true
:aliases [:include-license]}}

;; clojure -X:deploy :artifact '"target/saml20-clj.jar"'
:deploy
{:extra-deps {slipset/deps-deploy {:mvn/version "RELEASE"}}
:exec-fn deps-deploy.deps-deploy/deploy
:exec-args {:installer :remote}}}}
;; clojure -T:build build
;; clojure -T:build deploy
:build
{:deps {io.github.clojure/tools.build {:mvn/version "0.9.6"}
slipset/deps-deploy {:mvn/version "0.2.2"}}
:ns-default build}}}

0 comments on commit 5f104ec

Please sign in to comment.