How can I use web-deploy on github actions? - github

I have my domain and my hosting through one.com and I'm tired of moving individual files through filezilla and wanted to automate that process using github actions.
I guess I'll start out by saying I'm completely new to this and this is my first time trying to setup an action. Basically what I want is to just push the code to my github repo and then it gets build and sent to my host. Kinda like how it is with Netlify.
I stumbled upon this https://github.com/SamKirkland/web-deploy which should do the trick. I've seen tutorials using this method on youtube, but I guess they have a different provider than I do making it easier.
This is what information I have to go off of and I hope it will be enough to set it up:
Host: ssh.one-example.com
Username: one-example.com
Password: the one you chose for SSH in your Control Panel
Port: 22
and this is what I put in the yml file:
on:
push:
branches:
- main
name: Publish Website
jobs:
web-deploy:
name: 🚀 Deploy Website Every Commit
runs-on: ubuntu-latest
steps:
- name: 🚚 Get Latest Code
uses: actions/checkout#v3
- name: 📂 Sync Files
uses: SamKirkland/web-deploy#v1
with:
target-server: ${{ secrets.ftp_host }}
remote-user: ${{ secrets.ftp_username }}
private-ssh-key: ${{ secrets.ftp_password }}
destination-path: ~/destinationFolder/
I've tried having the target server both be ssh.one-example.com (obviously using my own here) and I've tried one-example.com#ssh.one-example.com
But I'm ending up with the following error when the action is running:
Error: Error: The process '/usr/bin/rsync' failed with exit code 255
So safe to say I'm a little lost and would like some guidance on how to make it work. Is it what I'm typing that's the issue, is it the host? And if so how do I fix it?
Any help is much appreciated.

Try an SSH action first, to see if you actually can open an SSH session. This is just for testing the connection: try and execute on the remote server a trivial command (ls, or pwd)
Then, regarding your current original action, check the error messages before your "The process '/usr/bin/rsync' failed with exit code 255".
See as an example of previous error messages SamKirkland/web-deploy issue 5 (not yet resolved).

Related

GitHub action - how to parameterize container image hostname

I have a GitHub action with a workflow that uses a container to run it, using a private docker registry (myhostname.com - see below).
jobs:
myjob:
name: My Job
runs-on: [ some-tag-on-runners ]
container:
image: myhostname.com/dir/subdir/image:latest
I tried parameterizing myhostname.com using the {{ $secrets.SOME_SECRET }} feature but it doesn't work. I need to have this workflow in several repos and if the hostname changes I would like to be able to change it in only one place. Can't seem to find anything in the docs at GitHub.

github actions "The key 'concurrency' is not allowed."

