gpt4 book ai didi

GitHub 操作 : share common actions between jobs

转载 作者:行者123 更新时间:2023-12-04 13:30:06 26 4
gpt4 key购买 nike

转自 Travis CIGitHub Actions ,我想知道是否有办法在作业之间共享通用步骤。对于一个项目,我需要每个作业从 3 个操作开始:检查存储库代码、安装 Node.js v12、从缓存中恢复 node_modules(如果可用)。实际上,我为每个作业添加了这 3 个操作,虽然有效,但有点冗长。有没有办法说:“每个工作都必须先运行这些操作”或类似的话?

name: ci
on: [push, workflow_dispatch]

jobs:
setup:
runs-on: ubuntu-latest
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Cache node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Install dependencies
run: npm install

test_mysql:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Test MySQL 5
run: npm run test-mysql
env:
DOCKER_MYSQL_TAG: 5

- name: Test MySQL 8
run: npm run test-mysql
env:
DOCKER_MYSQL_TAG: 8

test_postgres:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Test Postgres 10
run: npm run test-postgres
env:
DOCKER_POSTGRES_TAG: 10

- name: Test Postgres 11
run: npm run test-postgres
env:
DOCKER_POSTGRES_TAG: 11

- name: Test Postgres 12
run: npm run test-postgres
env:
DOCKER_POSTGRES_TAG: 12

test_mariadb:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Test MariaDB 10.4
run: npm run test-mariadb
env:
DOCKER_MARIADB_TAG: 10.4.12

test_mssql:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Test MSSQL 2017
run: npm run test-mssql
env:
DOCKER_MSSQL_TAG: 2017-CU17-ubuntu

- name: Test MSSQL 2019
run: npm run test-mssql
env:
DOCKER_MSSQL_TAG: 2019-latest

test_sqlite:
runs-on: ubuntu-latest
needs: setup
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Test SQLite
run: npm run test-sqlite

publish:
runs-on: ubuntu-latest
needs: [test_mysql, test_postgres, test_mariadb, test_mssql, test_sqlite]
steps:
- name: Check out repository code
uses: actions/checkout@v2

- name: Setup node
uses: actions/setup-node@v2
with:
node-version: '12'

- name: Restore node_modules
id: cache-node-modules
uses: actions/cache@v2
with:
path: node_modules
key: node-modules-${{ hashFiles('package-lock.json') }}

- name: Build
run: npm run build

- name: Check version changes
uses: EndBug/version-check@v1
id: check

- name: Publish
if: steps.check.outputs.changed == 'true' && github.ref == 'refs/heads/master'
run: |
npm set registry "https://registry.npmjs.org"
npm set //registry.npmjs.org/:_authToken ${{ secrets.NPM_PUBLISH_TOKEN }}
npm publish

最佳答案

如果您要共享的步骤是uses,目前看来是不可能的。 .
应该由composite actions but处理

What does composite run steps currently support?

For each run step in a composite action, we support:

  • name
  • id
  • run
  • env
  • shell
  • working-directory

In addition, we support mapping input and outputs throughout the action.

See docs for more info.

What does Composite Run Steps Not Support

We don't support setting conditionals, continue-on-error, timeout-minutes, "uses", and secrets on individual steps within a composite action right now.

关于GitHub 操作 : share common actions between jobs,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/65570514/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com