如何在GitHub Action中根据提交信息跳过指定流水线步骤
在GitHub Actions中基于提交消息跳过指定测试步骤
我需要在GitHub Actions流水线里实现:当Git提交消息包含特定标识时,跳过名为“E2E TESTS”的测试步骤。最初打算用[no ci]作为标识,但发现GitHub会自动识别这个关键词并跳过整个流水线,不符合只跳过单个步骤的需求。
原流水线配置如下:
name: Pipeline on: ... jobs: test: runs-on: ubuntu-22.04 timeout-minutes: 10 steps: - uses: actions/checkout@v3 - uses: actions/setup-node@v3 with: node-version: 18.7.0 - uses: actions/cache/restore@v3 id: restore-cache with: path: node_modules key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }} - name: Yarn install run: yarn install --production=false - uses: actions/cache/save@v3 with: path: node_modules key: ${{ steps.restore-cache.outputs.cache-primary-key }} - name: run local server (NODE_ENV=production) run: | /bin/bash ci_server.sh & - name: E2E TESTS run: | /bin/bash playwright.sh --target docker
解决方案
改用[quick]作为跳过标识,在“E2E TESTS”步骤中添加if条件判断,只有当提交消息不包含[quick]时才执行该步骤。修改后的步骤配置如下:
... - name: E2E TESTS if: "!contains(github.event.head_commit.message, '[quick]')" run: | /bin/bash playwright.sh --target docker ...
说明
contains(github.event.head_commit.message, '[quick]')用于检查提交消息中是否包含[quick]字符串- 前缀
!表示取反逻辑:当提交消息不包含[quick]时,才会执行该测试步骤
内容的提问来源于stack exchange,提问作者stopsopa
相关产品推荐
相关产品推荐

