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
Related
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
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.
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
I have created a Reusable Workflow using a workflow_call trigger, but I need to run additional steps based on its outcome.
Example:
jobs:
released:
steps:
- name: Build
uses: my-org/some-repo/.github/workflows/build.yml#main
- name: Upload source maps
run: something
The reusable Build step builds my JS app and produces source maps. Now I need to upload these source maps to somewhere as a separate step that should only run inside this Released job.
Doing the above results in the following error:
Error : .github#L1
reusable workflows should be referenced at the top-level `jobs.*.uses' key, not within steps
It only allows running my reusable workflow inside a job, not inside a step. But by doing that I can no longer access the source maps.
My question: How do I reuse the steps from the Build workflow and access its output inside the Released job?
You can share these output files between jobs using artifacts.
Use the upload-artifact to upload the build files from the Build workflow and download-artifact to download them in the Released workflow.
Build workflow
name: Build
on:
workflow_call:
secrets:
SOME_SECRET:
required: true
jobs:
build:
steps:
# Your build steps here
- name: Create build-output artifact
uses: actions/upload-artifact#master
with:
name: build-output
path: build/
Released workflow
name: Released
on:
push:
branches:
- main
jobs:
build:
uses: my-org/some-repo/.github/workflows/build.yml#main
secrets:
SOME_SECRET: ${{ secrets.SOME_SECRET }}
released:
needs: build
steps:
- name: Download build-output artifact
uses: actions/download-artifact#master
with:
name: build-output
path: build/
# The "build" directory is now available inside this job
- name: Upload source maps
run: something
Bonus tip: Note that the "my-org/some-repo/.github/workflows/build.yml#main" string is case-sensitive. I wasted some time figuring out that that was the cause of the error below.
Error : .github#L1
error parsing called workflow "my-org/some-repo/.github/workflows/build.yml#main": workflow was not found. See https://docs.github.com/en/actions/learn-github-actions/reusing-workflows#access-to-reusable-workflows for more information.
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.