Skip to content

Commit

Permalink
Merge pull request #15 from yumemi-inc/support_all_event
Browse files Browse the repository at this point in the history
Support all events
  • Loading branch information
hkusu authored Dec 21, 2023
2 parents cb3e699 + da5de3d commit 158a265
Showing 1 changed file with 29 additions and 6 deletions.
35 changes: 29 additions & 6 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,23 @@ inputs:
required: false
default: 'Report from Gradle Dependency Diff Report action'
head-ref:
description: 'Target commit reference.'
description: 'Current branch, tag, or commit SHA to compare with base.'
required: false
default: ${{ github.sha }}
base-ref:
description: 'Branch, tag, or commit SHA as a basis for comparison.'
required: false
default: |-
${{
(github.event_name == 'pull_request' && github.base_ref) ||
(github.event_name == 'push' && (startsWith(github.event.before, '0000') && github.event.repository.default_branch || github.event.before)) ||
(github.event_name == 'merge_group' && github.event.merge_group.base_sha) ||
github.event.repository.default_branch
}}
use-merge-base:
description: 'Whether to compare with the latest common commit.'
required: false
default: 'false'
outputs:
exists-diff:
description: 'Whether there are any differences in dependencies.'
Expand All @@ -43,21 +57,22 @@ runs:
SCRIPT: ${{ inputs.script }}
REPORT_TITLE: ${{ inputs.report-title }}
HEAD_REF: ${{ inputs.head-ref }}
BASE_REF: ${{ inputs.base-ref }}
USE_MERGE_BASE: ${{ inputs.use-merge-base }}
IS_VALID_EVENT: ${{ contains(fromJSON('["pull_request","pull_request_target","merge_group"]'), github.event_name) }}
GH_REPO: ${{ github.repository }} # for GitHub CLI
GH_TOKEN: ${{ github.token }} # for GitHub CLI
run: |
echo "::debug::git version: $(git --version)"
echo "::debug::gh version: $(gh --version | tr '\n' ' ')"
echo "::debug::jq version: $(jq --version)"
source "$GITHUB_ACTION_PATH/raise_error.sh"
readonly WORK_DIR="$GITHUB_ACTION_PATH"
mkdir "$WORK_DIR/tools"
mkdir "$WORK_DIR/deps"
if [ "$IS_VALID_EVENT" != 'true' ]; then raise_error "This action supports 'pull_request', 'pull_request_target' and 'merge_group' events."; fi
modules="$(echo "$MODULES" | xargs)"
configuration="$(echo "$CONFIGURATION" | xargs)"
Expand Down Expand Up @@ -92,15 +107,23 @@ runs:
raise_error "Incorrect checksum for dependency-tree-diff.jar."
fi
if [ -z "$HEAD_REF" ]; then raise_error "Specify 'head-ref' input."; fi
if [[ -z "$HEAD_REF" || -z "$BASE_REF" ]]; then raise_error "Specify 'head-ref' and 'base-ref' inputs."; fi
gh repo clone "$GH_REPO" "$WORK_DIR/sources" -- --depth 1 --no-checkout > /dev/null 2>&1 || raise_error "May not have 'contents: read' permission."
# ref: https://github.com/actions/checkout/blob/72f2cec99f417b1a1c5e2e88945068983b7965f9/src/git-auth-helper.ts#L55-L63
cd "$WORK_DIR/sources" && git config --local 'http.https://github.com/.extraheader' "AUTHORIZATION: basic $(echo -n "x-access-token:$GH_TOKEN"|base64)"
git fetch -q --depth 2 origin "$HEAD_REF" > /dev/null 2>&1 || raise_error "'head-ref' input is not valid."
git fetch -q --depth 1 origin "$HEAD_REF" > /dev/null 2>&1 || raise_error "'head-ref' input is not valid."
head_sha="$(git rev-parse FETCH_HEAD)"
base_sha="$(git rev-parse FETCH_HEAD~1)"
git fetch -q --depth 1 origin "$BASE_REF" > /dev/null 2>&1 || raise_error "'base-ref' input is not valid."
base_sha="$(git rev-parse FETCH_HEAD)"
if [ "$USE_MERGE_BASE" == 'true' ]; then
merge_base_sha="$(gh api "repos/{owner}/{repo}/compare/${base_sha}...${head_sha}" | jq -r '.merge_base_commit.sha')"
git fetch -q --depth 1 origin "$merge_base_sha"
base_sha="$(git rev-parse FETCH_HEAD)"
fi
# do not create a file with the input string
function create_file_name() {
Expand Down

0 comments on commit 158a265

Please sign in to comment.