-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add a PRNG Action * update * update * update * comments * update
- Loading branch information
1 parent
d117c60
commit 02b4d71
Showing
1 changed file
with
31 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,31 @@ | ||
name: "RNG" | ||
description: "Generate random bytes using /dev/urandom. WARNING: only use for non-cryptographic purposes (the results will show in logs)." | ||
inputs: | ||
length: | ||
description: "Number of raw random bytes to generate." | ||
default: 16 | ||
required: false | ||
outputs: | ||
random: | ||
description: > | ||
The output of the RNG encoded in hexadecimal. | ||
Note: Due to the encoding, the length of the string will be twice as long as the input length requested by the user. | ||
value: "${{ steps.prng.outputs.result }}" | ||
|
||
runs: | ||
using: "composite" | ||
steps: | ||
- name: Generate random | ||
id: prng | ||
env: | ||
LENGTH: "${{ inputs.length }}" | ||
run: | | ||
set -euo pipefail | ||
# Note: if we need to support different encoding, we can use | ||
# `head -c"$LENGTH" /dev/urandom | xxd ...` instead. | ||
# -l: the number of bytes | ||
# -c: the number of bytes displayed per column | ||
value=$(xxd -p -l "$LENGTH" -c "$LENGTH" /dev/urandom) | ||
echo "::set-output name=result::$value" | ||