Github include md files in README.md? - github

Is there a way in Github to include md files in for example the README.md?
# Headline
Text
[include](File:load_another_md_file_here.md)
It should not link to the file, it should load the contents from it, like PHP include / file_get_contents.

That does not seem to be possible, especially when considering github/markup#346 and github/markup#172.
No include directive is supported.

This is not the correct answer but a workaround for others who really want this.
It's possible to use Gulp and Gulp Concat to merge the files into one before they are sent to Github..

Since it is not possible I just ended up placing a link as
[MY-LINK](../../SOME-OTHER-README.MD)

migrate your readme to a different file then construct your actual README however you like as a github action
EDIT: Here's a demo that you can build off of. This repo has a single github action that runs a script that dynamically builds the README.md based on the contents of the repository (to build a site map for the repo in the form of a table of contents): https://github.com/dmarx/bench-warmers
the workflow config:
name: update-readme
on:
push:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- uses: actions/setup-python#v2
- name: Run the script
run: python scripts/update_readme.py
- name: Commit files
run: |
git config --local user.name "dmarx"
git add README.md
git commit -m "Updated TOC"
- name: Push changes
uses: ad-m/github-push-action#master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
force: true
Here's the chunk of my update script that's relevant to you:
... # code that builds the object `toc_str`
# template readme
with open('README.stub') as f:
readme_stub = f.read()
# simple replacement, use whatever stand-in value is useful for you.
readme = readme_stub.replace('{TOC}',toc_str)
with open('README.md','w') as f:
f.write(readme)
Which assumes you have a file named README.stub which might look something like this:
# Title
some text
{TOC}
more text
Where {TOC} is the substitution target for our dynamic content.

Ruby gem markdown_helper implements include files for GitHub flavored markdown (GFM).
Disclosure: I wrote the gem.

Related

Copy JSON files from a private repository to the current one

I've set up a YML file for a GitHub action to get some files from a private repo I have. The action seems to work without throwing any error (even the file names are showing up in the log) but the folder and the files are not showing up in the destination repository.
Can someone shed some light on what am I doing wrong?
This is my YML so far:
name: copy JSONs
on:
push:
workflow_dispatch:
jobs:
copy_files:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- name: Copy files from private repo
uses: actions/checkout#v2
with:
repository: paramm/cron-jobs
token: ghp_BLABLABALBALBALBABLABLA
path: private-repo-files
- name: Create directory for copied files
run: |
mkdir copied-files
mv private-repo-files/*.json copied-files/
- name: Add and commit copied files
run: |
git config --local user.email "action#github.com"
git config --local user.name "GitHub Action"
git add copied-files
git commit -m "Add copied files from private repo"
last line was missing:
git push origin main

GitHub Action errors because it can't see a folder

I'm trying to set up my first GiHub Action. All it needs to do is run a test over my Godot files. I based it on a template.
name: CI
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: godot-tester
uses: croconut/godot-tester#v2.5
with:
version: 3.4
release_type: stable
# Give relative path to your project.godot, if not in top level of repo
path: app
The action errors every time, when trying to find the project file.
/entrypoint.sh: line 166: cd: ./app: No such file or directory
The folder, app, is there and it contains the project. I've tried with or without a trailing slash, it makes no difference.
When you need to access the files from the proper repository in a Github Actions workflow, you need to setup the actions/checkout first.
This will allow the workflow to access the Github workspace (which is basically the repository root).
In your case, the workflow should look like this:
name: CI
on:
pull_request:
branches: [ main ]
workflow_dispatch:
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v3
- name: godot-tester
uses: croconut/godot-tester#v2.5
with:
version: 3.4
release_type: stable
# Give relative path to your project.godot, if not in top level of repo
path: app
The actions/checkout action has a default behavior, but you can also configure other fields to customize what you want it to do. Check the action README page to see all the possibilities.

Understanding npm packages inside github actions

Here is my idea: build a static web page template, over time add .md files to a /posts directory and build a CI job to convert the .md files to html (with the showdownjs/showdown package).
Is there a need to install the package on every push? Seems like a waste, but uploading /node-modules is incorrect as well. Is there a way to install the package once, and let github action just work with it (run the md to html converter on newly added files)?
You have 2 options:
Recommened: Use caching action to cache dependencies for your project - using a hash from package-lock.json as a key to make sure it rebuild when depenendencies has changed:
- name: Cache node modules
uses: actions/cache#v2
env:
cache-name: cache-node-modules
with:
# npm cache files are stored in `~/.npm` on Linux/macOS
path: ~/.npm
key: ${{ hashFiles('**/package-lock.json') }}
- name: Install Dependencies
run: npm install
Push your node_modules to Git repository so it's checkout together with everything else
For optimising a need to run your converted you can use this action:
https://github.com/tj-actions/changed-files/
and detect if any files were modified at certain path

