From c2b58adcbd38cb30b5b61ed69af0a5b813742d2a Mon Sep 17 00:00:00 2001 From: Tonye Jack Date: Fri, 21 May 2021 08:39:56 -0400 Subject: [PATCH] Switch to a docker based action (#78) --- Dockerfile | 10 ++++ action.yml | 132 ++------------------------------------------------ entrypoint.sh | 127 ++++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 140 insertions(+), 129 deletions(-) create mode 100644 Dockerfile create mode 100644 entrypoint.sh diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 00000000..87250431 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM alpine:3.13.5 + +LABEL maintainer="Tonye Jack " + +RUN apk add bash git openssh grep sed + +COPY entrypoint.sh /entrypoint.sh +RUN chmod +x /entrypoint.sh + +ENTRYPOINT ["/entrypoint.sh"] diff --git a/action.yml b/action.yml index 8c0851dd..75038364 100644 --- a/action.yml +++ b/action.yml @@ -18,156 +18,30 @@ inputs: outputs: added_files: description: List of added files. - value: ${{ steps.changed_files.outputs.added_files }} copied_files: description: List of copied files. - value: ${{ steps.changed_files.outputs.copied_files }} deleted_files: description: List of deleted files. - value: ${{ steps.changed_files.outputs.deleted_files }} modified_files: description: List of modified files. - value: ${{ steps.changed_files.outputs.modified_files }} renamed_files: description: List of renamed files. - value: ${{ steps.changed_files.outputs.renamed_files }} changed_files: description: List of changed files. - value: ${{ steps.changed_files.outputs.changed_files }} unmerged_files: description: List of unmerged files. - value: ${{ steps.changed_files.outputs.unmerged_files }} unknown_files: description: List of unknown files. - value: ${{ steps.changed_files.outputs.unknown_files }} all_changed_files: description: List of all changed files. - value: ${{ steps.changed_files.outputs.all_changed_files }} all_modified_files: - description: List of all copied modified and added files - value: ${{ steps.changed_files.outputs.all_modified_files }} + description: List of all copied modified and added files. any_changed: description: Return true only when any files provided using the files input have changed. - value: ${{ steps.changed_files.outputs.any_changed }} runs: - using: 'composite' - steps: - - id: changed_files - run: | - set -e - - git remote set-url origin "https://${{ inputs.token }}@github.com/${{ github.repository }}" - - export INPUT_FILES="${{ inputs.files }}" - export INPUT_SEPARATOR="${{ inputs.separator }}" - echo "Getting head sha..." - if [[ -z $GITHUB_BASE_REF ]]; then - HEAD_SHA=$(git rev-parse HEAD^1 || true) - else - TARGET_BRANCH=${GITHUB_BASE_REF} - git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" - HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" || true) - fi - - if [[ -z $HEAD_SHA ]]; then - echo "::warning::Unable to determine the head sha: $HEAD_SHA." - echo "::warning::You seem to be missing `fetch-depth: 0` or `fetch-depth: 2`" - exit 1 - else - echo "Using head sha: $HEAD_SHA..." - - if [[ -z "$INPUT_FILES" ]]; then - echo "Getting diff..." - ADDED=$(git diff --diff-filter=A --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - COPIED=$(git diff --diff-filter=C --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - DELETED=$(git diff --diff-filter=D --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - MODIFIED=$(git diff --diff-filter=M --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - RENAMED=$(git diff --diff-filter=R --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - CHANGED=$(git diff --diff-filter=T --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - UNMERGED=$(git diff --diff-filter=U --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - UNKNOWN=$(git diff --diff-filter=X --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") - else - ADDED_ARRAY=() - COPIED_ARRAY=() - DELETED_ARRAY=() - MODIFIED_ARRAY=() - RENAMED_ARRAY=() - CHANGED_ARRAY=() - UNMERGED_ARRAY=() - UNKNOWN_ARRAY=() - ALL_CHANGED_ARRAY=() - ALL_MODIFIED_FILES_ARRAY=() - - for path in ${INPUT_FILES} - do - echo "Checking for file changes: \"${path}\"..." - IFS=" " - ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) - done - - ADDED=$(echo "${ADDED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - COPIED=$(echo "${COPIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - DELETED=$(echo "${DELETED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - RENAMED=$(echo "${RENAMED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - CHANGED=$(echo "${CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') - fi - fi - - echo "Added files: $ADDED" - echo "Copied files: $COPIED" - echo "Deleted files: $DELETED" - echo "Modified files: $MODIFIED" - echo "Renamed files: $RENAMED" - echo "Changed files: $CHANGED" - echo "Unmerged files: $UNMERGED" - echo "Unknown files: $UNKNOWN" - echo "All changed files: $ALL_CHANGED" - echo "All modified files: $ALL_MODIFIED_FILES" - - if [[ -n "$INPUT_FILES" ]]; then - # shellcheck disable=SC2001 - ALL_INPUT_FILES=$(echo "$INPUT_FILES" | tr "\n" " " | xargs) - - echo "Input files: ${ALL_INPUT_FILES[@]}" - echo "Matching modified files: ${ALL_MODIFIED_FILES[@]}" - - if [[ -n "$ALL_MODIFIED_FILES" ]]; then - echo "::set-output name=any_changed::true" - else - echo "::set-output name=any_changed::false" - fi - fi - - echo "::set-output name=added_files::$ADDED" - echo "::set-output name=copied_files::$COPIED" - echo "::set-output name=deleted_files::$DELETED" - echo "::set-output name=modified_files::$MODIFIED" - echo "::set-output name=renamed_files::$RENAMED" - echo "::set-output name=changed_files::$CHANGED" - echo "::set-output name=unmerged_files::$UNMERGED" - echo "::set-output name=unknown_files::$UNKNOWN" - echo "::set-output name=all_changed_files::$ALL_CHANGED" - echo "::set-output name=all_modified_files::$ALL_MODIFIED_FILES" - unset INPUT_FILES - unset INPUT_SEPARATOR - shell: bash + using: 'docker' + image: 'Dockerfile' branding: icon: file-text diff --git a/entrypoint.sh b/entrypoint.sh new file mode 100644 index 00000000..161a3817 --- /dev/null +++ b/entrypoint.sh @@ -0,0 +1,127 @@ +#!/usr/bin/env bash + +set -e + +git remote set-url origin "https://${INPUT_TOKEN}@github.com/${GITHUB_REPOSITORY}" + +echo "Getting head sha..." + +if [[ -z $GITHUB_BASE_REF ]]; then + HEAD_SHA=$(git rev-parse HEAD^1 || true) +else + TARGET_BRANCH=${GITHUB_BASE_REF} + git fetch --depth=1 origin "${TARGET_BRANCH}":"${TARGET_BRANCH}" + HEAD_SHA=$(git rev-parse "${TARGET_BRANCH}" || true) +fi + +if [[ -z $HEAD_SHA ]]; then + echo "::warning::Unable to determine the head sha: $HEAD_SHA." + echo "::warning::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'" + exit 1 +else + echo "Using head sha: $HEAD_SHA..." + if [[ -z "$INPUT_FILES" ]]; then + echo "Getting diff..." + ADDED=$(git diff --diff-filter=A --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + COPIED=$(git diff --diff-filter=C --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + DELETED=$(git diff --diff-filter=D --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + MODIFIED=$(git diff --diff-filter=M --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + RENAMED=$(git diff --diff-filter=R --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + CHANGED=$(git diff --diff-filter=T --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + UNMERGED=$(git diff --diff-filter=U --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + UNKNOWN=$(git diff --diff-filter=X --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + ALL_CHANGED=$(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + ALL_MODIFIED_FILES=$(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | tr "\n" "$INPUT_SEPARATOR" | sed -E "s/($INPUT_SEPARATOR)$//") + else + ADDED_ARRAY=() + COPIED_ARRAY=() + DELETED_ARRAY=() + MODIFIED_ARRAY=() + RENAMED_ARRAY=() + CHANGED_ARRAY=() + UNMERGED_ARRAY=() + UNKNOWN_ARRAY=() + ALL_CHANGED_ARRAY=() + ALL_MODIFIED_FILES_ARRAY=() + for path in ${INPUT_FILES} + do + echo "Checking for file changes: \"${path}\"..." + IFS=" " + # shellcheck disable=SC2207 + ADDED_ARRAY+=($(git diff --diff-filter=A --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + COPIED_ARRAY+=($(git diff --diff-filter=C --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + DELETED_ARRAY+=($(git diff --diff-filter=D --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + MODIFIED_ARRAY+=($(git diff --diff-filter=M --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + RENAMED_ARRAY+=($(git diff --diff-filter=R --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + CHANGED_ARRAY+=($(git diff --diff-filter=T --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + UNMERGED_ARRAY+=($(git diff --diff-filter=U --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + UNKNOWN_ARRAY+=($(git diff --diff-filter=X --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + ALL_CHANGED_ARRAY+=($(git diff --diff-filter="*ACDMRTUX" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + # shellcheck disable=SC2207 + ALL_MODIFIED_FILES_ARRAY+=($(git diff --diff-filter="ACM" --name-only "$HEAD_SHA" | grep -E "(${path})" | xargs || true)) + done + + # shellcheck disable=SC2001 + ADDED=$(echo "${ADDED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + COPIED=$(echo "${COPIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + DELETED=$(echo "${DELETED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + MODIFIED=$(echo "${MODIFIED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + RENAMED=$(echo "${RENAMED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + CHANGED=$(echo "${CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + UNMERGED=$(echo "${UNMERGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + UNKNOWN=$(echo "${UNKNOWN_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + ALL_CHANGED=$(echo "${ALL_CHANGED_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + # shellcheck disable=SC2001 + ALL_MODIFIED_FILES=$(echo "${ALL_MODIFIED_FILES_ARRAY[*]}" | sed 's/ */'"$INPUT_SEPARATOR"'/g') + fi +fi +echo "Added files: $ADDED" +echo "Copied files: $COPIED" +echo "Deleted files: $DELETED" +echo "Modified files: $MODIFIED" +echo "Renamed files: $RENAMED" +echo "Changed files: $CHANGED" +echo "Unmerged files: $UNMERGED" +echo "Unknown files: $UNKNOWN" +echo "All changed files: $ALL_CHANGED" +echo "All modified files: $ALL_MODIFIED_FILES" + +if [[ -n "$INPUT_FILES" ]]; then + # shellcheck disable=SC2001 + ALL_INPUT_FILES=$(echo "$INPUT_FILES" | tr "\n" " " | xargs) + + echo "Input files: ${ALL_INPUT_FILES[*]}" + echo "Matching modified files: ${ALL_MODIFIED_FILES[*]}" + if [[ -n "$ALL_MODIFIED_FILES" ]]; then + echo "::set-output name=any_changed::true" + else + echo "::set-output name=any_changed::false" + fi +fi + +echo "::set-output name=added_files::$ADDED" +echo "::set-output name=copied_files::$COPIED" +echo "::set-output name=deleted_files::$DELETED" +echo "::set-output name=modified_files::$MODIFIED" +echo "::set-output name=renamed_files::$RENAMED" +echo "::set-output name=changed_files::$CHANGED" +echo "::set-output name=unmerged_files::$UNMERGED" +echo "::set-output name=unknown_files::$UNKNOWN" +echo "::set-output name=all_changed_files::$ALL_CHANGED" +echo "::set-output name=all_modified_files::$ALL_MODIFIED_FILES"