Skip to content

Commit

Permalink
Refactor
Browse files Browse the repository at this point in the history
  • Loading branch information
hkusu committed Dec 20, 2023
1 parent fbf232a commit 566b278
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 57 deletions.
112 changes: 55 additions & 57 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ inputs:
description: 'Bash script to run before Gradle dependencies task.'
required: false
repository: # opned for .github/workflows/ci.yml
description: ''
description: 'Target repository.'
required: false
default: ${{ github.repository }}
sha: # opend for .github/workflows/ci.yml
Expand All @@ -37,7 +37,7 @@ inputs:
outputs:
exists-diff:
description: 'Whether there are any differences in dependencies.'
value: ${{ steps.report.outputs.exists-diff || 'false' }}
value: ${{ steps.report.outputs.exists-diff }}
runs:
using: 'composite'
steps:
Expand All @@ -58,18 +58,19 @@ runs:
PR_NUMBER: ${{ github.event.pull_request.number }}
GH_TOKEN: ${{ github.token }}
run: |
function raise_error() {
echo "::error::$1"
return 1
}
echo "::debug::git version: $(git --version)"
echo "::debug::gh version: $(gh --version | tr '\n' ' ')"
source "$GITHUB_ACTION_PATH/raise_error.sh"
readonly WORK_DIR="$GITHUB_ACTION_PATH"
mkdir "$WORK_DIR/tools"
mkdir "$WORK_DIR/deps"
if [[ "$EVENT_NAME" != 'pull_request' && "$EVENT_NAME" != 'push' ]]; then raise_error "This action must be triggered by a 'pull_request' or 'push' event."; fi
if [[ -z "$MODULES" ]]; then raise_error "Specify 'modules' input."; fi
modules=()
configurations=()
for module in $MODULES ; do
configuration="$CONFIGURATION"
Expand All @@ -84,27 +85,18 @@ runs:
configurations+=($configuration)
done
cd "$GITHUB_ACTION_PATH"
readonly WORK_DIR="$(pwd)"
mkdir tools
mkdir deps
curl -f -L -o "$WORK_DIR/tools/dependency-diff-tldr-r8.jar" 'https://github.com/careem/dependency-diff-tldr/releases/download/v0.0.6/dependency-diff-tldr-r8.jar'
if [[ 'b76af4e71fe1bc3362207d648542337c21ab91e8' != "$(cat "$WORK_DIR/tools/dependency-diff-tldr-r8.jar" | openssl sha1 | awk '{print $2}')" ]]; then
if [ 'b76af4e71fe1bc3362207d648542337c21ab91e8' != "$(cat "$WORK_DIR/tools/dependency-diff-tldr-r8.jar" | openssl sha1 | awk '{print $2}')" ]; then
raise_error "Incorrect checksum for dependency-diff-tldr-r8.jar."
fi
curl -f -L -o "$WORK_DIR/tools/dependency-tree-diff.jar" 'https://github.com/JakeWharton/dependency-tree-diff/releases/download/1.2.0/dependency-tree-diff.jar'
if [[ '949394274f37c06ac695b5d49860513e4d16e847' != "$(cat "$WORK_DIR/tools/dependency-tree-diff.jar" | openssl sha1 | awk '{print $2}')" ]]; then
if [ '949394274f37c06ac695b5d49860513e4d16e847' != "$(cat "$WORK_DIR/tools/dependency-tree-diff.jar" | openssl sha1 | awk '{print $2}')" ]; then
raise_error "Incorrect checksum for dependency-tree-diff.jar."
fi
gh repo clone "$REPOSITORY" sources > /dev/null 2>&1 || raise_error "May not have 'contents: read' permission."
cd ./sources
cd "$WORK_DIR/sources"
# enable fetch
# ref: https://github.com/actions/checkout/blob/72f2cec99f417b1a1c5e2e88945068983b7965f9/src/git-auth-helper.ts#L55-L63
Expand Down Expand Up @@ -145,42 +137,48 @@ runs:
cd "$WORK_DIR/sources/$PROJECT_DIR" # directory may have changed in the script
for i in "${!modules[@]}" ; do
# on windows, files containing CR cause an error in diff tools
./gradlew -q ":${modules[$i]}:dependencies" --configuration "${configurations[$i]}" | tr -d '\r' > "$WORK_DIR/deps/${modules[$i]}-after-deps.txt"
done
echo "### $REPORT_TITLE" >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo "- commit SHA before change: [${before_sha}](https://github.com/${REPOSITORY}/commit/${before_sha})" >> $GITHUB_STEP_SUMMARY
echo "- commit SHA after change: [${after_sha}](https://github.com/${REPOSITORY}/commit/${after_sha})" >> $GITHUB_STEP_SUMMARY
for i in "${!modules[@]}" ; do
result="$(java -jar "$WORK_DIR/tools/dependency-diff-tldr-r8.jar" "$WORK_DIR/deps/${modules[$i]}-before-deps.txt" "$WORK_DIR/deps/${modules[$i]}-after-deps.txt")"
echo '' >> $GITHUB_STEP_SUMMARY
if [[ -n "$result" ]]; then
echo ":orange_square: \`${modules[$i]}\` module ( \`${configurations[$i]}\` configuration )" >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo "$result" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
result_detail="$(java -jar "$WORK_DIR/tools/dependency-tree-diff.jar" "$WORK_DIR/deps/${modules[$i]}-before-deps.txt" "$WORK_DIR/deps/${modules[$i]}-after-deps.txt")"
echo '' >> $GITHUB_STEP_SUMMARY
echo '<details>' >> $GITHUB_STEP_SUMMARY
echo '<summary>detail</summary>' >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo '```diff' >> $GITHUB_STEP_SUMMARY
echo "$result_detail" >> $GITHUB_STEP_SUMMARY
echo '```' >> $GITHUB_STEP_SUMMARY
echo '</details>' >> $GITHUB_STEP_SUMMARY
echo 'exists-diff=true' >> $GITHUB_OUTPUT
else
echo ":green_square: \`${modules[$i]}\` module ( \`${configurations[$i]}\` configuration )" >> $GITHUB_STEP_SUMMARY
echo '' >> $GITHUB_STEP_SUMMARY
echo 'No differences in dependencies, when this module is the base point.' >> $GITHUB_STEP_SUMMARY
fi
done
exists=false
{
echo "### $REPORT_TITLE"
echo ''
echo "- commit SHA before change: [${before_sha}](https://github.com/${REPOSITORY}/commit/${before_sha})"
echo "- commit SHA after change: [${after_sha}](https://github.com/${REPOSITORY}/commit/${after_sha})"
for i in "${!modules[@]}" ; do
result="$(java -jar "$WORK_DIR/tools/dependency-diff-tldr-r8.jar" "$WORK_DIR/deps/${modules[$i]}-before-deps.txt" "$WORK_DIR/deps/${modules[$i]}-after-deps.txt")"
echo ''
if [[ -n "$result" ]]; then
exists=true
echo ":orange_square: \`${modules[$i]}\` module ( \`${configurations[$i]}\` configuration )"
echo ''
echo '```'
echo "$result"
echo '```'
result_detail="$(java -jar "$WORK_DIR/tools/dependency-tree-diff.jar" "$WORK_DIR/deps/${modules[$i]}-before-deps.txt" "$WORK_DIR/deps/${modules[$i]}-after-deps.txt")"
echo ''
echo '<details>'
echo '<summary>detail</summary>'
echo ''
echo '```diff'
echo "$result_detail"
echo '```'
echo '</details>'
else
echo ":green_square: \`${modules[$i]}\` module ( \`${configurations[$i]}\` configuration )"
echo ''
echo 'No differences in dependencies, when this module is the base point.'
fi
done
} >> "$GITHUB_STEP_SUMMARY"
echo "exists-diff=$exists" >> "$GITHUB_OUTPUT"
rm -fr "$WORK_DIR/tools"; rm -fr "$WORK_DIR/deps"; rm -fr "$WORK_DIR/sources"
4 changes: 4 additions & 0 deletions raise_error.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
function raise_error() {
echo "::error::$1"
return 1
}

0 comments on commit 566b278

Please sign in to comment.