-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move files over from main Antrea repository
Signed-off-by: Antonin Bas <abas@vmware.com>
- Loading branch information
1 parent
7a52732
commit 2ef01c4
Showing
4 changed files
with
118 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
FROM ubuntu:20.04 | ||
|
||
LABEL maintainer="Antrea <projectantrea-dev@googlegroups.com>" | ||
LABEL description="A Docker-based Github action to determine if changes were made outside of a provided path exclusion list." | ||
|
||
RUN apt-get update && \ | ||
DEBIAN_FRONTEND=noninteractive apt-get install -y --no-install-recommends git jq && \ | ||
rm -rf /var/lib/apt/lists/* | ||
|
||
COPY entrypoint.sh /entrypoint.sh | ||
|
||
ENTRYPOINT ["/entrypoint.sh"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,26 @@ | ||
# has-changes | ||
A GitHub action to detect if the diff for a push or pull_request event has changes outside of a list of paths | ||
# "Has Changes" Docker Action | ||
|
||
This action sets a boolean output (`has_changes`) if the diff (`push` or | ||
`pull_request` event) includes changes outside of a provided list of paths. | ||
|
||
## Inputs | ||
|
||
The list of paths to exclude. The action will use Bash pattern matching, so | ||
wildcards (`*`) are supported. | ||
|
||
## Outputs | ||
|
||
### `has_changes` | ||
|
||
Whether ('yes' or 'no') the diff includes changes outside of the provided list | ||
of paths. | ||
|
||
## Example usage | ||
|
||
```yaml | ||
uses: antrea-io/antrea/ci/gh-actions/has-changes@main | ||
with: | ||
args: docs *.md ci | ||
``` | ||
|
||
Make sure to checkout the repo first. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
# action.yml | ||
name: 'Has Changes' | ||
description: 'Checks if diff includes changes outside of a provided path exclusion list' | ||
outputs: | ||
has_changes: | ||
description: 'Whether (yes/no) the diff includes changes' | ||
runs: | ||
using: 'docker' | ||
image: 'Dockerfile' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
#!/usr/bin/env bash | ||
# Copyright 2022 Antrea Authors. | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
|
||
|
||
set -eo pipefail | ||
|
||
read -r -a PATTERNS <<< "$*" | ||
|
||
cat "$GITHUB_EVENT_PATH" | ||
|
||
PR_BASE_SHA=$(jq -r '.pull_request.base.sha' "$GITHUB_EVENT_PATH") | ||
BEFORE=$(jq -r '.before' "$GITHUB_EVENT_PATH") | ||
if [[ $PR_BASE_SHA != "" && $PR_BASE_SHA != "null" ]]; then # PR events | ||
SHA=$PR_BASE_SHA | ||
elif [[ $BEFORE != "" && $BEFORE != "null" ]]; then # push events | ||
SHA=$BEFORE | ||
else | ||
echo "This does not appear to be a PR or a push event" | ||
echo "Setting 'has_changes' to 'yes'" | ||
echo "::set-output name=has_changes::yes" | ||
exit 0 | ||
fi | ||
echo "BASE SHA: $SHA" | ||
|
||
CHANGED_FILES=$(git diff --name-only "$SHA" HEAD) || rc=$? | ||
|
||
if [[ $rc -ne 0 ]]; then | ||
echo "Error when running 'git diff'" | ||
echo "This is expected when the repo was not checked-out properly, or after a force push" | ||
echo "Setting 'has_changes' to 'yes'" | ||
echo "::set-output name=has_changes::yes" | ||
exit 0 | ||
fi | ||
|
||
echo "CHANGED_FILES are:" | ||
echo "$CHANGED_FILES" | ||
|
||
has_changes=false | ||
for changed_file in $CHANGED_FILES; do | ||
matched=false | ||
for pattern in "${PATTERNS[@]}"; do | ||
if [[ "$changed_file" == $pattern ]]; then | ||
matched=true | ||
break | ||
fi | ||
done | ||
if ! $matched; then | ||
has_changes=true | ||
break | ||
fi | ||
done | ||
|
||
if $has_changes; then | ||
echo "Setting 'has_changes' to 'yes'" | ||
echo "::set-output name=has_changes::yes" | ||
else | ||
echo "Setting 'has_changes' to 'no'" | ||
echo "::set-output name=has_changes::no" | ||
fi |