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: add support for using time based filtering. #588

Merged
merged 7 commits into from
Aug 21, 2022
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
30 changes: 25 additions & 5 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ jobs:
echo "${{ toJSON(steps.changed-files.outputs) }}"
shell:
bash

- name: Exit with 1 if no error is raised
if: steps.changed-files.outcome != 'failure'
run: |
Expand All @@ -187,7 +187,7 @@ jobs:
echo "${{ toJSON(steps.changed-files-specific.outputs) }}"
shell:
bash

- name: Exit with 1 if no error is raised
if: steps.changed-files-specific.outcome != 'failure'
run: |
Expand Down Expand Up @@ -219,7 +219,7 @@ jobs:
echo "${{ toJSON(steps.changed-files.outputs) }}"
shell:
bash

- name: Exit with 1 if no error is raised
if: steps.changed-files.outcome != 'failure'
run: |
Expand All @@ -239,7 +239,7 @@ jobs:
echo "${{ toJSON(steps.changed-files-specific.outputs) }}"
shell:
bash

- name: Exit with 1 if no error is raised
if: steps.changed-files-specific.outcome != 'failure'
run: |
Expand Down Expand Up @@ -302,6 +302,26 @@ jobs:
echo '${{ toJSON(steps.changed-files-dir-names.outputs) }}'
shell:
bash
- name: Run changed-files since 2022-08-19
id: changed-files-since
uses: ./
with:
since: "2022-08-19"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-since.outputs) }}'
shell:
bash
- name: Run changed-files until 2022-08-20
id: changed-files-until
uses: ./
with:
until: "2022-08-21"
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-until.outputs) }}'
shell:
bash
- name: Run changed-files with forward slash separator
id: changed-files-forward-slash
uses: ./
Expand Down Expand Up @@ -372,7 +392,7 @@ jobs:
base_sha: d1c0ee4
sha: 4d04215
include_all_old_new_renamed_files: true
- name: Show output
- name: Show output
run: |
echo '${{ toJSON(steps.changed-files-all-old-new-renamed-files-1.outputs) }}'
shell:
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -347,6 +347,18 @@ Support this project with a :star:
uses: tj-actions/changed-files@v27
with:
json: "true"

- name: Run changed-files since 2022-08-19
id: changed-files-since
uses: tj-actions/changed-files@v27
with:
since: "2022-08-19"

- name: Run changed-files until 2022-08-20
id: changed-files-until
uses: tj-actions/changed-files@v27
with:
until: "2022-08-20"
```

<img width="1147" alt="Screen Shot 2021-11-19 at 4 59 21 PM" src="https://user-images.githubusercontent.com/17484350/142696936-8b7ca955-7ef9-4d53-9bdf-3e0008e90c3f.png">
Expand Down
23 changes: 21 additions & 2 deletions action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,12 @@ inputs:
description: "Use the last commit on the remote branch as the base_sha for push event."
required: false
default: "false"
since:
description: "Get changed files for commits whose timestamp is older than the given time"
required: false
until:
description: "Get changed files for commits whose timestamp is earlier than the given time"
required: false
path:
description: "Specify a relative path under $GITHUB_WORKSPACE to locate the repository"
required: false
Expand Down Expand Up @@ -152,7 +158,10 @@ runs:
steps:
- run: |
# "Set base sha..."
if [[ -n "${{ inputs.base_sha }}" ]]; then
if [[ -n "${{ inputs.since }}" ]]; then
BASE_SHA=$(git log --format="%H" --date=local --since="${{ inputs.since }}" --reverse | head -n 1)
echo "::set-output name=base_sha::$BASE_SHA"
elif [[ -n "${{ inputs.base_sha }}" ]]; then
echo "::set-output name=base_sha::${{ inputs.base_sha }}"
elif [[ "${{ inputs.since_last_remote_commit }}" == "true" && "${{ github.event.forced }}" == "true" && "${{ github.event.before }}" != "0000000000000000000000000000000000000000" ]]; then
LAST_REMOTE_COMMIT=$(git rev-parse $(git branch -r --sort=-committerdate | head -1))
Expand All @@ -164,6 +173,16 @@ runs:
fi
id: base-sha
shell: bash
- run: |
# "Set the sha..."
if [[ -n "${{ inputs.until }}" ]]; then
SHA=$(git log -1 --format="%H" --date=local --until="${{ inputs.until }}")
echo "::set-output name=sha::$SHA"
else
echo "::set-output name=sha::${{ inputs.sha }}"
fi
id: sha
shell: bash
- run: |
# "Calculating the previous and current SHA..."
bash $GITHUB_ACTION_PATH/diff-sha.sh
Expand All @@ -178,7 +197,7 @@ runs:
GITHUB_WORKSPACE: ${{ github.workspace }}
# INPUT_<VARIABLE_NAME> is not available in Composite run steps
# https://github.community/t/input-variable-name-is-not-available-in-composite-run-steps/127611
INPUT_SHA: ${{ inputs.sha }}
INPUT_SHA: ${{ steps.sha.outputs.sha }}
INPUT_BASE_SHA: ${{ steps.base-sha.outputs.base_sha }}
INPUT_TOKEN: ${{ inputs.token }}
INPUT_PATH: ${{ inputs.path }}
Expand Down
7 changes: 3 additions & 4 deletions diff-sha.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ fi

echo "Verifying git version..."

function __version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
function __version() {
echo "$@" | awk -F. '{ printf("%d%03d%03d%03d\n", $1,$2,$3,$4); }';
}

GIT_VERSION=$(git --version | awk '{print $3}'); exit_status=$?
GIT_VERSION=$(git --version | awk '{print $3}'); exit_status=$?

if [[ $exit_status -ne 0 ]]; then
echo "::error::git not installed"
Expand Down Expand Up @@ -122,7 +122,6 @@ fi

if [[ -n "$PREVIOUS_SHA" && -n "$CURRENT_SHA" && "$PREVIOUS_SHA" == "$CURRENT_SHA" && "$INITIAL_COMMIT" == "false" ]]; then
echo "::error::Similar commit hashes detected: previous sha: $PREVIOUS_SHA is equivalent to the current sha: $CURRENT_SHA"
echo "::error::You seem to be missing 'fetch-depth: 0' or 'fetch-depth: 2'. See https://github.com/tj-actions/changed-files#usage"
exit 1
fi

Expand Down