I am new to github actions and need some help.
I have a readme.md file for a collection of scripts that is 100s of lines long. I want to translate it into different languages using this github action (https://github.com/dephraiim/translate-readme)
But instead of putting all the files it creates into the main directory. I want to create a folder inside my directory and put all these created files in there.
So in the main directory I have all the scripts I've written and one readme.md file. What I want is something like this.
Maindirectory/newreadmefolder/(all the new language readme.md files)
A directory can be created this way.:
- name: Create dir
run: |
mkdir mydirname
This has to be added in steps part like in this full action file:
name: mkdir example
on:
push:
branches: [ '**' ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Create dir
run: |
mkdir mydirname
If you also want to move some file, you can add something like mv readme-*.md mydirname at the end, e.g.:
- name: Create dir
run: |
mkdir mydirname
mv readme-*.md mydirname
Related
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.
I want to run a test through Github action for each PR.
My Github repository structure is
Root Dir
Sub Dirs
Child Dir
Java Module Dir
Sub Dirs
Child Dir
Java Module Dir
Sub Dirs
Child Dir
Java Module Dir
...
In this situation
I want to test only Java modules.
I don't want to create a repository as a multi-module project
The reason is that it is going to be used in combination with other languages, so it doesn't look good for the repository to look like it's based on Java.
Anyway, to run Java tests by subdirectory
Do I have to write that directory to the workflow file to run it?
Is it possible to dynamically find and execute Java-based directories?
(Java-based directories are probably prefixed with "Java-")
I set the matrix with GitHub action workflow
The directory description was tested.
I want to dynamically directory Testing in Github Action
You can dynamically create the input for the matrix in the first job and then use that as an input for the matrix in the second job.
For a project where all test directories are in a directory call tests, you could collect the directories like so:
collect_dirs:
runs-on: ubuntu-latest
outputs:
dirs: ${{ steps.dirs.outputs.dirs }}
steps:
- uses: actions/checkout#v2
- id: dirs
run: echo "::set-output name=dirs::$(ls -d tests/*/ | jq --raw-input --slurp --compact-output 'split("\n")[:-1]')"
The tricky part here is how to construct the dirs output:
First, we list all directories in the directory tests/
Second, jq formats the output as a JSON array. For example, if the directory contains the subdirectories a, b, and c, then the output is set to ["a","b","c"].
In a second job, you can use the matrix based on that output:
run_tests:
needs: collect_dirs
runs-on: ubuntu-latest
strategy:
matrix:
dir: ${{ fromJson(needs.collect_dirs.outputs.dirs) }}
steps:
- run: echo ${{ matrix.dir }}
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.
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.
I have defined a little github action workflow, which is supposed to compile a kss-styleguide from scss.
The steps of that workflow basically trigger building the resulting css and the respective kss-styleguide.
When I run the build process locally on my dev machine the built styleguide is written to the styleguide folder located in the root of my project.
However on github, despite everything being marked off green, I don't know, what or where the resulting files are being written to.
How can I deploy the generated styleguide, if I don't know where it is?
Here's my yaml file for this workflow:
name: Node.js CI
on:
push:
branches: [ mk-node-ci ]
pull_request:
branches: [ mk-node-ci ]
jobs:
build:
name: Build Styleguide
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [14.x]
steps:
- uses: actions/checkout#v2
- name: Use Node.js ${{ matrix.node-version }}
uses: actions/setup-node#v1
with:
node-version: ${{ matrix.node-version }}
- uses: borales/actions-yarn#v2.0.0
with:
cmd: install
env:
NODE_ENV: development
- name: "build CSS files"
uses: borales/actions-yarn#v2.0.0
with:
cmd: "build:css"
- name: "build styleguide files"
uses: borales/actions-yarn#v2.0.0
with:
cmd: "build:styleguide"
Updated 2020.10.14 19:25 GMT
GitHub Actions are performed on a separate "clean" Runner Machine.
actions/checkout#v2 is an action that copies your repository to that machine โ typically, to perform tests etc.
In order to get produced results (like modified files) from runner machine back to the original repository, we can use:
(1) upload-artifact action.
(2) git push.
For example, here is my script to modify files from the source directory and put them into the output directory (I run it as an action (bash script): - run: wrap.sh). The script wrap.sh:
echo "Copy directory structure from 'in' to 'out':";
find ./in -type d | while read i;
do
if [ ! -d "${i/in/out}" ]; then
mkdir "${i/in/out}"
echo "${i/in/out}";
fi
done
echo "Wrap files:";
find ./in -type f -name "*" | while read i;
do
echo "${i/in/out}";
cat ./tpl/header.html "$i" ./tpl/footer.html >"${i/in/out}"
git add "${i/in/out}"
done
git config user.name "chang-zhao"
git commit . -m "Wrapping"
git push origin main
Here git add "${i/in/out}" is adding to git a new file with that name. git config user.name "..." is required for the commit to work. git commit . -m "Wrapping" is the commit that puts new files into the repository ("Wrapping" is a name I gave to such commits).
This way files produced on a runner server get pushed to the original repository.