I have a static blog setup and every time I want a new post I have to commit and push a .md file. This is part of a group, so I was wondering if there is a way to automate the commit and push part every time a new .md file is saved to a google drive folder.
The first part is covered by IFTTT, where every time a new file is uploaded, a new issue is created on github containing the link to the file in the body.
However, I don't know how to create the action that will now download the file, create a new branch, commit and push the file to that branch and finally set up a pull request for me to approve.
If you know of any other way of automating this process I am open to suggestions!
Thanks!
Edit1:
I am not really sure how to complete this (including generating a random number where I wrote <random-number>. Here's what I have so far:
name: Pull request on issue
on:
issues:
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: create branch
uses: peterjgrainger/action-create-branch@v2.0.1
with:
# The branch to create
branch: post-<random-number>
- name: download file
run: wget ${{ github.event.issue.body }} -O source/_posts/
- name: commit and push new file
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add .
git commit -m "New post"
git push -u origin post-<random-number>
- name: create pull request towards the main branch
uses: peter-evans/create-pull-request@v3.10.1
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: Auto Pull Request
title: New post pr
body: Auto-created Pull Request
branch: post-<random-number> # The branch where you commit
base: master # Don't forget to specify the right base branch here
Edit2:
name: Pull request on issue
on:
issues:
inputs:
secret:
required: true
description: "Github PAT"
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v2.3.4
- name: Generate random number
id: random
run: echo "::set-output name=value::$(echo $RANDOM)"
- name: create branch
uses: peterjgrainger/action-create-branch@v2.0.1
with:
# The branch to create
branch: post-${{ steps.random.outputs.value }}
- name: download file
run: wget ${{ github.event.issue.body }} -O source/_posts/
- name: commit and push new file
run: |
git config user.name "GitHub Actions Bot"
git config user.email "<>"
git add .
git commit -m "New post"
git push -u origin post-${{ steps.random.outputs.value }}
- name: create pull request towards the main branch
uses: peter-evans/create-pull-request@v3.10.1
with:
token: ${{ secrets.GH_TOKEN }}
commit-message: Auto Pull Request
title: New post pr
body: Auto-created Pull Request
branch: post-${{ steps.random.outputs.value }} # The branch where you commit
base: master # Don't forget to specify the right base branch here
This is what I have at the moment, thanks to @GuiFalourd.
Unfortunately, when I run this, I get the following error:
Run peterjgrainger/action-create-branch@v2.0.1
Error: No token defined in the environment variables
Which token is it referring to? Is this referring to the private action you mentioned? The repository is public, though.
Thanks again for your help!