-
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.
Merge pull request #14 from drink7036290/elapsed-time
elapsed time action
- Loading branch information
Showing
5 changed files
with
94 additions
and
37 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
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,51 @@ | ||
name: "Elapsed Time" | ||
description: "Print how many seconds have elapsed since the last call" | ||
|
||
inputs: | ||
statement: | ||
description: "Statement to print" | ||
required: true | ||
|
||
reference: | ||
description: "Optional unique name for the timestamp file" | ||
required: false | ||
default: "generic" | ||
|
||
outputs: | ||
delta: | ||
description: "Time delta in seconds since last call" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Elapsed Time | ||
id: elapsed | ||
shell: bash | ||
run: | | ||
FILE=".elapsed_time_${{ inputs.reference }}" | ||
# 1) Read previous timestamp if present | ||
if [ -f "$FILE" ]; then | ||
last_time="$(cat "$FILE")" | ||
else | ||
last_time="" | ||
fi | ||
# 2) Get current time | ||
current_time=$(date +%s) | ||
# 3) Calculate the delta | ||
if [ -z "$last_time" ]; then | ||
delta=0 | ||
else | ||
delta=$(( current_time - last_time )) | ||
fi | ||
# 4) Print message | ||
echo "Elapsed time for ${{ inputs.statement }}: $delta seconds" | ||
# 5) Expose as output (optional) | ||
echo "delta=$delta" >> "$GITHUB_OUTPUT" | ||
# 6) Write new timestamp | ||
echo "$current_time" > "$FILE" |
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
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
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