我必须执行以下操作,每次提交(因此也可以通过在Github上的浏览器中编辑文件来完成(时,都会调用Github action
。
Github action
必须执行以下操作:运行package.json
中的命令,或者只运行ncc build
命令
什么东西:
"build": "ncc build"
然后提交构建文件。
使用推送提交后,必须运行4 Github action test
。
你建议我怎么做?
我想到了这样一件事:
on:
push:
branches:
- master
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
name: Check out current commit
- name: Install
run: npm install
- name: Build
run: npm run build
- name: Commit
run: |
git config --local user.email "41898282+github-actions[bot]@users.noreply.github.com"
git config --local user.name "github-actions[bot]"
git add .
git commit -m "Build" -a
- name: Push
uses: ad-m/github-push-action@master
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
branch: ${{ github.ref }}
例如,目前的测试是这样的,我该怎么办?
Test.yml
on:
push:
branches:
- master
name: "Testing"
jobs:
test_the_action:
name: Test the action
runs-on: ubuntu-18.04
steps:
- uses: actions/checkout@v2
- uses: suisei-cn/actions-download-file@master
id: downloadfile
name: Download a file
with:
url: "[API Endpoint](https://api.github.com/repos/suisei-cn/actions-download-file)"
target: public/
auto-match: true
- name: Display the file
run: head -n8 public/actions-download-file
有两个选项。您可以使用needs关键字在主yml中为每个测试添加作业,或者使用工作流运行事件作为触发器调用测试yml。
选项1包含needs关键字:
on:
push:
branches:
- master
name: Build
jobs:
build:
name: Build
runs-on: ubuntu-latest
steps:
- <your-build-steps>
test1:
name: Test
runs-on: ubuntu-latest
needs: build
steps:
- <your-test-steps>
将工作流作为触发器运行的选项2:
on:
workflow_run:
workflows: ["<name-of-your-main-workflow>"]
types:
- completed
name: "Testing"
jobs:
test_the_action:
此选项仅适用于默认分支。