Skip to content

Commit 73b9199

Browse files
authored
COMMUNITY-15: Obtain RTI Connext bundles using credentials (#631)
* COMMUNITY-15: adapt linux_install to new S3 bucket * COMMUNITY-15: adapt build.yml to the new linux_install script * COMMUNITY-15: add requirements.txt for CI/CD * COMMUNITY-15: add AWS credentials * COMMUNITY-15: improve scripts safety * COMMUNITY-15: add double asterisk to create a glob * COMMUNITY-15: trying with space-checkout * COMMUNITY-15: reorder checkout for workflow_run * COMMUNITY-15: reorder checkout for workflow_run x2 * COMMUNITY-15: do not include the git folder in the artifact * COMMUNITY-15: do not clean in the checkout step * COMMUNITY-15: do checkout before downloading repo from PR * COMMUNITY-15: solve deprecation warnings * COMMUNITY-15: rename steps * COMMUNITY-15: update comment * COMMUNITY-15: update VERSION
1 parent 7a7fe71 commit 73b9199

File tree

7 files changed

+133
-171
lines changed

7 files changed

+133
-171
lines changed

.github/workflows/build.yml

Lines changed: 58 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,11 @@ on:
1818

1919
jobs:
2020
build:
21-
runs-on: ubuntu-20.04
21+
strategy:
22+
matrix:
23+
architecture: [{name: x64Linux4gcc7.3.0, os: ubuntu-20.04}]
24+
25+
runs-on: ${{ matrix.architecture.os }}
2226
name: Build examples
2327

2428
# This job will be executed if the "PR handler" finalized successfully or
@@ -33,6 +37,50 @@ jobs:
3337

3438
steps:
3539

40+
# Download the artifacts generated by "PR Handler" if this workflow was
41+
# triggered by a workflow_run event.
42+
- name: Download artifact
43+
if: ${{ github.event_name == 'workflow_run' }}
44+
uses: actions/[email protected]
45+
with:
46+
script: |
47+
var fs = require('fs');
48+
var artifacts = await github.actions.listWorkflowRunArtifacts({
49+
owner: context.repo.owner,
50+
repo: context.repo.repo,
51+
run_id: ${{ github.event.workflow_run.id }},
52+
});
53+
var matchArtifact = artifacts.data.artifacts.filter((artifact) => {
54+
return artifact.name == "targetbranch"
55+
})[0];
56+
var download = await github.actions.downloadArtifact({
57+
owner: context.repo.owner,
58+
repo: context.repo.repo,
59+
artifact_id: matchArtifact.id,
60+
archive_format: 'zip',
61+
});
62+
fs.writeFileSync('${{github.workspace}}/targetbranch.zip', Buffer.from(download.data));
63+
64+
# Unzip the artifacts.
65+
- name: Unzip artifact
66+
if: ${{ github.event_name == 'workflow_run' }}
67+
run: unzip targetbranch.zip
68+
69+
# Save the PR number to send messages to the user that opened it.
70+
- name: Get target branch
71+
if: ${{ github.event_name == 'workflow_run' }}
72+
id: target_branch
73+
run: echo "TARGET_BRANCH=$(cat targetbranch)" >> $GITHUB_OUTPUT
74+
75+
# Sparse-checkout: we clone just the scripts from the target branch for
76+
# sefaty reasons.
77+
- uses: actions/checkout@v4
78+
with:
79+
ref: ${{ steps.target_branch.outputs.TARGET_BRANCH }}
80+
sparse-checkout: resources/ci_cd/
81+
sparse-checkout-cone-mode: false
82+
if: ${{ github.event_name == 'workflow_run' }}
83+
3684
# Download the artifacts generated by "PR Handler" if this workflow was
3785
# triggered by a workflow_run event.
3886
- name: Download artifact
@@ -60,13 +108,13 @@ jobs:
60108
# Unzip the artifacts.
61109
- name: Unzip artifact
62110
if: ${{ github.event_name == 'workflow_run' }}
63-
run: unzip pr.zip
111+
run: unzip -n pr.zip
64112

65113
# Save the PR number to send messages to the user that opened it.
66-
- name: Save PR number
114+
- name: Get PR number
67115
if: ${{ github.event_name == 'workflow_run' }}
68116
id: pr_number
69-
run: echo '::set-output name=PR_NUMBER::'$(cat NR)
117+
run: echo "PR_NUMBER=$(cat NR)" >> $GITHUB_OUTPUT
70118

71119
# Send an information message to the user that opened the pull request.
72120
- name: Send information message
@@ -105,14 +153,17 @@ jobs:
105153
# Install the dependencies to run the Python scripts.
106154
- name: Install dependencies
107155
run: |
108-
pip install scan-build
156+
pip install -r resources/ci_cd/requirements.txt
109157
110158
# This script downloads the mandatory libraries of RTI Connext DDS for
111159
# compiling the examples
112160
- name: Install RTI Connext DDS
113-
run: python resources/ci_cd/linux_install.py
161+
run: python resources/ci_cd/linux_install.py -a ${{ matrix.architecture.name }}
114162
env:
115-
RTI_MIN_PACKAGE_URL: ${{ secrets.RTI_MIN_PACKAGE_URL }}
163+
AWS_ACCESS_KEY_ID: ${{ secrets.AWS_ACCESS_KEY_ID }}
164+
AWS_SECRET_ACCESS_KEY: ${{ secrets.AWS_SECRET_ACCESS_KEY }}
165+
RTI_AWS_BUCKET: ${{ secrets.RTI_AWS_BUCKET }}
166+
RTI_AWS_PATH: ${{ secrets.RTI_AWS_PATH }}
116167

117168
# This script will compile the examples and execute the static analysis.
118169
- name: Build all the examples

.github/workflows/prhandler.yml

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,11 +25,30 @@ jobs:
2525
- name: Save PR number
2626
run: echo ${{ github.event.number }} > ${{ github.workspace }}/NR
2727

28+
# Save the PR number for the next workflow to create the current
29+
# workflow artifact along with the repository itself.
30+
- name: Save target branch
31+
run: echo ${{ github.base_ref }} > ${{ github.workspace }}/targetbranch
32+
2833
# Upload the artifacts to GitHub so that they can be used in the next
2934
# workflow.
30-
- name: Upload generated artifact
35+
- name: Upload PR changes
3136
uses: actions/upload-artifact@v3
3237
with:
3338
name: pr
34-
path: ${{ github.workspace }}
39+
path: |
40+
${{ github.workspace }}
41+
!${{ github.workspace }}/resources/ci_cd
42+
!${{ github.workspace }}/.git
43+
!${{ github.workspace }}/targetbranch
44+
if-no-files-found: error
45+
46+
# Upload the artifacts to GitHub so that they can be used in the next
47+
# workflow.
48+
- name: Upload target branch name
49+
uses: actions/upload-artifact@v3
50+
with:
51+
name: targetbranch
52+
path: |
53+
${{ github.workspace }}/targetbranch
3554
if-no-files-found: error

VERSION

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
7.2.0

resources/aws/requirements.txt

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,2 @@
11
boto3
22
boto3_type_annotations
3-
pexpect

resources/ci_cd/linux_install.py

Lines changed: 50 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -14,46 +14,73 @@
1414
the minimal installation archive.
1515
1616
"""
17+
import argparse
1718
import os
1819
import sys
1920
import tempfile
20-
import urllib.request
21-
2221
from distutils.spawn import find_executable
23-
from pathlib import Path
22+
from pathlib import Path, PurePosixPath
2423
from subprocess import call
2524
from urllib.error import URLError
2625

26+
import boto3
27+
28+
ROOT_DIR = Path(__file__).resolve().parents[2]
29+
30+
31+
def parse_args() -> argparse.Namespace:
32+
"""Parse the CLI options."""
33+
parser = argparse.ArgumentParser()
34+
parser.add_argument("-a", "--architecture", type=str, required=True)
35+
parser.add_argument(
36+
"-i",
37+
"--install-parent-dir",
38+
type=Path,
39+
default=os.getenv("RTI_INSTALLATION_PATH") or Path.home(),
40+
)
41+
parser.add_argument(
42+
"-b", "--bucket", type=str, default=os.getenv("RTI_AWS_BUCKET")
43+
)
44+
parser.add_argument(
45+
"-p",
46+
"--s3-path",
47+
type=PurePosixPath,
48+
default=os.getenv("RTI_AWS_PATH"),
49+
)
50+
51+
args = parser.parse_args()
52+
53+
return args
54+
2755

2856
def main():
29-
rti_minimal_package_url = os.getenv("RTI_MIN_PACKAGE_URL")
30-
temp_dir = Path(tempfile.gettempdir())
31-
if not rti_minimal_package_url:
32-
sys.exit(
33-
"Environment variable RTI_MIN_PACKAGE_URL not found, skipping..."
34-
)
57+
args = parse_args()
58+
version = ROOT_DIR.joinpath("VERSION").read_text()
59+
downloaded_zipped_file_path = Path(
60+
tempfile.gettempdir(),
61+
f"rti_connext_dds-{version}-lm-{args.architecture}.zip",
62+
)
63+
remote_zipped_file_path = PurePosixPath(
64+
args.s3_path, version, downloaded_zipped_file_path.name
65+
)
66+
s3 = boto3.client("s3")
3567

3668
try:
37-
rti_installation_path = Path(
38-
os.getenv("RTI_INSTALLATION_PATH") or Path.home()
39-
).resolve(strict=True)
69+
rti_install_parent_dir = Path(args.install_parent_dir).resolve(
70+
strict=True
71+
)
4072
except FileNotFoundError:
41-
sys.exit("The RTI_INSTALLATION_PATH does not exist.")
73+
sys.exit(f"File not found: {args.install_parent_dir}")
4274

4375
cmake_command = find_executable("cmake")
4476
if cmake_command is None:
4577
sys.exit("CMake must be installed in order to use the script.")
4678

4779
try:
48-
rti_zipped_file_name = Path(
49-
urllib.request.url2pathname(rti_minimal_package_url)
50-
).name
51-
rti_zipped_file_path = temp_dir.joinpath(rti_zipped_file_name)
52-
urllib.request.urlretrieve(
53-
rti_minimal_package_url, rti_zipped_file_path
54-
)
80+
with open(downloaded_zipped_file_path, "wb") as f:
81+
s3.download_fileobj(args.bucket, str(remote_zipped_file_path), f)
5582
except URLError as e:
56-
sys.exit("Error opening the URL: {}".format(e))
83+
sys.exit(f"Error opening the object: {e}")
5784

5885
try:
5986
return_value = call(
@@ -62,10 +89,10 @@ def main():
6289
"-E",
6390
"tar",
6491
"xf",
65-
str(rti_zipped_file_path),
92+
str(downloaded_zipped_file_path),
6693
"--format=zip",
6794
],
68-
cwd=rti_installation_path,
95+
cwd=rti_install_parent_dir,
6996
)
7097
except FileNotFoundError:
7198
sys.exit("The CMake executable could not be found.")

resources/ci_cd/requirements.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
boto3
2+
boto3_type_annotations
3+
scan-build

resources/static_analysis/run_static_analysis.py

Lines changed: 0 additions & 138 deletions
This file was deleted.

0 commit comments

Comments
 (0)