|
| 1 | +# - name: Set Skip Env Var |
| 2 | +# uses: ./.github/actions/skip |
| 3 | +# - name: Cache local Maven repository |
| 4 | +# if: env.SKIP_CI != 'true' |
| 5 | + |
| 6 | +name: "Set Skip Env Var" |
| 7 | +description: "Action to set the SKIP_CI environment variable indicating that we should skip CI jobs" |
| 8 | +inputs: |
| 9 | + paths: |
| 10 | + description: >- |
| 11 | + Set the SKIP_CI environment variable when and only when all the changed files located in one of the path, |
| 12 | + the paths is shell-style pattern. |
| 13 | + required: false |
| 14 | + default: >- |
| 15 | + "*.md" |
| 16 | + "*.txt" |
| 17 | + "skywalking-ui" |
| 18 | + ".asf.yaml" |
| 19 | + ".dlc.yaml" |
| 20 | + ".licenserc.yaml" |
| 21 | + "docs/menu.yml" |
| 22 | + ".github/actions/skip/action.yml" |
| 23 | + ".github/workflows/codeql.yaml" |
| 24 | + "dist-material/release-docs" |
| 25 | + "test/plugin/*" |
| 26 | + "*/component-libraries.yml" |
| 27 | +
|
| 28 | +runs: |
| 29 | + using: "composite" |
| 30 | + steps: |
| 31 | + - name: Check Changed Files And Set Env Var |
| 32 | + shell: bash |
| 33 | + run: | |
| 34 | + if [[ "${{ github.event_name }}" != "pull_request" ]]; then |
| 35 | + exit 0 |
| 36 | + fi |
| 37 | +
|
| 38 | + BASE_SHA=$(jq -r '.pull_request.base.sha' $GITHUB_EVENT_PATH) |
| 39 | + echo "Base sha is $BASE_SHA, head sha is $GITHUB_SHA" |
| 40 | +
|
| 41 | + git fetch --no-tags --progress --recurse-submodules --depth=1 origin ${BASE_SHA}:origin/${BASE_SHA} |
| 42 | + BASE_SHA=origin/${BASE_SHA} |
| 43 | + echo "Base sha is $BASE_SHA, head sha is $GITHUB_SHA" |
| 44 | +
|
| 45 | + if ! files=$(git --no-pager diff --name-only ${GITHUB_SHA} ${BASE_SHA}); then |
| 46 | + exit 1 |
| 47 | + fi |
| 48 | +
|
| 49 | + echo "Ignore pattern:" |
| 50 | + for pattern in $(echo '${{ inputs.paths }}'); do |
| 51 | + echo $pattern |
| 52 | + done |
| 53 | +
|
| 54 | + echo "Changed files:" |
| 55 | + for file in ${files}; do |
| 56 | + echo $file |
| 57 | + done |
| 58 | +
|
| 59 | + echo "SKIP_CI=true" >> $GITHUB_ENV |
| 60 | + for file in ${files}; do |
| 61 | + matched=0 |
| 62 | + for pattern in $(echo '${{ inputs.paths }}'); do |
| 63 | + pattern=$(echo "$pattern" | sed 's/"//g') |
| 64 | + if eval "[[ '$file' == $pattern ]]"; then |
| 65 | + matched=1 |
| 66 | + break |
| 67 | + fi |
| 68 | + done |
| 69 | + if [[ "$matched" == "0" ]]; then |
| 70 | + echo "$file doesn't match pattern $(echo '${{ inputs.paths }}'), stop checking" |
| 71 | + echo "SKIP_CI=false" >> $GITHUB_ENV |
| 72 | + break |
| 73 | + fi |
| 74 | + done |
0 commit comments