Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add a RNG Action #503

Merged
merged 6 commits into from
Jul 11, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
31 changes: 31 additions & 0 deletions .github/actions/rng/action.yml
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"