Missing files that have not yet been commited and pushed - github

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

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
....

Run github actions if branch has updated files from a specific directory

File structure:
apps
-- app-1
-- app-2
libs
-- lib-1
-- lib-2
We have tests that should run only in case if files were changed in lib-2.
I have tried to do
on:
push:
paths:
- 'libs/lib-2/**'
But it runs tests only when files from lib-2 were pushed in a commit but not running if some others were pushed after that.
Imagine tests are failed for lib-2, then developer have submitted files from lib-1 in the next commit and tests just wouldn't run for previous changes and github will consider checks as a success.
Is there a way to run actions if files from a certain directory were changed in a branch no matter in what commit?
I have designed a solution thanks to #guifalourd.
name: 'UI-kit Tests'
on:
pull_request:
branches:
- proto
- develop
- staging
- master
jobs:
filter-ui-kit:
runs-on: ubuntu-latest
name: Filter Ui kit
steps:
- uses: actions/checkout#v3
with:
fetch-depth: 0
- name: Get changed files in the docs folder
id: changed-files-specific
uses: tj-actions/changed-files#v34
with:
files: libs/ui-kit/**
- name: Run step if any file(s) in the docs folder change
if: steps.changed-files-specific.outputs.any_changed == 'true'
run: echo UI-kit is affected
- name: Prevent from running
if: steps.changed-files-specific.outputs.any_changed != 'true'
run: exit 1
test:
timeout-minutes: 60
runs-on: ubuntu-latest
needs: [filter-ui-kit]
steps:
... test actions goes there

GitHub Action checkout from specific directory

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.

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?