GitHub Action checkout from specific directory - github

I am trying to upload a repo to server via ftp on push to master branch. I have it set up and working. However in the repo there is a folder /public. I only want to upload the files in this folder to the server. Not other files or the folder itself. I have tried to set up a working directory for the job but this doesn't seem to do the trick.. any ideas?
on:
push:
branches:
- master
name: ๐Ÿš€ Deploy website on push
jobs:
ftp-web-deploy:
name: ๐ŸŽ‰ Deploy
runs-on: ubuntu-latest
defaults:
run:
working-directory: ./public
steps:
- name: ๐Ÿšš Get latest code
uses: actions/checkout#v2.4.0
working-directory: ./public
with:
fetch-depth: 2
- name: ๐Ÿ“‚ Sync files
uses: SamKirkland/FTP-Deploy-Action#4.2.0
with:
server: ****
username: ****
password: ${{ secrets.prod_ftp_password }}
server-dir: public_html/

Checking out only one directory is not possible, but has been requested in the actions/checkout repository before: https://github.com/actions/checkout/issues/483
There's an action to check out specific files, but I haven't tried it and I'm not sure if it does what you want: https://github.com/marketplace/actions/checkout-files
You might want to ask yourself why you're trying to limit the number of files transferred. Is it because you're concerned about traffic? Or because of the input expected in the subsequent action?
If it's the latter, you could also manually "fix" the structure by running some mv and rm commands.

Related

access script stored in .github directory in github action

I have a my_script.sh file in .github/my_script.sh in my repo.
Below is my YAML file:
jobs:
main:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
with:
path: master
- name: Set sync script in env
run: |
myscript=$(cat .github/my_script.sh)
echo "::set-env name=MY_SCRIPT::$myscript"
But I got this error:
cat: .github/my_script.sh: No such file
Any clue why?
According to https://github.com/actions/checkout, path is the "relative path under $GITHUB_WORKSPACE to place the repository". Note that does not change the working directory.
This means that using path: master will put your repo in a folder named master. I suspect that you meant to check out the master branch instead. Checkout will automatically checkout the branch the workflow was ran on so most of the time, specifying it specifically is not required.
You either want to remove the path argument or change your code to use the correct path: myscript=$(cat master/.github/my_script.sh)
I think specifying working directory will work.
jobs:
main:
runs-on: ubuntu-latest
defaults:
run:
working-directory: .github
steps:
- uses: actions/checkout#v3
- name: step sync script in env
run: cat my_script.sh
I have checked it and it works.

Github repository is empty when rsync is used

I have added workflow to github actions where i want to rsync files from repository to remote server
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Deploy with rsync
run: rsync -avuz --delete . ${{ secrets.USER }}#${{ secrets.HOST }}:~/App/MainPage/
rsync sends nothing because my repository in source folder is empty, even though there are files in repo.
i get this message
I know that rsync works, because if i change dir (eg ../../) files are being transferred to remote server and i can see them there.
I forgot to add checkout action to workflow .yaml file
...
jobs:
build:
runs-on: ubuntu-latest
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v3
- name: Install SSH Key
uses: shimataro/ssh-key-action#v2
....

Missing files that have not yet been commited and pushed

Hello I'm trying to test my actions locally using https://github.com/nektos/act
But the problem is when I want to use some of the files that have not yet been committed and pushed to the remote, act says that these files don't exist.
How to solve it? Below is my action config.
As you can seen in first step I'm doing a checkout to actions#v3. Without this, the next step shows nothing, but when I do checkout then it seems that my local sources are not get into consideration.
name: Main
on: [push, workflow_dispatch]
jobs:
terffere:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout#v3
- id: ls
run: ls -la ./.github/workflows
shell: bash

GitHub Actions - How clean up unchanged/uncommited files before upload to SFTP Server

Iยดm tring to config a GitHub Action to deploy my application to SFTP file.
My application has 6700 files and I would like to upload only changed/commited files.
How can I remove unchanged and/or uncommited files before upload to SFTP?
This way, my one file modification deploy would be so faster than upload 6k files.
name: CI
on:
push:
branches: [ main ]
workflow_dispatch:
jobs:
deploy:
runs-on: ubuntu-latest
name: Deploy Job
steps:
- name: Checkout
uses: actions/checkout#v2
with:
fetch-depth: 2
- name: Deploy files
uses: wlixcc/SFTP-Deploy-Action#v1.0
with:
username: 'deploy_user'
server: 'server_ip'
ssh_private_key: ${{ secrets.SSH_PRIVATE_KEY }}
local_path: './www/*'
remote_path: '/www'
args: '-o ConnectTimeout=10'
To list down all the files that are updated/committed in the given commit, you can use this command:
$ git diff-tree --no-commit-id --name-only -r $GITHUB_SHA
index.html
src/application.js
Then you can use this to delete all the files that are not on this list. This needs some bash digging. One hack I can think of is to make a temporary directory to copy updated files and only upload these files.

How can I use Github Actions to trigger downloading a static copy of a website and push to S3?

I am trying to use Github actions on the Push event to my master branch for running a wget command to mirror a website and download its contents as static files and then zip them together for uploading to an s3 bucket. Here is my test_events.yml file stored under .github/workflows in my git repo:
name: create a mirror of website and zip the saved contents
on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
jobs:
mirror-website:
name: mirrors the website
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: wget
uses: wei/wget#v1
with:
args: -O logfile.txt -P ./actions/ https://adappt.co.uk
zip-files:
name: Zips the Saved file
runs-on: ubuntu-latest
steps:
- name: Checkout Code
uses: actions/checkout#v2
- name: Prepares a zip file
uses: montudor/action-zip#v1.0.0
with:
args: zip -qq -r adappt_co_uk.zip . -i /actions/adappt.co.uk
Problem is whenever I push a change in my repo, the action gets triggered and gets completed without errors. But it does not save the web files to the given location, and hence, doesn't perform the zip operation as well.
What am I doing wrong here? Is there any other way apart from using wget?