Issue
I am facing an issue with reading the input from GitHub actions.
I have created a cli in which I need to provide some input while executing since I don't want to interact with the cli and provide the input directly in the command. I am using '<' for providing it.
I have tried below options but none of them works in github actions (all of them work fine in my local environment).
my-cli <<< name
my-cli < name.txt
(where name.txt contains the name)printf name | my-cli
cat name.txt | my-cli
(where name.txt contains the name)
Assuming, my-cli expects some string (name).
I tested all these in my local Ubuntu, it works fine but not with GitHub actions.
my workflow.yml file
# This is a basic workflow that is manually triggered
name: Some name
on:
schedule:
- cron: "0 0 * * *"
workflow_dispatch:
jobs:
solve:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2
- name: Apply permissions
run: chmod +x scripts/*.sh
- name: Setup
env:
name: ${{ vars.USERNAME }}
run: scripts/setup.sh
shell: bash
my setup.sh file
#!/bin/bash
echo $username
echo -e "$creds" >> auth.txt
# cat auth.txt | leetcode user -c
my-cli < auth.txt
# my-cli <<< $username
rm auth.txt
The output is empty name: But it should have name: someName upon execution.
Can someone please let me know if I am missing something? It works fine with local env
Solution
You may need to set Github Action secret first.
(Github > Settings > Security > Secrets and variables > Actions)
After that, you can retrieve them by specifying ${{ secrets.<your_secret_name> }}
So, in the Setup
step, maybe can do something like this:
- name: Setup
env:
name: ${{ vars.USERNAME }}
shell: bash
run: |
echo "env.name: ${{ env.name }}"
echo "whoami: $(whoami)"
echo ${{ secrets.creds }} | leetcode user -c
Answered By - ktc Answer Checked By - Pedro (WPSolving Volunteer)