Update ngrok.yaml #2
Workflow file for this run
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
name: Debugging with SSH | |
on: push | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
steps: | |
- uses: actions/checkout@v2 # It's recommended to use the latest action version | |
- name: Try Build | |
run: ./not-exist-file.sh || echo "Build script not found, build step failed, proceeding to SSH setup for debugging..." | |
- name: Start SSH via Ngrok | |
if: ${{ failure() }} | |
run: | | |
# The script content goes here, starting with the shebang line. For example: | |
#!/bin/bash | |
if [[ -z "$NGROK_TOKEN" ]]; then | |
echo "Please set 'NGROK_TOKEN'" | |
exit 2 | |
fi | |
if [[ -z "$USER_PASS" ]]; then | |
echo "Please set 'USER_PASS' for user: $USER" | |
exit 3 | |
fi | |
echo "### Install ngrok ###" | |
wget -q https://bin.equinox.io/c/bNyj1mQVY4c/ngrok-v3-stable-linux-amd64.tgz | |
sudo tar xvzf ngrok-v3-stable-linux-amd64.tgz -C /usr/local/bin | |
sudo chmod +x /usr/local/bin/ngrok | |
echo "### Update user: $USER password ###" | |
echo -e "$USER_PASS\n$USER_PASS" | sudo passwd "$USER" | |
echo "### Start ngrok proxy for 22 port ###" | |
rm -f .ngrok.log | |
/usr/local/bin/ngrok authtoken "$NGROK_TOKEN" | |
/usr/local/bin/ngrok tcp 22 --log ".ngrok.log" & | |
sleep 10 | |
HAS_ERRORS=$(grep "command failed" < .ngrok.log) | |
if [[ -z "$HAS_ERRORS" ]]; then | |
echo "" | |
echo "==========================================" | |
echo "To connect: $(grep -o -E "tcp://(.+)" < .ngrok.log | sed "s/tcp:\/\//ssh $USER@/" | sed "s/:/ -p /")" | |
echo "==========================================" | |
else | |
echo "$HAS_ERRORS" | |
exit 4 | |
fi | |
env: | |
NGROK_TOKEN: ${{ secrets.NGROK_TOKEN }} | |
USER_PASS: ${{ secrets.USER_PASS }} | |
- name: Don't kill instance | |
if: ${{ failure() }} | |
run: sleep 1h |