-
-
Notifications
You must be signed in to change notification settings - Fork 588
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ci: add environment variable handling in GitHub Actions
- Add a new job `testing-with-env` to the GitHub Actions workflow - Add steps to set up environment variables for public and private SSH keys - Add a step to create a new SSH server using Docker - Add a step to test the SSH connection using the `id_ed25519` key - Add a step to pass a single environment variable to the SSH action - Add a step to pass multiple environment variables to the SSH action - Add a step to use a custom format for environment variables - Add a step to pass all environment variables to the SSH action Signed-off-by: appleboy <[email protected]>
- Loading branch information
Showing
1 changed file
with
123 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 |
---|---|---|
|
@@ -337,3 +337,126 @@ jobs: | |
script: | | ||
whoami | ||
ls -al | ||
testing-with-env: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout code | ||
uses: actions/checkout@v4 | ||
|
||
- name: add public key to env | ||
run: | | ||
echo "PUBLIC_KEY<<EOF" >> $GITHUB_ENV | ||
cat testdata/.ssh/id_ed25519.pub >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
echo "======= public key =========" | ||
cat testdata/.ssh/id_ed25519.pub | ||
echo "============================" | ||
echo "PRIVATE_KEY<<EOF" >> $GITHUB_ENV | ||
cat testdata/.ssh/id_ed25519 >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
echo "======= private key =========" | ||
cat testdata/.ssh/id_ed25519 | ||
echo "============================" | ||
- name: create new ssh server | ||
run: | | ||
docker run -d \ | ||
--name=openssh-server \ | ||
--hostname=openssh-server \ | ||
-p 2222:2222 \ | ||
-e PUBLIC_KEY="${{ env.PUBLIC_KEY }}" \ | ||
-e SUDO_ACCESS=false \ | ||
-e PASSWORD_ACCESS=true \ | ||
-e USER_PASSWORD=password \ | ||
-e USER_NAME=linuxserver.io \ | ||
--restart unless-stopped \ | ||
lscr.io/linuxserver/openssh-server:latest | ||
docker exec openssh-server sh -c "hostname -i" > ip.txt | ||
echo "REMOTE_HOST<<EOF" >> $GITHUB_ENV | ||
cat ip.txt >> $GITHUB_ENV | ||
echo "EOF" >> $GITHUB_ENV | ||
echo "======= container ip address =========" | ||
cat ip.txt | ||
echo "======================================" | ||
sleep 2 | ||
- name: testing id_ed25519 key | ||
uses: appleboy/[email protected] | ||
with: | ||
host: ${{ env.REMOTE_HOST }} | ||
username: linuxserver.io | ||
key: ${{ env.PRIVATE_KEY }} | ||
port: 2222 | ||
script: | | ||
whoami | ||
ls -al | ||
- name: pass environment | ||
uses: appleboy/[email protected] | ||
env: | ||
FOO: "BAR" | ||
with: | ||
host: ${{ env.REMOTE_HOST }} | ||
username: linuxserver.io | ||
key: ${{ env.PRIVATE_KEY }} | ||
port: 2222 | ||
envs: FOO | ||
script: | | ||
echo "I am $FOO, thanks" | ||
echo "I am $BAR, thanks" | ||
- name: pass multiple environment | ||
uses: appleboy/[email protected] | ||
env: | ||
FOO: "BAR" | ||
BAR: "FOO" | ||
SHA: ${{ github.sha }} | ||
PORT: ${{ secrets.PORT }} | ||
with: | ||
host: ${{ env.REMOTE_HOST }} | ||
username: linuxserver.io | ||
key: ${{ env.PRIVATE_KEY }} | ||
port: 2222 | ||
envs: FOO,BAR,SHA,PORT | ||
script: | | ||
echo "I am $FOO, thanks" | ||
echo "I am $BAR, thanks" | ||
echo "sha: $SHA" | ||
echo "port: $PORT" | ||
sh test.sh | ||
- name: custom envs format | ||
uses: appleboy/[email protected] | ||
env: | ||
FOO: "BAR" | ||
AAA: "BBB" | ||
with: | ||
host: ${{ env.REMOTE_HOST }} | ||
username: linuxserver.io | ||
key: ${{ env.PRIVATE_KEY }} | ||
port: 2222 | ||
envs: FOO,BAR,AAA | ||
envs_format: export TEST_{NAME}={VALUE} | ||
script: | | ||
echo "I am $TEST_FOO, thanks" | ||
echo "I am $TEST_BAR, thanks" | ||
echo "I am $BAR, thanks" | ||
echo "I am $TEST_AAA, thanks" | ||
- name: pass all ENV variables to script | ||
uses: appleboy/[email protected] | ||
env: | ||
INPUT_FOO: "BAR" | ||
INPUT_AAA: "BBB" | ||
with: | ||
host: ${{ env.REMOTE_HOST }} | ||
username: linuxserver.io | ||
key: ${{ env.PRIVATE_KEY }} | ||
port: 2222 | ||
allenvs: true | ||
script: | | ||
echo "I am $INPUT_FOO, thanks" | ||
echo "I am $INPUT_AAA, thanks" | ||
echo "$GITHUB_BASE_REF" | ||
echo "$GITHUB_REF" |