Auto unzip files & deploy to Heroku from Github

I have a simple PHP + SQlite app working on Heroku with this structure:
myPhpApp/
├── Procfile
├── README.md
├── composer.json
├── composer.lock
├── data
│   ├── css.css
│   ├── small_db.sqlite3
│   ├── large_db.sqlite3.zip
└── index.php
The Procfile file simply contains: web: vendor/bin/heroku-php-apache2
Since my Github account limits file size, so I have to zip large_db.sqlite3 to large_db.sqlite3.zip .
What Inam trying to do is to auto unzip large_db.sqlite3.zip back to large_db.sqlite3 when I deploy it to Heroku through Github action.
So far I saw this code snippet:
# From https://github.com/marketplace/actions/deploy-to-heroku
name: Deploy
on:
push:
branches:
- master # Changing the branch here would also work
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout#v2
- uses: akhileshns/heroku-deploy#v3.7.8 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
heroku_email: "YOUR EMAIL"
Is it possible to do something like this (pseudo code) in Github Action?
cd ./data
unzip large_db.sqlite3.zip
cd ..
deploy/build (on Github/Heroku)
May you all be well and happy!
Thanks!
After a process of trials & errors, I came to this solution.
I shared it here for future visitors. May it be helpful.
Github action yml file: .github/workflows/main.yml
# From: Github action template
# This is a basic workflow to help you get started with Actions
name: CI
# Controls when the action will run.
on:
# Triggers the workflow on push or pull request events but only for the main branch
push:
branches: [ main ]
pull_request:
branches: [ main ]
# Allows you to run this workflow manually from the Actions tab
workflow_dispatch:
# A workflow run is made up of one or more jobs that can run sequentially or in parallel
jobs:
# This workflow contains a single job called "build"
build:
# The type of runner that the job will run on
runs-on: ubuntu-latest
# Steps represent a sequence of tasks that will be executed as part of the job
steps:
# Checks-out your repository under $GITHUB_WORKSPACE, so your job can access it
- uses: actions/checkout#v2
# Unzip and remove zip files
- run: unzip -qq './data/*.zip' -d ./data && rm ./data/*.zip
- uses: akhileshns/heroku-deploy#v3.7.8 # This is the action
with:
heroku_api_key: ${{secrets.HEROKU_API_KEY}}
heroku_app_name: "YOUR APP's NAME" #Must be unique in Heroku
heroku_email: "YOUR EMAIL"
Note:
For each zip file (separated zip files should be more flexible for your later updates, try not to bundle all in one big zip file), for my case, I compressed each file with this command: zip large_db.sqlite3.zip large_db.sqlite3
heroku_app_name is the appname in your https://appname.herokuapp.com

How to deploy to github with file pattern on travis?

I have created a simple travis configuration which packages an app and tries to deploy the archive file to github.
The problem is, I would like to have the version number part of the file name, so i require to use a pattern for the filename. I simply can't get it to work.
Configuration is currently:
deploy:
provider: releases
file: "build/distributions/worktrail-app-hub-sync*.zip"
on:
repo: worktrail/worktrail-app-hub-sync
tags: true
all_branches: true
But it fails with: "/home/travis/.rvm/gems/ruby-1.9.3-p547/gems/octokit-3.3.1/lib/octokit/client/releases.rb:86:in `initialize': No such file or directory - build/distributions/worktrail-app-hub-sync*.zip (Errno::ENOENT)" - but the file is certainly there: build/distributions/worktrail-app-hub-sync-0.0.1.zip
Example run: https://travis-ci.org/worktrail/worktrail-app-hub-sync/builds/35704111
travis.yml: https://github.com/worktrail/worktrail-app-hub-sync/blob/0.0.1/.travis.yml
Is this supported by travis deployment, or is there any workaround for this use case?
Wildcards are supported by now if you enable the file_glob option. This is how I deploy a build .deb file to GitHub releases:
before_deploy:
- export RELEASE_PKG_FILE=$(ls *.deb)
- echo "deploying $RELEASE_PKG_FILE to GitHub releases"
deploy:
provider: releases
api_key:
secure: YOUR_ENCRYPTED_API_KEY
file_glob: true
file: "${RELEASE_PKG_FILE}"
on:
tags: true
Setting up is easy by executing travis setup releases with a dummy filename and modifying .travis.yml afterwards.
deploy:
file_glob: true
file: "build/distributions/worktrail-app-hub-sync*.zip"
example
Sorry, wildcard patterns don't work at the moment, but we'll have a look into making that possible on Travis CI.