10 个你该了解的 GitHub Actions 进阶技巧

如果你已经在使用 GitHub Actions ,那么阅读本文你将获得更多有趣而有用的打开方式。阅读完,我又给仓库新增了几个 workflow 。

1. workflow 执行时,传入参数

在执行 workflow 时, 允许在 GitHub Actions 页面输入参数,控制执行逻辑。我们可以将人工处理的逻辑,在 GitHub Actions 参数化执行,适用于持续部署场景。

相关推荐

站点声明:本站部分内容转载自网络,作品版权归原作者及来源网站所有,任何内容转载、商业用途等均须联系原作者并注明来源。

相关侵权、举报、投诉及建议等,请发邮件至E-mail:service@mryunwei.com

回到顶部
 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
on: 
  workflow_dispatch:
    inputs:
      logLevel:
        description: 'Log level'     
        required: true
        default: 'warning'
      tags:
        description: 'Test scenario tags'  
jobs:
  printInputs:
    runs-on: ubuntu-latest
    steps:
    - run: |
        echo "Log level: ${{ github.event.inputs.logLevel }}"
        echo "Tags: ${{ github.event.inputs.tags }}"         
on: push
jobs:
  job1:
    runs-on: ubuntu-latest
    steps:
      - run: echo "job1"
  job2:
    runs-on: ubuntu-latest
    steps:
      - run: sleep 5
    needs: job1
  job3:
    runs-on: ubuntu-latest
    steps:
      - run: sleep 10
    needs: job1
  job4:
    runs-on: ubuntu-latest
    steps:
      - run: echo "job4"
    needs: [job2, job3]
- uses: actions/[email protected]
  with:
    repo-token: "${{ secrets.GITHUB_TOKEN }}"
docs_label:
  - ./docs/*
- name: Assign NEW issues and NEW pull requests to project 2
  uses: srggrs/[email protected]
  if: github.event.action == 'opened'
  with:
    project: 'https://github.com/srggrs/assign-one-project-github-action/projects/2'
- name: Assign issues and pull requests with `bug` label to project 3
  uses: srggrs/[email protected]
  if: |
    contains(github.event.issue.labels.*.name, 'bug') ||
    contains(github.event.pull_request.labels.*.name, 'bug')    
  with:
    project: 'https://github.com/srggrs/assign-one-project-github-action/projects/3'
    column_name: 'Labeled'
name: 'Close stale issues and PRs'
on:
  schedule:
    - cron: '30 1 * * *'

jobs:
  stale:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/[email protected]
        with:
          stale-issue-message: 'This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 5 days.'
          days-before-stale: 30
          days-before-close: 5
- uses: shaowenchen/[email protected]
  name: debugger
  timeout-minutes: 30
  continue-on-error: true
  with:
    ngrok_token: ${{ secrets.NGROK_TOKEN }}
- name: Get yarn cache directory path
  id: yarn-cache-dir-path
  run: echo "::set-output name=dir::$(yarn cache dir)"

- uses: actions/[email protected]
  id: yarn-cache # use this to check for `cache-hit` (`steps.yarn-cache.outputs.cache-hit != 'true'`)
  with:
    path: ${{ steps.yarn-cache-dir-path.outputs.dir }}
    key: ${{ runner.os }}-yarn-${{ hashFiles('**/yarn.lock') }}
    restore-keys: |
            ${{ runner.os }}-yarn-
name: Check Markdown links

on: push

jobs:
  markdown-link-check:
    runs-on: ubuntu-latest
    steps:
    - uses: actions/[email protected]
    - uses: gaurav-nelson/[email protected]
      with:
        use-quiet-mode: 'yes'
        config-file: '.github/workflows/checklink_config.json'
        max-depth: 3
{
  "replacementPatterns": [
    {
      "pattern": "^/",
      "replacement": "/github/workspace/"
    }
  ],
  "aliveStatusCodes": [
    429,
    200
  ]
}
=========================> MARKDOWN LINK CHECK <=========================

FILE: ./docs/governance.md

4 links checked.

FILE: ./docs/configuration/cri.md
[✖] https://build.opensuse.org/project/show/devel:kubic:libcontainers:stable

7 links checked.

ERROR: 1 dead links found!
[✖] https://build.opensuse.org/project/show/devel:kubic:libcontainers:stable → Status: 404

FILE: ./docs/configuration/kubeedge.md

21 links checked.

=========================================================================
on: push
jobs:
  node:
    runs-on: ${{ matrix.os }}
    strategy:
      matrix:
        os: [ubuntu-16.04, ubuntu-18.04]
        node: [6, 8, 10]
    steps:
      - uses: actions/[email protected]
        with:
          node-version: ${{ matrix.node }}
      - run: node --version
on: workflow_dispatch
on:
  schedule:
    - cron:  '*/15 * * * *'
on:
  fork
on:
  watch:
    types: [started]
on:
  issues:
    types: [opened]
FROM appleboy/drone-scp:1.6.2-linux-amd64

ADD entrypoint.sh /entrypoint.sh
RUN chmod +x /entrypoint.sh
ENTRYPOINT ["/entrypoint.sh"]
#!/bin/sh

set -eu

[ -n "$INPUT_STRIP_COMPONENTS" ] && export INPUT_STRIP_COMPONENTS=$((INPUT_STRIP_COMPONENTS + 0))

sh -c "/bin/drone-scp $*"
name: 'Hello World'
description: 'Greet someone'
inputs:
  who-to-greet:  # id of input
    description: 'Who to greet'
    required: true
    default: 'World'
outputs:
  random-number:
    description: "Random number"
    value: ${{ steps.random-number-generator.outputs.random-id }}
runs:
  using: "composite"
  steps:
    - run: echo Hello ${{ inputs.who-to-greet }}.
      shell: bash
    - id: random-number-generator
      run: echo "::set-output name=random-id::$(echo $RANDOM)"
      shell: bash
    - run: ${{ github.action_path }}/goodbye.sh
      shell: bash