Is there a smart way to copy and rename files via a GitHub Actions?
I want to have some READMEs to be copied to the /docs
folder (:= the same repo, not a remote one!), where they will be renamed according to their frontmatter title
.
Goal is to have some kind of auto-updating doc system where everytime I push the Jekyll gets populated automatically.
In your repository, browse to the file you want to rename. In the upper right corner of the file view, click to open the file editor. In the filename field, change the name of the file to the new filename you want. You can also update the contents of your file at the same time.
Step 1: Open GitHub. Step 2: Open the repository to rename any file in that repository. Step 3: Open the file which we want to rename. Step 4: Click the edit button and rename the file.
GitHub Actions makes it easy to automate all your software workflows, now with world-class CI/CD. Build, test, and deploy your code right from GitHub. Make code reviews, branch management, and issue triaging work the way you want.
Many files can be renamed directly on GitHub, but some files, such as images, require that you rename them from the command line. This procedure assumes you've already: Git Bash. Change the current working directory to your local repository.
Perform the following to record the rename operation in the staging area. Stage the deleted file− “file1.txt” and Stage the untracked file− “file1.java” Use the git add command to achieve this. Use the git status command to verify the status. The output of the command suggests that the rename operation has been recorded.
Many files can be moved directly on GitHub, but some files, such as images, require that you move them from the command line. On your computer, move the file to a new location within the directory that was created locally on your computer when you cloned the repository. Open TerminalTerminalGit Bash.
The syntax for using the Linux mv command is − Use the Linux command mv to rename the file to “file1.java”. Execute the git status command to verify the file’s status in Git. The output in the screenshot suggests that the file has been renamed in two steps −
In the end this is what I did:
name: docs
on:
push:
branches: [ master ]
paths: 'myfolder/*/README.md'
jobs:
docit:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@master
- name: Copy the Readmes
run: |
find ./myfolder/ -type f -name "README.md" | while read fname; do
dirname=`dirname "$fname"`
foldername=`basename "$dirname"`
filename=`basename "$fname"`
newname=`echo "$dirname" | sed -e "s/ /_/g"`
cp "${dirname}/$filename" "./docs/_myfolder/${foldername}.md"
done
- name: Commit files
run: |
git config --local user.email "[email protected]"
git config --local user.name "GitHub Action"
git commit -m "Add changes" -a
- name: Push changes
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
I figured out that I didn't need to look into the frontmatter, since the README was inside a folder with the name I need anyway.
Beware: cp
will nag if you run it the first time and the CI will fail, because you can't have empty folders tracked in git. So I just created an empty dummy file to make sure the "_myfolder" is always there.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With