last day (15 days later) » 

1:15 PM
1
A: Github actions get SSH link of repository

VonCConsidering the checkout action allows to run commands in the checked out working tree, you could use $GITHUB_ENV environment variables, since set-env is deprecated since Oct. 2020: on: push jobs: build: runs-on: ubuntu-latest steps: - uses: actions/checkout@v2 - run: | ...

 
Zal
Thanks, if I understand correctly your answer is an extra step as a replacement for my git clone right? Or is it more than that?
 
@Zal It is an addition step to store the URL in a variable, for you to use in your script from your next step.
 
Zal
Worked perfectly, thanks. Small side questions. Am I using the script: part correctly? Since you use run:
 
@Zal run: is a workflow command (docs.github.com/en/free-pro-team@latest/actions/reference/…‌​). with: script: is an action input parameter given to the action you are using.
 
Zal
I actually tested this with a project where the project did not exists, so it had to do the git clone $GURL and the GURL env variable is empty. So it fails, any idea what might cause this?
 
1:15 PM
@Zal Can you add pwd and ls -alrth and git version before the git remote get-url line? Just to check where you are at and what Git is used by this GitHub Action execution?
 
Zal
Sure, see my edit in OP.
 
OK, so you are in the right folder, with the right git
Can you add git remote get-url origin
To see if the remote is actually set?
 
Zal
Yes
It gets the wrong url I think. It gets the https url
output of git remote get-url origin is: github.com/orgname/digitalocean-test-deploy
https://github.com/orgname/digitalocean-test-deploy
Sorry it kept formatting the link
 
https://github.com/orgname/digitalocean-test-deploy is the wrong URL?
Because it is not github.com:orgname/projectname.git?
 
Zal
Well I expected it to be in the format git@github.com:orgname/digitalocean-test-deploy.git. Since it is a private repo, so we need ssh to clone the repo.
Yes
 
1:25 PM
Even if it is an HTTPS URL instead of an SSH one, is it the correct repository?
 
Zal
Weird thing is, when I run git remote get-url origin locally, it gives the correct format. So with git@github...
 
This is expected
 
Zal
Yes it is the correct repo, just wrong url format
 
Locally, you have set the URL yourself
Remotely, GitHub does not need an SSH URL
 
Zal
Okay didn't know
 
1:26 PM
(in its GitHub Action)
But the question remains
Is it the right repo name?
 
Zal
Yes, and the link work when I click on it in the GitHub Actions output.
 
OK.
debug the variable
Next step
FOr testing
can you try
echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV
 
Zal
It looks like it's empty
 
with space before and after >>
 
Zal
Oke
 
Zal
Did not work, let me give you the full output
pwd
ls -alrth
git version
git remote get-url origin
echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV
shell: /bin/bash -e {0}
/home/runner/work/digitalocean-test-deploy/digitalocean-test-deploy
total 60K
drwxr-xr-x 3 runner docker 4.0K Dec 27 13:28 ..
drwxr-xr-x 2 runner docker 4.0K Dec 27 13:28 tests
drwxr-xr-x 2 runner docker 4.0K Dec 27 13:28 src
-rw-r--r-- 1 runner docker 1.1K Dec 27 13:28 setup.py
drwxr-xr-x 2 runner docker 4.0K Dec 27 13:28 settings
-rw-r--r-- 1 runner docker 26 Dec 27 13:28 requirements.txt
Then later, I test for env variable with echo $GURL
======CMD======
mkdir -p ~/projects
echo $GURL
cd ~/projects
if [ -d "digitalocean-test-deploy" ]; then
echo "Directory already exists"
cd digitalocean-test-deploy
git pull --rebase
else
echo "Project does not exist, cloning.."
git clone $GURL
fi
echo 'Deployment to Digital Ocean succesful!'

======END======
out:
out: Project does not exist, cloning..
err: fatal: You must specify a repository to clone.
As we can see, the first out is empty, which is the echo of $GURL
 
When you say "later", is it in a separate step?
From your question, it should
 
Zal
Yes seperate step, as we saw in question
You want to see the whole YAML?
 
Before that
for testing, can you see if echo "GURL=aaa" >> $GITHUB_ENV works
Can you add in the second step
 
Zal
We set the GURL env variable before I do git clone yes
 
1:34 PM
echo "GURL='${GURL}'"
note the 'xx' simple quotes right around the variable
 
Zal
Oke
Sorry, just to be sure. I put "GURL=aaa" >> $GITHUB_ENV in the same step as we do git remote get-url origin? And echo "GURL='${GURL}'" in the step after?
 
Yes
since a step which sets the variable would not have access to that same variable
 
Zal
Do you want me to replace aaa with git remote get-url origin? Else it will again right?
fail*
mkdir -p ~/projects
echo "GURL='${GURL}'"
echo $GURL
cd ~/projects
if [ -d "digitalocean-test-deploy" ]; then
echo "Directory already exists"
cd digitalocean-test-deploy
git pull --rebase
else
echo "Project does not exist, cloning.."
git clone $GURL
fi
echo 'Deployment to Digital Ocean succesful!'

======END======
out: GURL=''
And before this step I have:

pwd
ls -alrth
git version
git remote get-url origin
echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV
 
OK: the '' in GURL='' do confirm the variable is empty
 
Zal
Yes
 
1:45 PM
But did you use "GURL=aaa" >> $GITHUB_ENV in the previous step
?
 
Zal
I did now:

