diff --git a/.github/workflows/diffend_gem_binary_diff.yml b/.github/workflows/diffend_gem_binary_diff.yml new file mode 100644 index 00000000000..fe0367c803e --- /dev/null +++ b/.github/workflows/diffend_gem_binary_diff.yml @@ -0,0 +1,44 @@ +name: Diffend.io gem binary diff links +on: + pull_request: + paths: + - '**.gem' +jobs: + create_comment_with_diffend_io_links: + runs-on: ubuntu-latest + steps: + - name: Checkout repository + uses: actions/checkout@v3 + with: + fetch-depth: 0 + - name: Create Diffend.io Links and Comment + id: create_diffend_io_links_and_comment + run: | + # Receive added and removed file names from the git diff, filter out everything besides the gem files and receive + # the basename without the gem file extension + ADDED_GEMS=( $(git diff --name-only --diff-filter=A origin/${GITHUB_BASE_REF} $GITHUB_SHA | grep .gem$ | xargs basename -s .gem) ) + REMOVED_GEMS=( $(git diff --name-only --diff-filter=D origin/${GITHUB_BASE_REF} $GITHUB_SHA | grep .gem$ | xargs basename -s .gem) ) + + COMMENT_TEXT="Please see the links listed bellow to review the changes applied to the gems:"$'\n' + + for i in "${!ADDED_GEMS[@]}"; do + # Receive gem name without version number + GEM_NAME=$(echo ${ADDED_GEMS[i]} | rev | cut -d "-" -f2- | rev) + + # Receive added and removed gem version numbers + ADDED_GEM_VERSION=$(echo ${ADDED_GEMS[i]} | rev | cut -d "-" -f1 | rev) + REMOVED_GEM_VERSION=$(echo ${REMOVED_GEMS[i]} | rev | cut -d "-" -f1 | rev) + + # Create the link to diffend.io + DIFFEND_LINK=("https://my.diffend.io/gems/${GEM_NAME}/${REMOVED_GEM_VERSION}/${ADDED_GEM_VERSION}") + COMMENT_TEXT+="- [${GEM_NAME} ${REMOVED_GEM_VERSION} -> ${ADDED_GEM_VERSION}](${DIFFEND_LINK})"$'\n' + done + + echo "comment_text<> $GITHUB_OUTPUT + echo "$COMMENT_TEXT" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + - name: Add Comment to PR + uses: thollander/actions-comment-pull-request@v2 + with: + message: | + ${{steps.create_diffend_io_links_and_comment.outputs.comment_text}}