Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get github env in shh-action #99

Closed
erfannariman opened this issue Dec 27, 2020 · 1 comment
Closed

Get github env in shh-action #99

erfannariman opened this issue Dec 27, 2020 · 1 comment

Comments

@erfannariman
Copy link

erfannariman commented Dec 27, 2020

I want to get the remote-url as an env variable in my ssh-action step. What I tried so far:

name: Azure VM deploy # test deploy Azure
on:
  push:
    branches:
      - main
jobs:
  build:
    runs-on: ubuntu-latest
    steps:

    - name: Check out code
      uses: actions/checkout@v2

    - name: Environment variables
      run: |
        echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV

    - name: Create project dir
      uses: appleboy/ssh-action@master
      env:
        MYGURL: ${{ github.GURL }}
      with:
        HOST: ${{ secrets.AZURE_HOST }}
        USERNAME: ${{ secrets.AZURE_USERNAME }}
        KEY: ${{ secrets.AZURE_KEY }}
        PORT: ${{ secrets.PORT }}
        ENVS: MYGURL
        script: |
          mkdir -p ~/projects
          echo "$MYGURL"
          cd ~/projects
          if [ -d "${{ github.event.repository.name }}" ]; then
            echo "Directory already exists"
            cd ${{ github.event.repository.name }}
            git pull --rebase
          else
            echo "Project does not exist, cloning.."
            git clone $MYGURL
          fi
          echo 'Deployment to Azure succesful!'

But this does not seem to work since echo "$MUGURL" gives an empty string. Is there a way to achieve what I want with ssh-action?

The final goal is to make line git clone $MYGURL work in some way. So we have to get the remote repo url in a general way.

@sastraxi
Copy link

sastraxi commented Jan 7, 2021

@erfannariman The best way to do this is to build the clone URL yourself, something like this (untested):

uses: appleboy/ssh-action@master
env:
  REPO: ${{ github.repository }} # e.g. "appleboy/ssh-action"
  TOKEN: ${{ github.token }}
with:
  envs: REPO,TOKEN
  script: |
    git clone https://$TOKEN@github.com/$REPO.git

See https://github.blog/2012-09-21-easier-builds-and-deployments-using-git-over-https-and-oauth/ for why this URL works.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants