Doc: Explain variables required for building Routing Service examples… #231
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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, | |
}); |