yalegria / devops-git-actions

0 stars 0 forks source link

Pass the rep name as part of the destination dir path on the deployment action. #16

Open yuriaru opened 3 years ago

Voxelghiest commented 3 years ago

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.

  1. 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")
  2. Use Bash's cut function to parse out the repo name exclusively, by dividing at the forward slash character
  3. Append that result to the location of the directory in the remote server /var/www/html/ in our case.
  4. 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
yuriaru commented 3 years ago

@yuriaru need to find a server to run procedure on this ticket.