I've learned basics of Github Actions and I'd like to improve a workflow of an Open Source project which I currently maintain (TiddlyWiki Classic).
Now: we have 2 repos: main one contains sources and docs bits as separate files; secondary one is used for hosting docs as a built TW via Github Pages (uses both code bits and docs bits). So when one proposes a change to docs, they create a PR in the main repository, but to make accepted changes make their way to the site, I have to manually pull changes, build docs page locally, commit & push them to the secondary repo.
Desired: I suppose those manual steps can be automated with Github Actions (on commit to master), but I'm not sure how.
Considerations: In steps:
I can write things like run: npm install
and other build steps, but how do I commit into another repo? Since this is an organization, passing credentials into env is not a good idea, I guess. Or setting those as a secret (settings/secrets) should be good enough? (looks like those are not readable after being saved, are they?)
Actually, I'd prefer an alternative approach where the whole thing is inside the same repository, but I don't know if it's possible to show something (the built page) in Github Pages without committing them. Well, it's acceptable if the built page will be stored in the repo if it's updated automatically, although this will clutter change history, so it's not really desirable.
Any suggestions for building either flow is very welcome.
PS. Following the suggestion by GuiFalourd, I'm trying to setup the combination of dispatching an event from the main repo to the and handling it in the secondary repo. The handling itself works quite nicely, here's what I've come up with:
# todo: add correct event trigger
on: push
jobs:
build-site:
runs-on: ubuntu-latest
steps:
# should be run first since it makes files created in cwd before not accessible
- uses: actions/checkout@v2
- name: get TiddlyWiki source
run: git clone https://github.com/TiddlyWiki/TiddlyWiki.git
- name: install and build
run: |
cd ./TiddlyWiki
npm i
npm run build-site
cd ..
- name: move and commit resulting file
# todo: get the "build/cooked/2.9.2" path bit from core repo itself
# mv ./TiddlyWiki/build/cooked/2.9.2/index.html ./
# todo: enrich commit message with event/source commit
run: |
mv ./TiddlyWiki/build/cooked/*/index.html ./
git config --global user.name ${{ github.event.pusher.name }}
git config --global user.email ${{ github.event.pusher.email }}
git add ./index.html
git commit -m "autoupdate index.html"
git push
However, I haven't succeeded with dispatching yet. Following this post, I've set up a simple handler:
on: repository_dispatch
jobs:
explore-dispatch:
steps:
- run: |
echo 'repository_dispatch event is triggered'
echo ${{ github.event.inputs }}
in my test repo and tried to dispatch with Postman:
POST
to https://api.github.com/repos/YakovL/try-github-actions/actions/workflows/dispatch/dispatches
(dispatch is the name of the workflow, see dispatch.yaml)
with custom header Accept application/vnd.github.v3+json
and Basic Auth (my github login/password)
and body { "ref": "main", "inputs": {} }
but I'm getting
{
"message": "Must have admin rights to Repository.",
"documentation_url": "https://docs.github.com/rest/reference/actions#create-a-workflow-dispatch-event"
}
What am I doing wrong?