pwd
ls -alrth
git version
git remote get-url origin
echo "GURL=aaa" >> $GITHUB_ENV
 
OK. Does the echo in the second step still show an empty variable?
 
Zal
But still

out: GURL=''
out:
 
OK, I guess I misunderstood the documentation (docs.github.com/en/free-pro-team@latest/actions/reference/…): "The action that creates or updates the environment variable does not have access to the new value, but all subsequent actions in a job will have access."
 
Zal
I was reading myself as well, it's pretty confusing I agree
And the example you sent to me does the same?
 
1:50 PM
Maybe add a shell: bash at the end of run?
as in the example
 
Zal
tried it, did not work
Wait
The output is now:

echo "GURL=aaa" >> $GITHUB_ENV
shell: /bin/bash --noprofile --norc -e -o pipefail {0}
What does pipefail {0} mean?
 
Zal
It might be because I use:

uses: appleboy/ssh-action@master
right?
 
set -o pipefail This setting prevents errors in a pipeline from being masked. If any command in a pipeline fails, that return code will be used as the return code of the whole pipeline.
You should set the variable before using the action
Example
 
Zal
I do, so: uses: appleboy/ssh-action@master is after
 
Zal
So should I change something?
 
Yes: the idea is to put/set the variable in a step, before a second step which declares the action to use.
In that link, you can see the first step named "Default", which sets a variable
Then the second step uses an action
Try setting the variable before the step - uses: actions/checkout@master
 
Zal
Oke
These are my first two steps now:

jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Environment variables
run: |
echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV

- name: Check out code
- uses: actions/checkout@v2
The indentation is gone
This results in: every step must define a uses or run key
But github.com/nak3/net-ingressv2/blob/… does not have any 'uses' in his Default step
 
It does have run
And uses
In the default step, it has run
line 45
 
Zal
2:09 PM
This should be the same as line 44-57
 
The should not be a - before uses, as in line 63 of the example
and in that step (with uses), you can try the echo to see if the variable is accessible and not empty
 
Zal
Now I put it in a seperate step I get:

echo "GURL=$(git remote get-url origin)" >> $GITHUB_ENV
shell: /bin/bash -e {0}
fatal: not a git repository (or any of the parent directories): .git
 
Right because this needs the context established by the checkout action
 
Zal
So this happens after checkout
It needs to happen
 
Yes
followed by a variable setup
followed by using those variables
 
Zal
2:25 PM
I changed the order, put it in a seperate step, still empty. And the order looks quite similar to the link you just sent. Very weird
 
Try first with GURL=aaa
not GURL=$(xxx)
The goal is to check if the variable can be set
(to anything)
Then, once that is validated, can we move t the next hurdle
and see if the $() subshell syntax can work
But do not try and debug two issues at once
Other example I have found: github.com/UncleRus/esp-idf-lib/blob/…
Heck, even one with subshell!
 
Zal
Thanks for the examples, last one is a bit too complex for me to be fair. Not sure what happens there exactly.
But still empty output, this is my workflow right now:
 
Can you try a second simpler step
one with just a run in it
(a run and the echo, to check if the variable is empty or not)
So no uses in the second step
just run, and its echo
 
Zal
Do you mean the third step? Because the second step is already just a run and an echo right?
 
The second step is indeed an echo, to register the variable
So yes, a simpler third step
which just a run and an echo, to display the variable
 
Zal
2:37 PM
Okay that is werid, it worked
echo $GURL
shell: /bin/bash -e {0}
env:
GURL: aaa
aaa
 
OK, keep that
 
Zal
This is what I have now
 
but replace the registration part with the $(xxx) subshell command (the git remote get-url origin one)
So replace aaa
by $(...)
 
Zal
Okay
That worked!
Run echo $GURL
echo $GURL
shell: /bin/bash -e {0}
env:
GURL: https://github.com/org/digitalocean-test-deploy
https://github.com/org/digitalocean-test-deploy
It keeps formatting the links, but you get what I mean
Dont know how to do multi line code blocks in chat..
 
Sure, great:
Now lets try to re-introduce the second uses step
 
Zal
2:41 PM
Oke
 
The appleboy/ssh-action@master step
 
Zal
This one you mean?
Btw, I brb 10min, sorry.
I need to do something personally
 
I will have to go as well for an hour or two
But for testing, when you will get back
can you add in the with section
` with:`
` MYGURL: ${GURL}`
 
Zal
Oke
 
To see if we can have a parameter set to that variable
See you in a bit
 
Zal
2:44 PM
thank you ! See you in a but
bit*
 
Zal
3:16 PM
I have the following now, but this resulted in:

Warning: Unexpected input(s) 'MYGURL', valid inputs are ['entryPoint', 'args', 'host', 'port', 'passphrase', 'username', 'password', 'sync', 'use_insecure_cipher', 'cipher', 'timeout', 'command_timeout', 'key', 'key_path', 'fingerprint', 'proxy_host', 'proxy_port', 'proxy_username', 'proxy_password', 'proxy_passphrase', 'proxy_timeout', 'proxy_key', 'proxy_key_path', 'proxy_fingerprint', 'proxy_cipher', 'proxy_use_insecure_cipher', 'script', 'script_stop', 'envs', 'debug']
 
Zal
3:43 PM
Looks like a appleboy/ssh-action things. I solved the warning, but still empty env variable
I have the following now
I will open an issue in the github repo of ssh-action and ask it there.
 
 
1 hour later…
5:14 PM
(I am back)
OK, I see
 

last day (15 days later) »