Github 操作执行一个操作,该操作在完成后调用其他操作

发布于 2025-01-11 21:13:41 字数 1792 浏览 1 评论 0 原文

我必须执行以下操作,每次完成提交(因此也可以通过从 Github 上的浏览​​器编辑文件来完成),调用 Github 操作

Github 操作 必须执行以下操作: 运行在 package.json 中找到的命令或仅运行 ncc build 命令,

这样的事情:

"build": "ncc build"

然后提交构建文件。

提交推送后,必须运行 4 Github 操作测试

你建议我怎么做?

我想到了这样一件事:

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 }}

现在测试是这样的,我该怎么办?

测试.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   

I have to do the following, every time a commit is done (so it can also be done by editing the file from the browser on Github), a Github action is called.

The Github action has to do the following:
Run the command found in the package.json or just run the ncc build command

What such a thing:

"build": "ncc build"

To then commit the build files.

After committing with the push, the 4 Github action test must be run.

How do you advise me to do?

I thought of such a thing:

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 }}

At the moment the test is like this for example, how can I do?

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   

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一个人练习一个人 2025-01-18 21:13:41

有两种选择。您可以使用 needs 关键字或使用 工作流程运行事件作为触发器。

带有需求关键字的选项 1:

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:

此选项仅适用于默认分支。

There are two options. You can add jobs for each test in your main yml with the needs keyword or call your test yml with the workflow run event as trigger.

Option 1 with needs keyword:

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>

Option 2 with workflow run as trigger:

on:
  workflow_run:
    workflows: ["<name-of-your-main-workflow>"]
    types:
      - completed

name: "Testing"

jobs:
  test_the_action:

This option works only on default branch.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文