diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml index 702d36f..228edc9 100644 --- a/.github/workflows/deploy.yml +++ b/.github/workflows/deploy.yml @@ -1,44 +1,44 @@ -# name: Deploy -# -# on: -# push: -# branches: -# - master -# -# 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 Macaw -# run: clojure -T:build build -# env: -# GITHUB_SHA: ${{ env.GITHUB_SHA }} -# - name: Deploy Macaw -# run: clojure -T:build deploy -# env: -# CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} -# CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} +name: Deploy + +on: + push: + branches: + - master + +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 Macaw + run: clojure -T:build jar + env: + GITHUB_SHA: ${{ env.GITHUB_SHA }} + - name: Deploy Macaw + run: clojure -T:build deploy + env: + CLOJARS_USERNAME: ${{ secrets.CLOJARS_USERNAME }} + CLOJARS_PASSWORD: ${{ secrets.CLOJARS_PASSWORD }} diff --git a/build.clj b/build.clj index 17ff3fe..e9877db 100644 --- a/build.clj +++ b/build.clj @@ -4,9 +4,12 @@ (:require [clojure.java.shell :as sh] [clojure.string :as str] - [clojure.tools.build.api :as b])) + [clojure.tools.build.api :as b] + [deps-deploy.deps-deploy :as dd])) -(def lib 'metabase/macaw) +(def lib 'io.github.metabase/macaw) +(def github-url "https://github.com/metabase/macaw") +(def scm-url "git@github.com:metabase/macaw.git") (def major-minor-version "0.1") @@ -17,6 +20,12 @@ parse-long) "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)) @@ -25,23 +34,60 @@ (def basis (delay (b/create-basis {:project "deps.edn"}))) +(def pom-template + [[:description "A Clojure wrapper for JSqlParser"] + [:url github-url] + [:licenses + [:license + [:name "Eclipse Public License"] + [:url "http://www.eclipse.org/legal/epl-v10.html"]]] + [:developers + [:developer + [:name "Tim Macdonald"]]] + [: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" "java"] + :pom-data pom-template}) + (defn clean [_] (b/delete {:path target})) -(defn compile [_] - (b/javac {:src-dirs ["java"] - :class-dir class-dir - :basis @basis - :javac-opts ["--release" "11"]})) +(defn compile [opts] + (println "\nCompiling Java files...") + (b/javac (merge default-options + opts + {:src-dirs ["java"] + :javac-opts ["--release" "11"]}))) -(defn jar [_] +(defn jar [opts] + (println "\nStarting to build a JAR...") (compile nil) - (b/write-pom {:class-dir class-dir - :lib lib - :version version - :basis @basis - :src-dirs ["src"]}) + (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})) + :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! 🦜")))