Skip to content

Commit

Permalink
feat(get-modified-packages): support retrieving diffs without fetchin…
Browse files Browse the repository at this point in the history
…g all (#299)

Signed-off-by: M. Fatih Cırıt <[email protected]>
  • Loading branch information
xmfcx authored Jun 12, 2024
1 parent 45b31c5 commit 9a6e0b7
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
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

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

0 comments on commit 9a6e0b7

Please sign in to comment.