The goal is to retrieve the name of a repository inside of a GitHub action in order to name the folder in the server correctly when the files are sent.
Get the name of the repository using the built-in variable github.repository. This includes the username of the owner and the repo name (e.g., "Voxelghiest/ExampleRepo")
Use Bash's cut function to parse out the repo name exclusively, by dividing at the forward slash character
Append that result to the location of the directory in the remote server /var/www/html/ in our case.
Store that as the value of the variable REMOTE_DIRECTORY by writing it into the $GITHUB_ENV file used by actions to store variables between steps.
Here's the entire snippet, all in one step:
- name: Parse Remote Directory Name
env:
# This variable only exists for the duration of this step in the job
# The curly brace notation is used to retrieve the built-in variable so it can be accessed by the virtual machine shell
GITHUB_REPOSITORY: ${{ github.repository }}
# This part parses the repo name, appends it, and stores the new REMOTE_DIRECTORY variable all in one step
run: echo "REMOTE_DIRECTORY=/var/www/html/$(echo $GITHUB_REPOSITORY | cut -d "/" -f 2)" >> $GITHUB_ENV
The goal is to retrieve the name of a repository inside of a GitHub action in order to name the folder in the server correctly when the files are sent.
github.repository
. This includes the username of the owner and the repo name (e.g., "Voxelghiest/ExampleRepo")cut
function to parse out the repo name exclusively, by dividing at the forward slash character/var/www/html/
in our case.REMOTE_DIRECTORY
by writing it into the$GITHUB_ENV
file used by actions to store variables between steps.Here's the entire snippet, all in one step: