Skip to content

Commit

Permalink
feat: add guide for retrieving changed files for tags (#955)
Browse files Browse the repository at this point in the history
  • Loading branch information
jackton1 committed Jan 19, 2023
1 parent 0953088 commit f487fc6
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 0 deletions.
50 changes: 50 additions & 0 deletions README.md
Expand Up @@ -403,6 +403,56 @@ See [inputs](#inputs) for more information.

</details>

<details>
<summary>Get all changed files between the previous tag and the current tag</summary>

```yaml
...
on:
push:
tags:
- 'v*'

jobs:
release:
name: Release
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
with:
fetch-depth: 0

- name: Get Base SHA
id: get-base-sha
run: |
echo "base_sha=$(git rev-parse "$(git tag --sort=-v:refname | head -n 2 | tail -n 1)")" >> $GITHUB_OUTPUT
- name: Get changed files
id: changed-files
uses: tj-actions/changed-files@v35
with:
base_sha: ${{ steps.get-base-sha.outputs.base_sha }}

- name: Get changed files in the .github folder
id: changed-files-specific
uses: tj-actions/changed-files@v35
with:
base_sha: ${{ steps.get-base-sha.outputs.base_sha }}
files: .github/**

- name: Run step if any file(s) in the .github folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: |
echo "One or more files in the .github folder has changed."
echo "List all the files that have changed: ${{ steps.changed-files-specific.outputs.all_changed_files }}"
...
```

See [inputs](#inputs) for more information.

</details>

<details>
<summary>Get all changed files for a repository located in a different path</summary>

Expand Down
9 changes: 9 additions & 0 deletions diff-sha.sh
Expand Up @@ -8,6 +8,11 @@ EXTRA_ARGS="--no-tags --prune --no-recurse-submodules"
PREVIOUS_SHA=""
CURRENT_SHA=""
DIFF="..."
IS_TAG="false"

if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
IS_TAG="true"
fi

if [[ "$GITHUB_REF" == "refs/tags/"* ]]; then
EXTRA_ARGS="--prune --no-recurse-submodules"
Expand Down Expand Up @@ -132,6 +137,10 @@ if [[ -z $GITHUB_EVENT_PULL_REQUEST_BASE_REF ]]; then
fi
else
PREVIOUS_SHA=$INPUT_BASE_SHA

if [[ "$IS_TAG" == "true" ]]; then
TARGET_BRANCH=$(git describe --tags "$PREVIOUS_SHA")
fi
fi

echo "::debug::Target branch $TARGET_BRANCH..."
Expand Down

0 comments on commit f487fc6

Please sign in to comment.