Skip to content

Commit

Permalink
Init
Browse files Browse the repository at this point in the history
  • Loading branch information
mitsuharu-kojima committed Mar 18, 2022
0 parents commit 0a301bf
Show file tree
Hide file tree
Showing 3 changed files with 137 additions and 0 deletions.
57 changes: 57 additions & 0 deletions .github/workflows/test.yml
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
34 changes: 34 additions & 0 deletions README.md
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
```
46 changes: 46 additions & 0 deletions action.yml
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 }}

0 comments on commit 0a301bf

Please sign in to comment.