Skip to content

Commit

Permalink
[minor] v0.2.0 feature (#6)
Browse files Browse the repository at this point in the history
* 🚚 Remove commands and revise package structures

Signed-off-by: Rintaro Okamura <[email protected]>

* 🔥 Remove Makefile

Signed-off-by: Rintaro Okamura <[email protected]>

* ⬆️ upgrade dependencies

Signed-off-by: Rintaro Okamura <[email protected]>

* 🔧 Fix

Signed-off-by: Rintaro Okamura <[email protected]>

* 🔧 Fix

Signed-off-by: Rintaro Okamura <[email protected]>

* 💚 Fix Ci

Signed-off-by: Rintaro Okamura <[email protected]>

* 🐳 Fix Dockerfile

Signed-off-by: Rintaro Okamura <[email protected]>

* 📝 update docs

Signed-off-by: Rintaro Okamura <[email protected]>
  • Loading branch information
rinx authored Apr 29, 2020
1 parent ab08f72 commit 70ea5d4
Show file tree
Hide file tree
Showing 24 changed files with 319 additions and 431 deletions.
12 changes: 7 additions & 5 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ on:
paths:
- src/**
- project.clj
- reflection.json
- native-config/**

jobs:
build-linux:
Expand All @@ -21,7 +21,7 @@ jobs:
- uses: actions/checkout@v1
- uses: rinx/[email protected]
with:
graalvm-version: 19.3.0
graalvm-version: 20.0.0
java-version: java8
- name: Install dependencies
run: |
Expand All @@ -34,8 +34,9 @@ jobs:
./lein uberjar
- name: Build native image
run: |
make
./lein native-image
# upx --lzma --best gitwerk
mv target/gitwerk gitwerk
zip --junk-paths gitwerk-linux-amd64 gitwerk
- name: Upload artifact
uses: actions/upload-artifact@v1
Expand All @@ -59,7 +60,7 @@ jobs:
echo "::set-env name=GRAALVM_HOME::$GRAALVM_HOME"
echo "::set-env name=JAVA_HOME::$GRAALVM_HOME"
env:
GRAALVM_VERSION: 19.3.0
GRAALVM_VERSION: 20.0.0
JAVA_VERSION: java8
- name: Install dependencies
run: |
Expand All @@ -70,7 +71,8 @@ jobs:
lein uberjar
- name: Build native image
run: |
make
lein native-image
mv target/gitwerk gitwerk
zip --junk-paths gitwerk-macos-amd64 gitwerk
- name: Upload artifact
uses: actions/upload-artifact@v1
Expand Down
8 changes: 4 additions & 4 deletions .github/workflows/semver.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ on:
- master

jobs:
semver-auto:
name: Run semver-auto
semver:
name: Run semver
runs-on: ubuntu-latest
steps:
- name: Check out code.
Expand All @@ -17,9 +17,9 @@ jobs:
run: |
wget "https://github.com/rinx/gitwerk/releases/latest/download/gitwerk-linux-amd64.zip"
unzip gitwerk-linux-amd64.zip
- name: Run gitwerk semver-auto
- name: Run gitwerk semver
run: |
./gitwerk semver-auto
./gitwerk contextual-semver
git remote set-url origin "https://${GITHUB_USER}:${GITHUB_TOKEN}@github.com/${GITHUB_REPOSITORY}.git"
git push origin --tags
env:
Expand Down
6 changes: 2 additions & 4 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,7 @@ RUN lein uberjar

COPY native-config native-config

COPY Makefile Makefile

RUN make
RUN lein native-image

RUN mkdir -p /out/lib \
&& cp $JAVA_HOME/jre/lib/amd64/libsunec.so /out/lib/ \
Expand All @@ -36,6 +34,6 @@ LABEL maintainer "rinx <[email protected]>"
RUN apt-get update && apt-get install -y git && rm -rf /var/lib/apt/lists/*

COPY --from=graalvm /out /gitwerk-libs
COPY --from=graalvm /gitwerk/gitwerk /gitwerk
COPY --from=graalvm /gitwerk/target/gitwerk /gitwerk

CMD ["/gitwerk", "-Djava.library.path=/gitwerk-libs/lib", "-Djavax.net.ssl.trustStore=/gitwerk-libs"]
75 changes: 0 additions & 75 deletions Makefile

This file was deleted.

121 changes: 66 additions & 55 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,61 @@ It is available to download native binaries for Linux and macOS from the [latest

## Usage

gitwerk has several subcommands.
gitwerk has several default functions.

### semver-auto
- `clone`
- `log`
- `tag`
- `contextual-semver`

The definitions of these functions can be printed by `prelude` function.

```bash
$ gitwerk prelude
(defn clone [repository]
(git/clone repository))

(defn log
([]
(log "."))
([repodir]
(-> (git/repo repodir)
(git/logs))))

(defn tag
([]
(tag "."))
([repodir]
(-> (git/repo repodir)
(git/tags))))

(defn repl []
(println "not implemented yet"))

(defn contextual-semver
([]
(contextual-semver "."))
([repodir]
(let [repo (git/repo repodir)
message (-> repo
(git/latest-log)
:full-message)
tag (or (-> repo
(git/tags)
(semver/latest-tag))
(semver/default-version-str))
new-tag (semver/contextual-semver message tag)]
(if (not (= tag new-tag))
(do
(git/tag repo new-tag)
{:status :updated
:old-version tag
:new-version new-tag})
{:status :not-updated}))))
```


### contextual-semver

increments version by git log message contexts.

Expand All @@ -28,7 +80,7 @@ increments version by git log message contexts.
$ git commit -m "[patch] increment patch version"
## the commit comment contains "[patch]"

$ gitwerk semver-auto
$ gitwerk contextual-semver
{:status :updated :old-version v0.0.1 :new-version v0.0.2}
## increments tag to v0.0.2

Expand All @@ -37,7 +89,7 @@ $ gitwerk semver-auto
$ git commit -m "[tag.suffix=-alpha] [minor] increment minor version and add suffix"
## the commit comment contains "[minor]" and "[tag.suffix=-alpha]"

$ gitwerk semver-auto
$ gitwerk contextual-semver
{:status :updated :old-version v0.0.2 :new-version v0.1.0-alpha}
## increments tag to v0.1.0-alpha

Expand All @@ -46,7 +98,7 @@ $ gitwerk semver-auto
$ git commit -m "[tag.prefix=] [tag.suffix=] [major] increment major version and remove prefix and suffix"
## the commit comment contains "[major]", "[tag.prefix=]" and "[tag.suffix=]"

$ gitwerk semver-auto
$ gitwerk contextual-semver
{:status :updated :old-version v0.1.0-alpha :new-version 1.0.0}
## increments tag to 1.0.0

Expand All @@ -55,69 +107,28 @@ $ gitwerk semver-auto
$ git commit -m "[tag.prefix=v] just adding prefix"
## the commit comment contains "[tag.prefix=v]"

$ gitwerk semver-auto
$ gitwerk contextual-semver
{:status :updated :old-version 1.0.0 :new-version v1.0.0}
## increments tag to v1.0.0
```

### semver

prints incremented version.

```bash
## when the latest tag is v0.0.1
### Define your own functions

$ gitwerk semver patch
v0.0.2
You can define your own functions and load them by using `--file` option or `--stdin` option.

$ gitwerk semver minor
v0.1.0

$ gitwerk semver major
v1.0.0
```bash
gitwerk --stdin myfunc
(defn myfunc []
(print "this is my first func"))
```

### sci
Available functions are non-side-effecting functions enabled in [sci](https://github.com/borkdude/sci) and the exported functions in gitwerk.internal and gitwerk.prelude namespaces.

gitwerk supports to run user-defined scripts written in clojure (powered by [borkdude/sci](https://github.com/borkdude/sci)).

```bash
## can read stdin
$ echo '(semver ctx ["patch"])' | gitwerk sci
v0.0.2

## also read a file as a script
$ cat examples/example1.clj
(semver ctx ["patch"])
$ gitwerk sci examples/example1.clj
v0.0.3

## fetch executed command result and modify returned message
$ cat examples/example2.clj
(let [res (semver-auto ctx nil)
status (get-in res [:console-out :status])
oldv (get-in res [:console-out :old-version])
newv (get-in res [:console-out :new-version])]
(if (= status :updated)
(str "Version updated: " oldv " -> " newv)
"Version not updated"))
$ gitwerk sci examples/example2.clj
Version not updated

$ git commit --allow-empty -m "[patch] version updated"
$ gitwerk sci examples/example2.clj
Version updated: v0.0.3 -> v0.0.4

## http get/post using clj-http-lite.client
$ echo '(-> (http/get "https://api.github.com/repos/rinx/gitwerk/issues") pprint)' | gitwerk sci

## parse json and convert to clj map
$ echo '(-> (http/get "https://api.github.com/repos/rinx/gitwerk/issues") :body (json/read-value) pprint)' | gitwerk sci
```

## License

Copyright © 2019 rinx
Copyright © 2019-2020 rinx

This program and the accompanying materials are made available under the
terms of the Eclipse Public License 2.0 which is available at
Expand Down
4 changes: 4 additions & 0 deletions native-config/reflect-config.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@
"name":"org.eclipse.jgit.lib.CoreConfig$SymLinks",
"methods":[{"name":"values","parameterTypes":[] }]
},
{
"name":"org.eclipse.jgit.lib.CoreConfig$LogRefUpdates",
"methods":[{"name":"values","parameterTypes":[] }]
},
{
"name":"org.eclipse.jgit.lib.ObjectIdRef$PeeledNonTag",
"allPublicMethods":true
Expand Down
31 changes: 26 additions & 5 deletions project.clj
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,35 @@
:url "https://github.com/rinx/gitwerk"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.9.0"]
#_[org.clojure/spec.alpha "0.2.176"]
:dependencies [[org.clojure/clojure "1.10.2-alpha1"]
[org.clojure/tools.cli "0.4.2"]
[metosin/jsonista "0.2.2"]
[metosin/jsonista "0.2.5"]
[camel-snake-kebab "0.4.0"]
[io.quarkus/quarkus-jgit "1.1.0.CR1"]
[borkdude/sci "0.0.12-alpha.7"]
[io.quarkus/quarkus-jgit "1.4.1.Final"]
[borkdude/sci "0.0.13-alpha.17"]
[org.martinklepsch/clj-http-lite "0.4.3"]]
:plugins [[io.taylorwood/lein-native-image "0.3.1"]]
:native-image {:name "gitwerk"
:opts ["-H:+ReportExceptionStackTraces"
"-H:Log=registerResource:"
"-H:ConfigurationFileDirectories=native-config"
"--enable-url-protocols=http,https"
"--enable-all-security-services"
"-H:+JNI"
"--verbose"
"--no-fallback"
"--no-server"
"--report-unsupported-elements-at-runtime"
"--initialize-at-run-time=org.eclipse.jgit.transport.HttpAuthMethod$Digest"
"--initialize-at-run-time=org.eclipse.jgit.lib.GpgSigner"
"--initialize-at-run-time=io.quarkus.jsch.runtime.PortWatcherRunTime"
"--initialize-at-build-time"
"-H:IncludeResourceBundles=org.eclipse.jgit.internal.JGitText"
"--allow-incomplete-classpath"
"-J-Xms2g"
"-J-Xmx7g"]
:jvm-opts ["-Dclojure.spec.skip-macros=true"
"-Dclojure.compiler.direct-linking=true"]}
:profiles {:dev {:dependencies [[org.clojure/tools.namespace "0.2.11"]
[orchestra "2019.02.06-1"]]
:source-paths ["dev"]}
Expand Down
Loading

0 comments on commit 70ea5d4

Please sign in to comment.