-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 0a301bf
Showing
3 changed files
with
137 additions
and
0 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,57 @@ | ||
name: Test | ||
|
||
on: | ||
pull_request: | ||
branches: [ main ] | ||
workflow_dispatch: | ||
|
||
jobs: | ||
test_is_same: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-20.04, ubuntu-18.04, macos-11, macos-10.15, windows-2016, windows-2019, windows-2022 ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- run: echo 0 > ~/test | ||
shell: bash | ||
- uses: smilerobotics/actions-check-command-output-diff@v1 | ||
id: compare | ||
with: | ||
command: 'echo 0' | ||
command_output: "~/test" | ||
cache_key_prefix: "test-is-same-${{ matrix.os }}" | ||
- run: test "${{ steps.compare.outputs.is_same }}" == "true" | ||
shell: bash | ||
test_is_different: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-20.04, ubuntu-18.04, macos-11, macos-10.15, windows-2016, windows-2019, windows-2022 ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- uses: smilerobotics/actions-check-command-output-diff@v1 | ||
id: compare | ||
with: | ||
command: 'echo $(date)' | ||
command_output: "~/test" | ||
cache_key_prefix: "test-is-different-${{ matrix.os }}" | ||
- run: test "${{ steps.compare.outputs.is_same }}" == "false" | ||
shell: bash | ||
test_is_different_with_no_file: | ||
strategy: | ||
matrix: | ||
os: [ ubuntu-20.04, ubuntu-18.04, macos-11, macos-10.15, windows-2016, windows-2019, windows-2022 ] | ||
runs-on: ${{ matrix.os }} | ||
steps: | ||
- name: Get Date | ||
id: get_date | ||
run: | | ||
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H_%M_%S")" | ||
shell: bash | ||
- uses: smilerobotics/actions-check-command-output-diff@v1 | ||
id: compare | ||
with: | ||
command: 'echo $(date)' | ||
command_output: "~/test" | ||
cache_key_prefix: "test-is-different-with-no-file-${{ matrix.os }}-${{ steps.get_date.outputs.date }}" | ||
- run: test "${{ steps.compare.outputs.is_same }}" == "false" | ||
shell: bash |
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,34 @@ | ||
# check-command-output-diff | ||
|
||
## Description | ||
|
||
An action to run a command and check the difference of the output of the command. | ||
|
||
## Required input | ||
|
||
1. command: Command to run. | ||
1. command_output: Path of the command output file. | ||
1. cache_key_prefix: Key prefix for cache of the command output file. | ||
|
||
## Output | ||
|
||
1. is_same: If old and new output is same, true. | ||
|
||
## Example | ||
|
||
```yaml | ||
jobs: | ||
check: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- run: echo 0 > ~/test | ||
shell: bash | ||
- uses: smilerobotics/actions-check-command-output-diff@v1 | ||
id: compare | ||
with: | ||
command: 'echo 0' | ||
command_output: "~/test" | ||
cache_key_prefix: "test-is-same-${{ matrix.os }}" | ||
- run: echo ${{ steps.compare.outputs.is_same }} | ||
shell: bash | ||
``` |
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,46 @@ | ||
name: 'check-command-output-diff' | ||
description: 'Run command and check diff between old output of the command and new one.' | ||
inputs: | ||
command: | ||
description: 'Command to run.' | ||
required: true | ||
command_output: | ||
description: 'Path of the command output file.' | ||
required: true | ||
cache_key_prefix: | ||
description: 'Key prefix for cache of the command output file.' | ||
required: true | ||
outputs: | ||
is_same: | ||
description: "If old and new output is same, true." | ||
value: ${{ steps.compare.outputs.is_same }} | ||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Get Date | ||
id: get_date | ||
run: | | ||
echo "::set-output name=date::$(/bin/date -u "+%Y-%m-%d-%H_%M_%S")" | ||
shell: bash | ||
- name: Make temp file | ||
id: mktemp | ||
run: | | ||
echo "::set-output name=tempfile::$(mktemp)" | ||
shell: bash | ||
- name: Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ${{ inputs.command_output }} | ||
key: ${{ inputs.cache_key_prefix }}-${{ steps.get_date.outputs.date }} | ||
restore-keys: ${{ inputs.cache_key_prefix }}- | ||
- name: Run command | ||
shell: bash | ||
run: | | ||
${{ inputs.command }} > ${{ steps.mktemp.outputs.tempfile }} | ||
- name: Compare | ||
id: compare | ||
shell: bash | ||
run: | | ||
diff ${{ inputs.command_output }} ${{ steps.mktemp.outputs.tempfile }} && echo "::set-output name=is_same::true" || echo "::set-output name=is_same::false" | ||
mv ${{ steps.mktemp.outputs.tempfile }} ${{ inputs.command_output }} | ||
cat ${{ inputs.command_output }} |