rev*_*evy 9 continuous-integration github travis-ci github-actions
从Travis CI切换到GitHub 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
Run Code Online (Sandbox Code Playgroud)
现在可以在复合动作中使用 - 请检查此链接
\n复合动作:
\nname: "Publish to Docker"\ndescription: "Pushes built artifacts to Docker"\n\ninputs:\n registry_username:\n description: \xe2\x80\x9cUsername for image registry\xe2\x80\x9d\n required: true\n registry_password:\n description: \xe2\x80\x9cPassword for image registry\xe2\x80\x9d\n required: true\n\nruns:\n using: "composite"\n steps:\n - uses: docker/setup-buildx-action@v1\n\n - uses: docker/login-action@v1\n with:\n username: ${{inputs.registry_username}}\n password: ${{inputs.registry_password}}\n\n - uses: docker/build-push-action@v2\n with:\n context: .\n push: true\n tags: user/app:latest\n
Run Code Online (Sandbox Code Playgroud)\n进而:
\non: [push]\n\njobs:\n publish:\n runs-on: ubuntu-latest\n steps:\n - uses: actions/checkout@v2\n - uses: my-org/publish-docker@v1\n with:\n registry_username: ${{secrets.REGISTRY_USERNAME}}\n registry_password: ${{secrets.REGISTRY_PASSWORD}}\n
Run Code Online (Sandbox Code Playgroud)\n原回复:
\n如果您想要共享的步骤中有以下内容,目前看来是不可能的uses
。
它应该通过复合动作来处理,但是
\n\n\n复合运行步骤当前支持什么?
\n对于复合操作中的每个运行步骤,我们支持:
\n\n
\n- 姓名
\n- ID
\n- 跑步
\n- 环境
\n- 壳
\n- 工作目录
\n此外,我们支持在整个操作过程中映射输入和输出。
\n请参阅文档以获取更多信息。
\n复合运行步骤不支持什么
\n我们不支持设置条件、错误继续、超时分钟、“使用”我们目前
\n
归档时间: |
|
查看次数: |
5170 次 |
最近记录: |