-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add deploy script for Clojars [Fixes #22]
- Loading branch information
1 parent
ac3c663
commit daf7e04
Showing
4 changed files
with
165 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
name: Deploy | ||
|
||
on: | ||
push: | ||
branches: | ||
- main | ||
|
||
jobs: | ||
deploy: | ||
runs-on: ubuntu-20.04 | ||
environment: Deployment | ||
steps: | ||
- 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: Restore cache | ||
uses: actions/cache@v3 | ||
with: | ||
path: | | ||
~/.m2/repository | ||
~/.gitlibs | ||
~/.deps.clj | ||
key: v1-${{ hashFiles('./deps.edn') }}-deploy | ||
restore-keys: | | ||
v1-${{ hashFiles('./deps.edn') }}- | ||
v1- | ||
- name: Build Hawk | ||
run: clojure -T:build jar | ||
env: | ||
GITHUB_SHA: ${{ env.GITHUB_SHA }} | ||
- name: Deploy Hawk | ||
run: clojure -T:build deploy | ||
env: | ||
CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} | ||
CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
0.1.x |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
;; Further info: https://clojure.org/guides/tools_build#_mixed_java_clojure_build | ||
|
||
(ns build | ||
(:refer-clojure :exclude [compile]) | ||
(:require | ||
[clojure.java.shell :as sh] | ||
[clojure.string :as str] | ||
[clojure.tools.build.api :as b] | ||
[deps-deploy.deps-deploy :as dd])) | ||
|
||
(def lib 'io.github.metabase/hawk) | ||
(def github-url "https://github.com/metabase/hawk") | ||
(def scm-url "git@github.com:metabase/hawk.git") | ||
|
||
(def version-template (str/trim (slurp "VERSION"))) | ||
(assert (re-matches #"\d+\.\d+\.x" version-template)) | ||
|
||
(def major-minor-version (str/replace version-template #"\.x$" "")) | ||
|
||
(defn sh [& args] | ||
(let [{:keys [exit out]} (apply sh/sh args)] | ||
(assert (zero? exit)) | ||
(str/trim out))) | ||
|
||
(defn- commits-since-version-changed [] | ||
(let [last-sha (sh "git" "log" "-1" "--format=%H" "--" "VERSION")] | ||
(parse-long (sh "git" "rev-list" "--count" (str last-sha "..HEAD"))))) | ||
|
||
(defn commit-number [] | ||
(if (= "master" (sh "git" "rev-parse" "--abbrev-ref" "HEAD")) | ||
(commits-since-version-changed) | ||
"9999-SNAPSHOT")) | ||
|
||
(def sha | ||
(or (not-empty (System/getenv "GITHUB_SHA")) | ||
(not-empty (-> (sh/sh "git" "rev-parse" "HEAD") | ||
:out | ||
str/trim)))) | ||
|
||
(def version (str major-minor-version \. (commit-number))) | ||
(def target "target") | ||
(def class-dir (format "%s/classes" target)) | ||
|
||
(def jar-file (format "target/%s-%s.jar" (name lib) version)) | ||
|
||
(def basis (delay (b/create-basis {:project "deps.edn"}))) | ||
|
||
(def pom-template | ||
[[:description "It watches your code like a hawk!"] | ||
[:url github-url] | ||
[:licenses | ||
[:license | ||
[:name "Eclipse Public License"] | ||
[:url "http://www.eclipse.org/legal/epl-v20.html"]]] | ||
[:developers | ||
[:developer | ||
[:name "Cam Saul"]] | ||
[:developer | ||
[:name "John Cromartie"]] | ||
[:developer | ||
[:name "Nemanja Glumac"]] | ||
[:developer | ||
[:name "Cal Herries"]] | ||
[:developer | ||
[:name "Ngoc Khuat"]] | ||
[:developer | ||
[:name "Tim Macdonald"]] | ||
[:developer | ||
[:name "Case Nelson"]] | ||
[:developer | ||
[:name "Filipe Silva"]] | ||
[:developer | ||
[:name "Dan Sutton"]] | ||
[:developer | ||
[:name "Chris Truter"]]] | ||
[: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 @basis | ||
:class-dir class-dir | ||
:target target | ||
:src-dirs ["src"] | ||
:pom-data pom-template}) | ||
|
||
(defn clean [_] | ||
(b/delete {:path target})) | ||
|
||
(defn jar [opts] | ||
(println "\nStarting to build a JAR...") | ||
(println "\tWriting pom.xml...") | ||
(b/write-pom (merge default-options opts)) | ||
(println "\tCopying source...") | ||
(b/copy-dir {:src-dirs ["src" "resources"] | ||
:target-dir class-dir}) | ||
(printf "\tBuilding %s...\n" jar-file) | ||
(b/jar {:class-dir class-dir | ||
:jar-file jar-file}) | ||
(println "Done! 🦜")) | ||
|
||
|
||
(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 "Deployed! 🦅"))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters