【发布时间】:2021-12-30 08:11:09
【问题描述】:
我有一个静态博客设置,每次我想要一篇新文章时,我都必须提交并推送一个 .md 文件。这是一个组的一部分,所以我想知道是否有一种方法可以在每次将新的 .md 文件保存到谷歌驱动器文件夹时自动提交和推送部分。
第一部分由 IFTTT 覆盖,每次上传新文件时,都会在 github 上创建一个新问题,其中包含正文中文件的链接。
但是,我不知道如何创建现在将下载文件、创建新分支、提交并将文件推送到该分支并最终设置拉取请求以供我批准的操作。
如果您知道任何其他自动化此过程的方法,我愿意接受建议!
谢谢!
编辑1:
我不确定如何完成此操作(包括在我写
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
编辑2:
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
感谢@GuiFalourd,这就是我目前所拥有的。
不幸的是,当我运行它时,我收到以下错误:
Run peterjgrainger/action-create-branch@v2.0.1
Error: No token defined in the environment variables
它指的是哪个令牌?这是指你提到的私人行动吗?不过,存储库是公开的。
再次感谢您的帮助!
【问题讨论】:
-
是否可以通过命令行下载文件?如果是,则仅使用 git 命令即可完成其余过程。然后,如果您想创建一个执行相同操作的操作,您可以创建一个
composite操作来收集所有这些命令行。 -
您的问题应该显示您自己的研究以及您遇到的问题。也就是说,创建问题时可以触发操作,请参见此处:docs.github.com/en/actions/learn-github-actions/…
标签: git github-actions blogs ifttt