-
Notifications
You must be signed in to change notification settings - Fork 140
209 lines (181 loc) · 7.64 KB
/
build.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
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
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# This workflow was created to access the repository secrets in a safe way when
# a Pull Request is opened. If this workflow was triggered by "PR handler"
# completion, it will download the artifacts generated by the completed
# workflow (that contains the changes and the resources to compile all the
# examples). On the other hand, if this workflow was triggered by a push event,
# it will execute a checkout to get all the changes.
name: Build and run static analysis
on:
push:
branches:
- master
workflow_run:
workflows: ["PR handler"]
types:
- completed
jobs:
build:
strategy:
matrix:
architecture: [{name: x64Linux4gcc7.3.0, os: ubuntu-20.04}]
runs-on: ${{ matrix.architecture.os }}
name: Build examples
# This job will be executed if the "PR handler" finalized successfully or
# if this workflow was triggered by a push event.
if: >
${{ (github.event.workflow_run.event == 'pull_request' &&
github.event.workflow_run.conclusion == 'success') ||
github.event_name == 'push' }}
outputs:
pr_number: ${{ steps.pr_number.outputs.PR_NUMBER }}
steps:
# Download the artifacts generated by "PR Handler" if this workflow was
# triggered by a workflow_run event.
- name: Download artifact
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v3.1.0
with:
script: |
var fs = require('fs');
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "targetbranch"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/targetbranch.zip', Buffer.from(download.data));
# Unzip the artifacts.
- name: Unzip artifact
if: ${{ github.event_name == 'workflow_run' }}
run: unzip targetbranch.zip
# Save the PR number to send messages to the user that opened it.
- name: Get target branch
if: ${{ github.event_name == 'workflow_run' }}
id: target_branch
run: echo "TARGET_BRANCH=$(cat targetbranch)" >> $GITHUB_OUTPUT
# Sparse-checkout: we clone just the scripts from the target branch for
# sefaty reasons.
- uses: actions/checkout@v4
with:
ref: ${{ steps.target_branch.outputs.TARGET_BRANCH }}
sparse-checkout: resources/ci_cd/
sparse-checkout-cone-mode: false
if: ${{ github.event_name == 'workflow_run' }}
# Download the artifacts generated by "PR Handler" if this workflow was
# triggered by a workflow_run event.
- name: Download artifact
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v3.1.0
with:
script: |
var fs = require('fs');
var artifacts = await github.actions.listWorkflowRunArtifacts({
owner: context.repo.owner,
repo: context.repo.repo,
run_id: ${{ github.event.workflow_run.id }},
});
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
return artifact.name == "pr"
})[0];
var download = await github.actions.downloadArtifact({
owner: context.repo.owner,
repo: context.repo.repo,
artifact_id: matchArtifact.id,
archive_format: 'zip',
});
fs.writeFileSync('${{github.workspace}}/pr.zip', Buffer.from(download.data));
# Unzip the artifacts.
- name: Unzip artifact
if: ${{ github.event_name == 'workflow_run' }}
run: unzip -n pr.zip
# Save the PR number to send messages to the user that opened it.
- name: Get PR number
if: ${{ github.event_name == 'workflow_run' }}
id: pr_number
run: echo "PR_NUMBER=$(cat NR)" >> $GITHUB_OUTPUT
# Send an information message to the user that opened the pull request.
- name: Send information message
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v3.1.0
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var issue_number = ${{ steps.pr_number.outputs.PR_NUMBER }};
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: `The compilation is starting. Take a look [here](https://github.com/${context.repo.owner}/${context.repo.repo}/actions/runs/${context.runId}).`
});
# If this workflow was triggered by a push event, it will download the
# repository with the changes.
- uses: actions/checkout@v3
with:
submodules: true
if: ${{ github.event_name == 'push' }}
# Setup Python. If you need another version, just change it below.
- name: Setup Python 3.11
uses: actions/setup-python@v2
with:
python-version: 3.11
- name: Set up Clang
uses: egor-tensin/setup-clang@v1
with:
version: 13
platform: x64
# Install the dependencies to run the Python scripts.
- name: Install dependencies
run: |
pip install -r resources/ci_cd/requirements.txt
# This script downloads the mandatory libraries of RTI Connext DDS for
# compiling the examples
- name: Install RTI Connext DDS
run: python resources/ci_cd/linux_install.py -a ${{ matrix.architecture.name }}
env:
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
RTI_AWS_BUCKET: ${{ secrets.RTI_AWS_BUCKET }}
RTI_AWS_PATH: ${{ secrets.RTI_AWS_PATH }}
# This script will compile the examples and execute the static analysis.
- name: Build all the examples
run: python resources/ci_cd/linux_build.py
- name: Peform the static analysis
run: python resources/ci_cd/linux_static_analysis.py
commentpr:
runs-on: ubuntu-latest
needs: build
name: Comment PR
# This job will be executed if this workflow was triggered by a
# workflow_run event even if the build job failed or succeeded.
if: ${{ always() && github.event_name == 'workflow_run' }}
steps:
# This job will create a comment on the Pull Request reporting if the
# build finished successfully or failed.
- name: Comment on PR
if: ${{ github.event_name == 'workflow_run' }}
uses: actions/github-script@v3
env:
ISSUE_NUMBER: ${{ needs.build.outputs.pr_number }}
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
script: |
var message;
if ('${{ needs.build.result }}' == 'success')
message = 'Everything is OK. Thank you for the PR!';
else
message = 'Oops, something went wrong!';
var issue_number = ${{ needs.build.outputs.pr_number }};
await github.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: issue_number,
body: message,
});