Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(get-modified-packages): support retrieving diffs without fetching all #299

Merged
merged 2 commits into from
Jun 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 24 additions & 1 deletion get-modified-packages/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ This action get the list of ROS packages modified in the pull request.

## Usage

### Basic

```yaml
jobs:
get-modified-packages:
runs-on: ubuntu-latest
steps:
- name: Check out repository
uses: actions/checkout@v3
uses: actions/checkout@v4
with:
fetch-depth: 0
HansRobo marked this conversation as resolved.
Show resolved Hide resolved

Expand All @@ -19,6 +21,27 @@ jobs:
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
```

### Fetch only the PR branch and all PR commits

```yaml
jobs:
get-modified-packages:
runs-on: ubuntu-latest
steps:
- name: Set PR fetch depth
run: echo "PR_FETCH_DEPTH=$(( ${{ github.event.pull_request.commits }} + 1 ))" >> "${GITHUB_ENV}"

- name: Checkout PR branch and all PR commits
uses: actions/checkout@v4
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: ${{ env.PR_FETCH_DEPTH }}

- name: Get modified packages
id: get-modified-packages
uses: autowarefoundation/autoware-github-actions/get-modified-packages@v1
```

## Inputs

| Name | Required | Description |
Expand Down
10 changes: 8 additions & 2 deletions get-modified-packages/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: get-modified-packages
description: ""

inputs:
base-branch:
base-ref:
description: ""
required: false
default: ${{ github.base_ref }}
Expand All @@ -20,10 +20,16 @@ runs:
git config --global --add safe.directory "$GITHUB_WORKSPACE"
shell: bash

- name: Fetch the base branch with enough history for a common merge-base commit
run: |
git fetch origin ${{ inputs.base-ref }}
shell: bash

- name: Get modified packages
id: get-modified-packages
run: |
echo "modified-packages=$(${GITHUB_ACTION_PATH}/get-modified-packages.sh origin/${{ inputs.base-branch }})" >> $GITHUB_OUTPUT
modified_packages=$(${GITHUB_ACTION_PATH}/get-modified-packages.sh origin/${{ inputs.base-ref }})
echo "modified-packages=$modified_packages" >> $GITHUB_OUTPUT
shell: bash

- name: Show result
Expand Down
10 changes: 6 additions & 4 deletions get-modified-packages/get-modified-packages.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
# Search for packages that have been modified from the base branch.
# Usage: get-modified-packages.sh <base_branch>

set -e

# Parse arguments
args=()
while [ "${1-}" != "" ]; do
Expand All @@ -15,6 +13,7 @@ while [ "${1-}" != "" ]; do
shift
done

# example: base_branch="origin/main"
base_branch="${args[0]}"

# Check args
Expand Down Expand Up @@ -49,8 +48,11 @@ function find_package_dir() {
return 1
}

# Find modified files from base branch
modified_files=$(git diff --name-only "$base_branch"...HEAD)
# Find modified files from the base branch
if ! modified_files=$(git diff --name-only "$base_branch"...HEAD); then
echo -e "\e[31mFailed to determine modified files. Please check if the base branch exists and fetch depth is sufficient.\e[m"
exit 1
fi

# Find modified packages
modified_package_dirs=()
Expand Down
Loading