Skip to content

Commit

Permalink
fix getting modified deps
Browse files Browse the repository at this point in the history
  • Loading branch information
namenu committed Oct 2, 2023
1 parent f903d8b commit c1e0a84
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 16 deletions.
40 changes: 25 additions & 15 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,24 +36,19 @@ But it's good to know that such potential risks can be detected in advance.
`deps-diff` is a GitHub Action created for this purpose.


## Inputs

| Name | Description | Default Value |
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `base` | The deps.edn before the change being referenced. You can specify a git ref or file path. The default value is the git ref of the base branch of the PR, referencing the `deps.edn` at the repository's root path. You can specify it like `{{git-ref}}:{{path-to-deps.edn}}`. | Git ref of PR's base branch |
| `target` | The deps.edn after the change being referenced. You can specify a git ref or file path. The default value is the deps.edn in the current directory. | `deps.edn` in the current directory |
| `format` | Determines the format of the output. You can specify `edn`, `markdown`, or `cli`. The default value is edn | `edn` |
| `aliases` | Specifies the aliases to be used when forming the basis. It must be expressed as a quoted sequence (e.g., `'[:dev :test]'`). | `nil` |


## Outputs

- `deps_diff` - The name of the outlet where the execution result is output. Use it along with the action's id in your workflow.
## Example

Just make some changes in your `deps.edn` then run:

## Example
```sh
clj -Sdeps '{:deps {io.github.namenu/deps-diff {:git/tag "v1.0" :git/sha "f301e0b"}}}' \
-X namenu.deps-diff/diff \
:base '"HEAD"' \
:target '"deps.edn"' \
:format :cli
```

Create a `deps-diff.yml` file in `.github/workflows` as follows.
... or create a `.github/workflows/deps-diff.yml` file as follows.

```yml
name: Notify dependency diff
Expand Down Expand Up @@ -90,3 +85,18 @@ jobs:
This workflow will comment on your PR as shown below.
<img src="example.png" width="696">
## Inputs
| Name | Description | Default Value |
|-------------|-------------------------------------------------------------------------------------------------------------------------------------------------|----------------------------|
| `base` | The deps.edn before the change being referenced. You can specify a git ref or file path. The default value is the git ref of the base branch of the PR, referencing the `deps.edn` at the repository's root path. You can specify it like `{{git-ref}}:{{path-to-deps.edn}}`. | Git ref of PR's base branch |
| `target` | The deps.edn after the change being referenced. You can specify a git ref or file path. The default value is the deps.edn in the current directory. | `deps.edn` in the current directory |
| `format` | Determines the format of the output. You can specify `edn`, `markdown`, or `cli`. The default value is edn | `edn` |
| `aliases` | Specifies the aliases to be used when forming the basis. It must be expressed as a quoted sequence (e.g., `'[:dev :test]'`). | `nil` |


## Outputs

- `deps_diff` - The name of the outlet where the execution result is output. Use it along with the action's id in your workflow.
6 changes: 5 additions & 1 deletion src/namenu/deps_diff.clj
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,15 @@
(assert (s/valid? ::spec/ref target))
(assert (s/valid? ::spec/aliases aliases))
(assert (s/valid? ::spec/format format))

(let [deps-from (resolve-deps (read-edn base) aliases)
deps-to (resolve-deps (read-edn target) aliases)

key-set (comp set keys)

[removed-deps added-deps common-deps] (data/diff (key-set deps-from) (key-set deps-to))
modified-deps (set/union (select-keys deps-from common-deps) (select-keys deps-to common-deps))]
modified-deps (set/difference (set (select-keys deps-to common-deps))
(select-keys deps-from common-deps))]
(make-output
{:removed (into (sorted-map) (select-keys deps-from removed-deps))
:added (into (sorted-map) (select-keys deps-to added-deps))
Expand All @@ -88,6 +90,8 @@
;; git show e0f4689c07bc652492bf03eba7edac20ab2bee0f:test/resources/base.edn > base.edn
;; clojure -X namenu.deps-diff/diff base.edn deps.edn

(diff {:base "HEAD" :target "deps.edn" :format :cli})

(diff {:base "b2a1ca302959b720e703618a912a4b140389ee55" :target "deps.edn"
:format :cli})

Expand Down

0 comments on commit c1e0a84

Please sign in to comment.