This is an automated email from the ASF dual-hosted git repository.
sijie pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pulsar-test-infra.git
The following commit(s) were added to refs/heads/master by this push:
new e199a8c Move diff-only action to pulsar-test-infra (#1)
e199a8c is described below
commit e199a8cf9f1e86dd16526609fd0a3e1b666bad38
Author: Sijie Guo <[email protected]>
AuthorDate: Tue Feb 4 17:50:43 2020 -0800
Move diff-only action to pulsar-test-infra (#1)
*Motivation*
The `diff-only` is currently hosted in a personal project -
https://github.com/sijie/pulsar-github-actions.
Move it to ASF repo.
---
README.md | 6 +++++-
diff-only/Dockerfile | 15 +++++++++++++++
diff-only/README.md | 23 +++++++++++++++++++++++
diff-only/entrypoint.sh | 38 ++++++++++++++++++++++++++++++++++++++
4 files changed, 81 insertions(+), 1 deletion(-)
diff --git a/README.md b/README.md
index 916446c..d560eba 100644
--- a/README.md
+++ b/README.md
@@ -1,3 +1,7 @@
# Apache Pulsar Test Infrastructure
-This repo is used for keeping all the scripts and github actions for running
Pulsar test infrastructure.
\ No newline at end of file
+This repo is used for keeping all the scripts and github actions for running
Pulsar test infrastructure.
+
+## Github Actions
+
+- [diff-only](diff-only/README.md) action
\ No newline at end of file
diff --git a/diff-only/Dockerfile b/diff-only/Dockerfile
new file mode 100644
index 0000000..3dd8693
--- /dev/null
+++ b/diff-only/Dockerfile
@@ -0,0 +1,15 @@
+FROM alpine:latest
+
+LABEL version="1.0.0"
+LABEL repository="http://github.com/apache/pulsar-test-infra"
+LABEL homepage="http://github.com/apache/pulsar-test-infra/diff-only"
+LABEL maintainer="Apache Pulsar Team"
+LABEL "com.github.actions.name"="Diff only"
+LABEL "com.github.actions.description"="Check if changes were only made in
certain files/directories."
+LABEL "com.github.actions.icon"="git-commit"
+LABEL "com.github.actions.color"="gray-dark"
+
+RUN apk add --update git jq bash && rm -rf /var/cache/apk/*
+
+COPY entrypoint.sh /entrypoint.sh
+ENTRYPOINT ["/entrypoint.sh"]
\ No newline at end of file
diff --git a/diff-only/README.md b/diff-only/README.md
new file mode 100644
index 0000000..396fa3e
--- /dev/null
+++ b/diff-only/README.md
@@ -0,0 +1,23 @@
+# Diff Only Filter for GitHub Actions
+
+This action includes a filter to check if only certain files or directories
are changed in a range of commits.
+
+If only the provided files and directories are changed, the action will set
`changed_only` to `yes`.
+Otherwise, `changed_only` is set to `false`.
+
+## Examples
+
+```
+ - name: Check if this pull request only changes documentation
+ id: docs
+ uses: apache/pulsar-test-infra/diff-only@master
+ with:
+ args: site2
+
+ - name: Set up JDK 1.8
+ uses: actions/setup-java@v1
+ # skip this step if this pull request only changes documentation
+ if: steps.docs.outputs.changed_only == 'no'
+ with:
+ java-version: 1.8
+```
diff --git a/diff-only/entrypoint.sh b/diff-only/entrypoint.sh
new file mode 100755
index 0000000..2084b30
--- /dev/null
+++ b/diff-only/entrypoint.sh
@@ -0,0 +1,38 @@
+#!/bin/bash
+
+read -r -a TARGET_DIRS <<< "$*"
+
+cat ${GITHUB_EVENT_PATH}
+COMMITS=$(jq '.pull_request.commits' "${GITHUB_EVENT_PATH}")
+echo "COMMITS: ${COMMITS}"
+
+git --version
+git rev-parse --abbrev-ref HEAD
+
+CHANGED_DIRS=$(git diff --dirstat=files,0 HEAD~${COMMITS} | awk '{ print $2 }')
+echo "CHANGED_DIRS are : ${CHANGED_DIRS}"
+
+found_changed_dir_not_in_target_dirs="no"
+for changed_dir in ${CHANGED_DIRS}
+do
+ matched="no"
+ for target_dir in "${TARGET_DIRS[@]}"
+ do
+ if [[ ${changed_dir} == "${target_dir}"* ]]; then
+ matched="yes"
+ break
+ fi
+ done
+ if [[ ${matched} == "no" ]]; then
+ found_changed_dir_not_in_target_dirs="yes"
+ break
+ fi
+done
+
+if [[ ${found_changed_dir_not_in_target_dirs} == "yes" ]]; then
+ echo "Changes ${CHANGED_DIRS} not only in $*, setting 'changed_only' to
'no'"
+ echo ::set-output name=changed_only::no
+else
+ echo "Changes ${CHANGED_DIRS} only in $*, setting 'changed_only' to 'yes'"
+ echo ::set-output name=changed_only::yes
+fi
\ No newline at end of file