-
Notifications
You must be signed in to change notification settings - Fork 34
95 lines (79 loc) · 3.46 KB
/
check-kttest-snippets.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
name: Check Snippet kttest Snippets
on:
pull_request:
types: [ opened, synchronize ]
# Allow the workflow to read the contents of the repository and pull request to be
# able to retrieve list of changed files.
permissions:
contents: read
pull-requests: read
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
get-github-context:
name: Get Branches And Changed Files
runs-on: ubuntu-latest
# Allow the workflow to read the contents of the repository and pull request to be
# able to retrieve list of changed files when PR is opened from forked repository.
permissions:
contents: read
pull-requests: read
steps:
- name: Get branch name
id: branch-name
uses: tj-actions/branch-names@v8
- name: List Branches
run: |
echo current branch: ${{ steps.branch-name.outputs.current_branch }}
echo base ref branch branch: ${{ steps.branch-name.outputs.base_ref_branch }}
echo default branch: ${{ steps.branch-name.outputs.default_branch }}
- name: Get Changed Files
id: changed-files
uses: tj-actions/changed-files@v45.0.5
- name: Echo List Changed Files
run: |
echo Changed files:
echo ${{ steps.changed-files.outputs.all_changed_files }} | tr ' ' '\n'
- name: Echo Run Condition (any true to run)
run: |
echo Current branch starts with "release/": ${{ startsWith(steps.branch-name.outputs.current_branch, 'release/') }}
echo Base ref branch is "main": ${{ steps.branch-name.outputs.base_ref_branch == 'main' }}
echo Changed .kttest files: ${{ contains(steps.changed-files.outputs.all_changed_files, '.kttest') }}
outputs:
current_branch: ${{ steps.branch-name.outputs.current_branch }}
base_ref_branch: ${{ steps.branch-name.outputs.base_ref_branch }}
all_changed_files: ${{ steps.changed-files.outputs.all_changed_files }}
check-kttest-snippets:
name: Check kttest Snippets
needs: get-github-context
runs-on: ubuntu-latest
if: |
needs.get-github-context.outputs.base_ref_branch == 'main' ||
startsWith(needs.get-github-context.outputs.current_branch, 'release/') ||
contains(needs.get-github-context.outputs.all_changed_files, '.kttest')
steps:
- name: Checkout
uses: actions/checkout@v4
- name: Set up JDK
uses: actions/setup-java@v4
with:
java-version: 21
distribution: 'corretto'
- name: Run Python Script for All Files
if: needs.get-github-context.outputs.base_ref_branch == 'main' || startsWith(needs.get-github-context.outputs.current_branch, 'release/')
run: python3 scripts/check_kttest_snippets.py -all
- name: Filter Changed .kttest Files
if: contains(needs.get-github-context.outputs.all_changed_files, '.kttest')
run: |
kttest_files=$(echo '${{ needs.get-github-context.outputs.all_changed_files }}' | tr ' ' '\n' | grep '\.kttest$')
if [ -n "$kttest_files" ]; then
temp_file=$(mktemp)
echo "$kttest_files" > "$temp_file"
echo "TEMP_FILE=$temp_file" >> $GITHUB_ENV
fi
- name: Run Python Script With Changed .kttest Files
if: contains(needs.get-github-context.outputs.all_changed_files, '.kttest')
run: python3 scripts/check_kttest_snippets.py "$TEMP_FILE"
env:
TEMP_FILE: ${{ env.TEMP_FILE }}