-
Notifications
You must be signed in to change notification settings - Fork 283
170 lines (160 loc) · 5.8 KB
/
build.yml
File metadata and controls
170 lines (160 loc) · 5.8 KB
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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
name: Build
on:
pull_request:
types: [opened, reopened, synchronize]
push:
branches:
- master
jobs:
paths-filter:
runs-on: ubuntu-latest
permissions:
contents: read
outputs:
java: ${{ steps.java.outputs.java }}
cpp: ${{ steps.cpp.outputs.cpp }}
golang: ${{ steps.golang.outputs.golang }}
csharp: ${{ steps.csharp.outputs.csharp }}
php: ${{ steps.php.outputs.php }}
rust: ${{ steps.rust.outputs.rust }}
python: ${{ steps.python.outputs.python }}
nodejs: ${{ steps.nodejs.outputs.nodejs }}
steps:
- uses: actions/checkout@v4
- name: Get changed files (Push/Pull Request)
id: changed_files
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: |
if [ "${{ github.event_name }}" = "pull_request" ]; then
PR_NUMBER=${{ github.event.pull_request.number }}
REPO_OWNER=${{ github.repository_owner }}
REPO_NAME=${{ github.event.repository.name }}
# calling GitHub API for changed files in PR, the result is in string format.
CHANGED_FILES=$(curl -s -H "Authorization: Bearer $GITHUB_TOKEN" \
"https://api.github.com/repos/$REPO_OWNER/$REPO_NAME/pulls/$PR_NUMBER/files" | \
jq -r '.[].filename' | tr '\n' ' ')
else
CHANGED_FILES=$(git diff --name-only HEAD~1 HEAD)
fi
echo "::set-output name=files::$CHANGED_FILES"
- name: Check Java changes
id: java
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n'| grep -qE '^(java/|pom.xml)'; then
echo "::set-output name=java::true"
else
echo "::set-output name=java::false"
fi
- name: Check C++ changes
id: cpp
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n'| grep -qE '^cpp/'; then
echo "::set-output name=cpp::true"
else
echo "::set-output name=cpp::false"
fi
- name: Check Golang changes
id: golang
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^golang/'; then
echo "::set-output name=golang::true"
else
echo "::set-output name=golang::false"
fi
- name: Check C# changes
id: csharp
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^csharp/'; then
echo "::set-output name=csharp::true"
else
echo "::set-output name=csharp::false"
fi
- name: Check PHP changes
id: php
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^php/'; then
echo "::set-output name=php::true"
else
echo "::set-output name=php::false"
fi
- name: Check Rust changes
id: rust
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^rust/'; then
echo "::set-output name=rust::true"
else
echo "::set-output name=rust::false"
fi
- name: Check Python changes
id: python
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^python/'; then
echo "::set-output name=python::true"
else
echo "::set-output name=python::false"
fi
- name: Check Node.js changes
id: nodejs
run: |
if echo "${{ steps.changed_files.outputs.files }}" | tr ' ' '\n' | grep -qE '^nodejs/'; then
echo "::set-output name=nodejs::true"
else
echo "::set-output name=nodejs::false"
fi
java-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.java == 'true' }}
uses: ./.github/workflows/java_build.yml
cpp-build:
needs: [paths-filter]
secrets: inherit
if: ${{ needs.paths-filter.outputs.cpp == 'true' }}
uses: ./.github/workflows/cpp_build.yml
csharp-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.csharp == 'true' }}
uses: ./.github/workflows/csharp_build.yml
golang-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.golang == 'true' }}
uses: ./.github/workflows/golang_build.yml
php-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.php == 'true' }}
uses: ./.github/workflows/php_build.yml
rust-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.rust == 'true' }}
uses: ./.github/workflows/rust_build.yml
python-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.python == 'true' }}
uses: ./.github/workflows/python_build.yml
nodejs-build:
needs: [paths-filter]
if: ${{ needs.paths-filter.outputs.nodejs == 'true' }}
uses: ./.github/workflows/nodejs_build.yml
build-result:
runs-on: ubuntu-latest
needs: [java-build, cpp-build, csharp-build, golang-build, php-build, rust-build, python-build, nodejs-build]
if: ${{ always() }}
steps:
- uses: actions/checkout@v2
- name: Collect build result
run: |
if echo java-${{ needs.java-build.result }},\
cpp-${{ needs.cpp-build.result }},\
csharp-${{ needs.csharp-build.result }},\
golang-${{ needs.golang-build.result }},\
php-${{ needs.php-build.result }},\
rust-${{ needs.rust-build.result }},\
nodejs-${{ needs.nodejs-build.result }},\
python-${{ needs.python-build.result }} | grep -E 'cancelled|failure' -o > null
then
echo "There are failed/cancelled builds"
exit 1
else
echo "All builds are successful/skipped"
exit 0
fi