Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Stage artifacts during CI run #17

Merged
merged 10 commits into from
Dec 6, 2023
Merged
55 changes: 55 additions & 0 deletions .github/artifacts/_stage_ci_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
"""Stage client files."""

from argparse import ArgumentParser
from pathlib import Path
from shutil import copy2
from tempfile import TemporaryDirectory

class _ArtifactLocations:
repo_root: Path

def __init__(self, repo_root: Path):
self.repo_root = repo_root

@property
def proto_files(self) -> Path:
return self.repo_root


def stage_ci_files(output_path: Path):
"""Stage the client files into the given output path."""
repo_root = Path(__file__).parent.parent.parent
artifact_locations = _ArtifactLocations(repo_root)

proto_path = output_path / "proto"
proto_path.mkdir(parents=True)

for file in artifact_locations.proto_files.glob("*.proto"):
copy2(file, proto_path)


if __name__ == "__main__":
parser = ArgumentParser(description="Stage ni-api files.")
parser.add_argument(
"--output",
"-o",
help="The path to the top-level directory to stage the client files. Must be empty or non-existent.",
)

args = parser.parse_args()

if args.output:
stage_ci_files(Path(args.output))
else:
print(
"""
***No --output directory specified.***
Performing Dry Run.
"""
)
with TemporaryDirectory() as tempdir:
tempdirpath = Path(tempdir)
stage_ci_files(tempdirpath)
created_files = (f for f in tempdirpath.glob("**/*") if not f.is_dir())
for out_file in created_files:
print(out_file.relative_to(tempdirpath))
7 changes: 7 additions & 0 deletions .github/artifacts/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions .github/artifacts/poetry.toml
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[virtualenvs]
in-project = true
15 changes: 15 additions & 0 deletions .github/artifacts/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
[tool.poetry]
name = "Stage artifacts"
version = "0.1"
description = "Stage artifacts for the CI build"
authors = ["NI <[email protected]>"]
readme = "README.md" # apply the repo readme to the package as well
repository = "https://github.com/ni/ni-apis/"
license = "MIT"

[tool.poetry.dependencies]
python = "^3.9"

[build-system]
requires = ["poetry-core>=1.2.0"]
build-backend = "poetry.core.masonry.api"
5 changes: 4 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,7 @@ on:
jobs:
check_protos:
name: Check .proto files
uses: ./.github/workflows/check_protos.yml
uses: ./.github/workflows/check_protos.yml
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved
create_ci_artifacts:
uses: ./.github/workflows/create_ci_artifacts.yml

45 changes: 45 additions & 0 deletions .github/workflows/create_ci_artifacts.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
name: Create CI Artifacts

on:
workflow_call:
workflow_dispatch:

env:
POETRY_VERSION: 1.2.2
PYTHON_VERSION: 3.9

jobs:
build:
name: 'Proto Artifacts'
runs-on: 'windows-latest'

steps:
- name: Checkout Repo
uses: actions/checkout@v2

- name: Setup python3
uses: actions/setup-python@v5
with:
python-version: ${{ env.PYTHON_VERSION }}

- name: Set up Poetry
uses: Gr1N/setup-poetry@v8
with:
poetry-version: ${{ env.POETRY_VERSION }}
- name: Cache virtualenv
uses: actions/cache@v3
with:
path: .github/check_protos/.venv
key: create-artifacts-${{ runner.os }}-py${{ env.PYTHON_VERSION }}-${{ hashFiles('.github/artifacts/poetry.lock') }}
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved

- name: Stage Client Files
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved
run: |
rsync -av --prune-empty-dirs --include "*/" --include "*.proto" --exclude "*" ni/ ${{ runner.temp }}/staging/ni/
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved

- name: Upload Windows Client Files Artifact
dixonjoel marked this conversation as resolved.
Show resolved Hide resolved
uses: actions/upload-artifact@v2
with:
name: ni-apis
path: |
${{ runner.temp }}/staging/ni
retention-days: 5
Loading