I want to cancel the previous run when a new run is executed.
So, referring to the https://docs.github.com/en/actions/reference/workflow-syntax-for-github-actions#concurrency document, I added the concurrency keyword.
Below is my sample code.
name: test
on:
push:
branches:
- feature/**
concurrency:
group: ${{ github.ref }}
cancel-in-progress: true
jobs:
~~~
However, when executing the action, an error saying "The key 'concurrency' is not allowed" is thrown and it does not work. The examples on google are no different from my sample code. What is the cause?
(If the concurrency keyword is removed, the action works normally.)
Tried the code you provided and it worked for me with no issue. Not sure what the problem is on your side. Are you running this on a GitHub-provided runner or are you self-hosting one? Can't gauge that since you job description is missing. Also do you have a link to the repository maybe?
Something to try would be to add the concurrency key on the job level instead of the global level. Maybe that changes things for you

"Error: timeout of 600000ms exceeded" in github build with ghost inspector tests

I have the below error in github build with ghost inspector tests
"Error: timeout of 600000ms exceeded"
I tried maxTimeout in git build .yml file. But it's not working.
https://ghostinspector.com/docs/integration/github-actions/
If anyone knows this solution share it with me.
Instead of changing the concurrency in the ghostinpector, you can use the ghostinprctor-cli for run the git actions.
Ex:
https://ghostinspector.com/docs/api/cli/
- uses: docker://ghostinspector/cli
with:
args: suite execute ${{ secrets.GI_SUITE }} \
--apiKey ${{ secrets.GI_API_KEY }} \
--errorOnFail
secrets.GI_SUITE and secrets.GI_API_KEY are the ghostinspector API and SUITE keys. you can get those from the ghostinspector settings
secrets and the github secrets https://docs.github.com/en/actions/security-guides/encrypted-secrets
The above issue has based on concurrency limitations.
Previously I used 25 tests that not working.
Now I changed that 50 tests. Now, maxTimeout=600000ms is working correctly for me.

Github actions: Post comment to PR workflow that triggered the current workflow

I have two workflows, the first one runs a build script and generates an artifact.
The first one is triggered when a pull request is created like this:
name: build
on:
pull_request:
types: [opened, edited, ready_for_review, reopened]
The second flow runs when the first is done, by using the workflow_runtrigger like this:
on:
workflow_run:
workflows: ["build"]
types:
- "completed"
The second flow has to be separate and run after the first one. When done it is supposed to post a comment on the PR that triggered the first workflow, but I am unable to find out how.
According to the Github Action Docs this is one of the typical use cases, as per this qoute:
For example, if your pull_request workflow generates build artifacts, you can create
a new workflow that uses workflow_run to analyze the results and add a comment to the
original pull request.
But I can't seem to find out how. I can get the first workflow's id in the 2nd workflow's context.payload.workflow_run.id, but workflow_run should also have about the pull request, but they`re empty.
What am I doing wrong, and where can I find the necessary info to be able to comment on my created pull request?
You're not doing anything wrong, it's just that the Pull Request datas from the first workflow are not present in the Github Context of the second workflow.
To resolve your problem, you could send the Pull Request datas you need from the first workflow to the second workflow.
There are different ways to do it, for example using a dispatch event (instead of a workflow run), or an artifact.
For the artifact, it would look like something as below:
In the FIRST workflow, you get the PR number from the github.event. Then you save that number into a file and upload it as an artifact.
- name: Save the PR number in an artifact
shell: bash
env:
PULL_REQUEST_NUMBER: ${{ github.event.number }}
run: echo $PULL_REQUEST_NUMBER > pull_request_number.txt
- name: Upload the PULL REQUEST number
uses: actions/upload-artifact#v2
with:
name: pull_request_number
path: ./pull_request_number.txt
In the SECOND workflow, you get the artifact and the Pull Request number from the FIRST workflow, using the following GitHub Apps:
- name: Download workflow artifact
uses: dawidd6/action-download-artifact#v2.11.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
workflow: <first_workflow_name>.yml
run_id: ${{ github.event.workflow_run.id }}
- name: Read the pull_request_number.txt file
id: pull_request_number_reader
uses: juliangruber/read-file-action#v1.0.0
with:
path: ./pull_request_number/pull_request_number.txt
- name: Step to add comment on PR
[...]

github actions get URL of test build

I can't seem to find out how to get the URL of a test workflow anywhere in the docs. I have a simple job which runs tests and on fail it needs to post the URL of the failed job to another web service.
I was expecting this to be in the default env vars but apparently not.
Thanks,
${{ github.server_url }}/${{ github.repository }}/actions/runs/${{ github.run_id }}
This was originally suggested in this post on GH forum.
Am convinced there is nothing about this in the docs, but I eventually found that this works:
https://github.com/<name>/<repo>/commit/$GITHUB_SHA/checks
You can get the GitHub Action URL for the particular commit by formulating the URL like the example below for a shell script step.
- name: Run shell cmd
run: echo "https://github.com/${{github.repository}}/commit/${{github.sha}}/checks/${{github.run_id}}"
Alternatively, GitHub action provides the env's as GITHUB_REPOSITORY, GITHUB_SHA, GITHUB_RUN_ID in each step and only need to construct the URL in the above pattern.