-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaction.yml
66 lines (66 loc) · 2.58 KB
/
action.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
name: "git add a report if it has changed"
description: "The files are only added if there is no 'latest.<fileExtension>' file (or 'latest' dir) or if it has changed"
inputs:
filePath:
description: 'The path to the report file or dir'
required: true
destinationDir:
description: 'The destination directory for the report type. Every report has to be in its own directory'
required: true
keepAllVersions:
description: 'Whether to keep timestamped version if set to true. Otherwise only the latest version will be saved and overwritten.'
default: 'true'
required: false
reportIsDirectory:
description: 'Set to true if the report is not a file but a directory'
default: 'false'
required: false
runs:
using: 'composite'
steps:
- name: Check that file path does not target a directory
if: inputs.reportIsDirectory == 'false'
shell: bash
run: |
if [ -d "${{ inputs.filePath }}" ]; then
echo "File is a directory. Set input 'reportIsDirectory' to 'true'."
exit 1
fi
- name: Prepare report committing for files
shell: bash
id: preparation
run: |
mkdir -p ${{ inputs.destinationDir }}
if ${{ inputs.reportIsDirectory }}; then
extension=
rm -rf ${{ inputs.destinationDir }}/latest
else
filepath=${{ inputs.filePath }}
extension=.${filepath##*.}
fi
echo "EXTENSION=$extension" >> $GITHUB_OUTPUT
cp -r ${{ inputs.filePath }} ${{ inputs.destinationDir }}/latest$extension
- name: Check if report has changed
shell: bash
id: file-check
run: |
if git status -s --untracked-files | grep " latest${{ steps.preparation.outputs.EXTENSION }}"; then
echo "file_changed=true" >> $GITHUB_OUTPUT
else
echo "file_changed=false" >> $GITHUB_OUTPUT
fi
working-directory: ${{ inputs.destinationDir }}
- name: Add latest report
shell: bash
run: |
git add latest${{ steps.preparation.outputs.EXTENSION }}
if: steps.file-check.outputs.file_changed == 'true'
working-directory: ${{ inputs.destinationDir }}
- name: Add timestamped report
shell: bash
run: |
NOW=$(TZ=Europe/Berlin date +'%Y-%m-%dT%H%M%S')
cp -r latest${{ steps.preparation.outputs.EXTENSION }} $NOW${{ steps.preparation.outputs.EXTENSION }}
git add $NOW${{ steps.preparation.outputs.EXTENSION }}
if: steps.file-check.outputs.file_changed == 'true' && inputs.keepAllVersions == 'true'
working-directory: ${{ inputs.destinationDir }}