Skip to content

Commit

Permalink
Merge pull request #9 from nnichols/cdua-7/monorepo-support
Browse files Browse the repository at this point in the history
CDUA-7: Better monorepo support
  • Loading branch information
nnichols committed Jan 29, 2022
2 parents 6bbff79 + d2d6f37 commit acc698b
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 41 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## v4 - 01/29/2022

- Dependency update commit messages now link to the github diff between the old and new version.
- Utilize antq instead of sed for updating dependencies
- Fix multi-directory support

## v3 - 01/30/2021

- Enable a batch update mode
Expand Down
43 changes: 40 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,11 +1,20 @@
# Clojure Dependency Update Action

A simple GitHub action to create Pull Requests for your out-of-date tools.deps dependencies.
A simple GitHub action to create Pull Requests for your out-of-date dependencies in clojure projects.
This action can automatically update the following dependency files:

- [deps.edn](https://github.com/clojure/tools.deps.alpha)
- [shadow-cljs.edn](https://github.com/thheller/shadow-cljs)
- [project.clj](https://github.com/technomancy/leiningen)
- [build.boot](https://github.com/boot-clj/boot)
- [pom.xml](https://github.com/apache/maven)

This action uses [antq](https://github.com/liquidz/antq) to check dependencies.

## Sample Usage

### Basic

```yml
name: Clojure Dependency Checking

Expand All @@ -18,12 +27,40 @@ jobs:

steps:
- name: Checkout Latest Commit
uses: actions/checkout@v1
uses: actions/checkout@v2.3.4

- name: Check deps
uses: nnichols/clojure-dependency-update-action@v4
with:
github-token: ${{ secrets.github_token }}
```

### Advanced

```yml

name: Batch Dependency Update

on: workflow_dispatch

jobs:
build:

runs-on: ubuntu-latest

steps:
- name: Checkout Latest Commit
uses: actions/checkout@v2.3.4

- name: Check deps
uses: nnichols/clojure-dependency-update-action@v3
uses: nnichols/clojure-dependency-update-action@v4
with:
github-token: ${{ secrets.github_token }}
git-username: nnichols
skips: "pom"
batch: "true"
branch: "main"
directories: "cli web"
```

## Supported Arguments
Expand Down
93 changes: 55 additions & 38 deletions dependency-check.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ for artifact in $EXCLUDE; do
EXCLUDES="${EXCLUDES} --exclude=${artifact}"
done

if [ -z "${DIRECTORY}" ]; then
DIRECTORY="."
fi

DIRECTORIES=""
for directory in $DIRECTORY; do
DIRECTORIES="${DIRECTORIES} --directory=${directory}"
Expand All @@ -21,46 +25,59 @@ for skip in $SKIP; do
done

PREFETCH=$(clojure -Stree -Sdeps '{:deps {antq/antq {:mvn/version "RELEASE"}}}')
UPGRADES=$(clojure -Sdeps '{:deps {antq/antq {:mvn/version "RELEASE"}}}' -m antq.core --reporter=format --error-format="{{name}},{{version}},{{latest-version}}" $EXCLUDES $DIRECTORIES $SKIPS | sed '/Failed to fetch/d' | sed '/Unable to fetch/d' | sed '/Logging initialized/d')

if [ $BATCH = 'true' ]; then
BRANCH_NAME="dependencies/clojure/$(date +"%Y-%m-%d-%H-%M-%S")"
git checkout -b $BRANCH_NAME
for upgrade in $UPGRADES; do
IFS=',' temp=($upgrade)
DEP_NAME=${temp[0]}
OLD_VERSION=${temp[1]}
NEW_VERSION=${temp[2]}
echo "Updating" $DEP_NAME "version" $OLD_VERSION "to" $NEW_VERSION
ESCAPED_DEP_NAME=`echo $DEP_NAME | sed 's/\//\\\\\//'`
sed -e "/$ESCAPED_DEP_NAME/s/$OLD_VERSION/$NEW_VERSION/" deps.edn > deps2.edn
mv deps2.edn deps.edn
git add .
git commit -m "Bump $DEP_NAME from $OLD_VERSION to $NEW_VERSION"
done
git push -u "https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git" $BRANCH_NAME
gh pr create --fill --head $BRANCH_NAME --base $BRANCH
echo
git checkout $BRANCH
else
for upgrade in $UPGRADES; do
IFS=',' temp=($upgrade)
DEP_NAME=${temp[0]}
OLD_VERSION=${temp[1]}
NEW_VERSION=${temp[2]}
FORMATTER="--reporter=format --error-format=\"{{name}},{{version}},{{latest-version}},{{diff-url}}\""
UPGRADE_CMD="clojure -Sdeps '{:deps {antq/antq {:mvn/version \"RELEASE\"}}}' -m antq.core ${FORMATTER} ${EXCLUDES} ${DIRECTORIES} ${SKIPS}"
UPGRADE_LIST=$(eval ${UPGRADE_CMD})
UPGRADES=$(echo ${UPGRADE_LIST} | sed '/Failed to fetch/d' | sed '/Unable to fetch/d' | sed '/Logging initialized/d' | sort -u)
UPDATE_TIME=$(date +"%Y-%m-%d-%H-%M-%S")

for upgrade in $UPGRADES; do

# Parse each upgrade into its constituent parts
IFS=',' temp=($upgrade)
DEP_NAME=${temp[0]}
OLD_VERSION=${temp[1]}
NEW_VERSION=${temp[2]}
DIFF_URL=${temp[3]}
MODIFIED_FILE=${temp[4]}

# If we're performing a batch update, reuse the branch name
# Otherwise, create branch names for each unique update
if [ "$BATCH" == "true" ]; then
BRANCH_NAME="dependencies/clojure/${UPDATE_TIME}"
else
BRANCH_NAME="dependencies/clojure/$DEP_NAME-$NEW_VERSION"
fi

# Checkout the branch if it exists, otherwise create it
echo "Checking out" $BRANCH_NAME
git checkout $BRANCH_NAME || git checkout -b $BRANCH_NAME

if [[ $? == 0 ]]; then

# Use antq to update the dependency
echo "Updating" $DEP_NAME "version" $OLD_VERSION "to" $NEW_VERSION
git checkout -b $BRANCH_NAME
if [[ $? == 0 ]]; then
ESCAPED_DEP_NAME=`echo $DEP_NAME | sed 's/\//\\\\\//'`
sed -e "/$ESCAPED_DEP_NAME/s/$OLD_VERSION/$NEW_VERSION/" deps.edn > deps2.edn
mv deps2.edn deps.edn
git add .
git commit -m "Bump $DEP_NAME from $OLD_VERSION to $NEW_VERSION"
git push -u "https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git" $BRANCH_NAME
UPDATE_CMD="clojure -Sdeps '{:deps {antq/antq {:mvn/version \"RELEASE\"}}}' -m antq.core --upgrade --force ${DIRECTORIES} --focus=${DEP_NAME}"
eval ${UPDATE_CMD} || $(echo "Cannot update ${DEP_NAME}. Continuing" && git checkout ${BRANCH} && continue)

# Commit the dependency update, and link to the diff
git add .
git commit -m "Bumped $DEP_NAME from $OLD_VERSION to $NEW_VERSION." -m "Inspect dependency changes here: $DIFF_URL"
git push -u "https://$GITHUB_ACTOR:$TOKEN@github.com/$GITHUB_REPOSITORY.git" $BRANCH_NAME

# We only create pull requests per dependency in non-batch mode
if [ "$BATCH" != "true" ]; then
gh pr create --fill --head $BRANCH_NAME --base $BRANCH
echo
git checkout $BRANCH
fi
done

# Print a blank line, and reset the branch
echo
git checkout $BRANCH
fi
done

# Once all updates have been made, open the pull request for batch mode
if [ "$BATCH" == "true" ]; then
git checkout $BRANCH_NAME
gh pr create --fill --head $BRANCH_NAME --base $BRANCH
fi

0 comments on commit acc698b

Please sign in to comment.