我有一個靜態博客設定,每次我想要一個新帖子時,我都必須提交并推送一個 .md 檔案。這是一個組的一部分,所以我想知道是否有一種方法可以在每次將新的 .md 檔案保存到谷歌驅動器檔案夾時自動執行提交和推送部分。
IFTTT 涵蓋了第一部分,每次上傳新檔案時,都會在 github 上創建一個新問題,其中包含指向正文中檔案的鏈接。
但是,我不知道如何創建現在下載檔案、創建新分支、提交檔案并將其推送到該分支并最終設定拉取請求以供我批準的操作。
如果您知道任何其他自動化此程序的方法,我愿意接受建議!
謝謝!
編輯1:
我不太確定如何完成這個(包括在我寫的地方生成一個亂數 <random-number>。這是我到目前為止所擁有的:
name: Pull request on issue
on:
issues:
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: create branch
uses: peterjgrainger/[email protected]
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/[email protected]
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/[email protected]
- name: Generate random number
id: random
run: echo "::set-output name=value::$(echo $RANDOM)"
- name: create branch
uses: peterjgrainger/[email protected]
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/[email protected]
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/[email protected]
Error: No token defined in the environment variables
它指的是哪個令牌?這是指你提到的私人行動嗎?但是,存盤庫是公開的。
再次感謝你的幫助!
uj5u.com熱心網友回復:
可以使用輸出變數來更新您的作業流程以添加亂數。我還認為您需要將actions/checkout操作添加到您的存盤庫中以訪問下載的檔案。
更新后的作業流檔案如下所示
name: Pull request on issue
on:
issues:
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected]
- name: Generate random number
id: random
run: echo "::set-output name=value::$(echo $RANDOM)"
- name: Example how to use the output
run: echo "${{ steps.random.outputs.value }}"
- name: create branch
uses: peterjgrainger/[email protected]
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/[email protected]
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
您還可以創建一個composite可以重現您正在使用的所有步驟的操作,例如使用以下內容:
action action.yml 看起來像這樣。
name: 'Action Name'
description: 'Runs a composite step action'
inputs:
secret:
required: true
description: "Github PAT"
runs:
using: "composite"
steps:
- name: Checkout
uses: actions/[email protected]
- name: Generate random number
id: random
run: echo "::set-output name=value::$(echo $RANDOM)"
shell: bash
- name: Example how to use the output
run: echo "${{ steps.random.outputs.value }}"
shell: bash
- name: create branch
uses: peterjgrainger/[email protected]
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 }}
shell: bash
- name: create pull request towards the main branch
uses: peter-evans/[email protected]
with:
token: ${{ inputs.secret }}
commit-message: Auto Pull Request
title: New post pr
body: Auto-created Pull Request
branch: post-${{ steps.random.outputs.value }}
base: master
inputs如果您想將某些值動態化(例如,您不能直接在操作中使用秘密),請向操作添加一些其他內容。
編輯
要在同一存盤庫中本地使用此操作檔案(如果您不想將其公開),您需要創建一個.github/actions/<action-name>檔案夾,并將此action.yml檔案添加到那里。
然后,要在您的作業流作業中使用它,您需要將您的workflow.yml實作更新為:
name: Pull request on issue
on:
issues:
jobs:
create:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/[email protected] # Necessary to access local action
- name: Local Action Call
uses: ./.github/actions/<action-name>
with:
secret: ${{ secrets.GH_TOKEN }}
更新<action-name>您選擇的檔案夾名稱。
我已經創建了類似的東西(呼叫本地動作)的作業流實體這里用這個動作,YML檔案
請注意,Github Marketplace上也有許多操作來執行git commit push操作。
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/361018.html
標籤:混帐 github-actions 博客 伊夫特
