-
Notifications
You must be signed in to change notification settings - Fork 140
158 lines (135 loc) · 5.52 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
# 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:
runs-on: ubuntu-20.04
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 == "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 pr.zip
# Save the PR number to send messages to the user that opened it.
- name: Save PR number
if: ${{ github.event_name == 'workflow_run' }}
id: pr_number
run: echo '::set-output name=PR_NUMBER::'$(cat NR)
# 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.7
uses: actions/setup-python@v2
with:
python-version: 3.7
- 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 scan-build
# 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
env:
RTI_MIN_PACKAGE_URL: ${{ secrets.RTI_MIN_PACKAGE_URL }}
# 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,
});