Skip to content

Commit 1359a2d

Browse files
authored
Merge pull request #509 from opsmill/develop
Merge 'develop' into 'stable' for SDK 1.14 & Infrahub 1.4
2 parents ed76689 + c1a1fb0 commit 1359a2d

File tree

20 files changed

+344
-77
lines changed

20 files changed

+344
-77
lines changed

.github/workflows/ci.yml

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ jobs:
4646
github_workflows: ${{ steps.changes.outputs.github_workflows }}
4747
steps:
4848
- name: "Check out repository code"
49-
uses: "actions/checkout@v4"
49+
uses: "actions/checkout@v5"
5050
- name: Check for file changes
5151
uses: dorny/paths-filter@v3
5252
id: changes
@@ -63,7 +63,7 @@ jobs:
6363
timeout-minutes: 5
6464
steps:
6565
- name: "Check out repository code"
66-
uses: "actions/checkout@v4"
66+
uses: "actions/checkout@v5"
6767
- name: "Setup environment"
6868
run: "pip install yamllint==1.35.1"
6969
- name: "Linting: yamllint"
@@ -76,7 +76,7 @@ jobs:
7676
timeout-minutes: 5
7777
steps:
7878
- name: "Check out repository code"
79-
uses: "actions/checkout@v4"
79+
uses: "actions/checkout@v5"
8080
- name: "Setup environment"
8181
run: "pip install ruff==0.11.0"
8282
- name: "Linting: ruff check"
@@ -94,7 +94,7 @@ jobs:
9494
timeout-minutes: 5
9595
steps:
9696
- name: "Check out repository code"
97-
uses: "actions/checkout@v4"
97+
uses: "actions/checkout@v5"
9898
- name: "Linting: markdownlint"
9999
uses: DavidAnson/markdownlint-cli2-action@v20
100100
with:
@@ -110,7 +110,7 @@ jobs:
110110
timeout-minutes: 5
111111
steps:
112112
- name: "Check out repository code"
113-
uses: "actions/checkout@v4"
113+
uses: "actions/checkout@v5"
114114
- name: Check workflow files
115115
run: |
116116
bash <(curl https://raw.githubusercontent.com/rhysd/actionlint/main/scripts/download-actionlint.bash)
@@ -134,7 +134,7 @@ jobs:
134134
timeout-minutes: 5
135135
steps:
136136
- name: "Check out repository code"
137-
uses: "actions/checkout@v4"
137+
uses: "actions/checkout@v5"
138138
with:
139139
submodules: true
140140
- name: Install NodeJS
@@ -161,7 +161,7 @@ jobs:
161161
timeout-minutes: 5
162162
steps:
163163
- name: "Check out repository code"
164-
uses: "actions/checkout@v4"
164+
uses: "actions/checkout@v5"
165165
with:
166166
submodules: true
167167
- name: Set up Python
@@ -190,7 +190,7 @@ jobs:
190190
timeout-minutes: 5
191191
steps:
192192
- name: "Check out repository code"
193-
uses: "actions/checkout@v4"
193+
uses: "actions/checkout@v5"
194194
with:
195195
submodules: true
196196

@@ -227,7 +227,7 @@ jobs:
227227
timeout-minutes: 30
228228
steps:
229229
- name: "Check out repository code"
230-
uses: "actions/checkout@v4"
230+
uses: "actions/checkout@v5"
231231
- name: Set up Python ${{ matrix.python-version }}
232232
uses: actions/setup-python@v5
233233
with:
@@ -276,7 +276,7 @@ jobs:
276276
timeout-minutes: 30
277277
steps:
278278
- name: "Check out repository code"
279-
uses: "actions/checkout@v4"
279+
uses: "actions/checkout@v5"
280280
- name: Set up Python
281281
uses: actions/setup-python@v5
282282
with:
@@ -316,14 +316,14 @@ jobs:
316316
# timeout-minutes: 30
317317
# steps:
318318
# - name: "Check out repository code"
319-
# uses: "actions/checkout@v4"
319+
# uses: "actions/checkout@v5"
320320

321321
# - name: "Extract target branch name"
322322
# id: extract_branch
323323
# run: echo "TARGET_BRANCH=${{ github.base_ref }}" >> $GITHUB_ENV
324324

325325
# - name: "Checkout infrahub repository"
326-
# uses: "actions/checkout@v4"
326+
# uses: "actions/checkout@v5"
327327
# with:
328328
# repository: "opsmill/infrahub"
329329
# path: "infrahub-server"

.github/workflows/labels.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
steps:
1818
-
1919
name: Checkout
20-
uses: actions/checkout@v4
20+
uses: actions/checkout@v5
2121
-
2222
name: Run Labeler
2323
uses: crazy-max/ghaction-github-labeler@v5

.github/workflows/publish-pypi.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ jobs:
5050
installer-parallel: true
5151

5252
- name: "Check out repository code"
53-
uses: "actions/checkout@v4"
53+
uses: "actions/checkout@v5"
5454
with:
5555
submodules: true
5656

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jobs:
2121
latest_tag: ${{ steps.release.outputs.latest_tag }}
2222
steps:
2323
- name: "Check out repository code"
24-
uses: "actions/checkout@v4"
24+
uses: "actions/checkout@v5"
2525
with:
2626
submodules: true
2727

.github/workflows/repository-dispatch.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ jobs:
4242

4343
steps:
4444
- name: Checkout code
45-
uses: actions/checkout@v4
45+
uses: actions/checkout@v5
4646

4747
- name: Repository Dispatch
4848
uses: peter-evans/repository-dispatch@v3

.github/workflows/sync-docs.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@ jobs:
1616
runs-on: ubuntu-latest
1717
steps:
1818
- name: Checkout source repository
19-
uses: actions/checkout@v4
19+
uses: actions/checkout@v5
2020
with:
2121
path: source-repo
2222

2323
- name: Checkout target repository
24-
uses: actions/checkout@v4
24+
uses: actions/checkout@v5
2525
with:
2626
repository: opsmill/infrahub-docs
2727
token: ${{ secrets.PAT_TOKEN }}

.github/workflows/update-submodule.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ jobs:
3333
runs-on: ubuntu-22.04
3434
steps:
3535
- name: Checkout code
36-
uses: actions/checkout@v4
36+
uses: actions/checkout@v5
3737

3838
- name: Trigger submodule update
3939
run: |

changelog/466.added.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Added `infrahubctl repository init` command to allow the initialization of an Infrahub repository using [infrahub-template](https://github.com/opsmill/infrahub-template).

docs/docs/infrahubctl/infrahubctl-repository.mdx

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ $ infrahubctl repository [OPTIONS] COMMAND [ARGS]...
1919
**Commands**:
2020

2121
* `add`: Add a new repository.
22+
* `init`: Initialize a new Infrahub repository.
2223
* `list`
2324

2425
## `infrahubctl repository add`
@@ -47,6 +48,29 @@ $ infrahubctl repository add [OPTIONS] NAME LOCATION
4748
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
4849
* `--help`: Show this message and exit.
4950

51+
## `infrahubctl repository init`
52+
53+
Initialize a new Infrahub repository.
54+
55+
**Usage**:
56+
57+
```console
58+
$ infrahubctl repository init [OPTIONS] DIRECTORY
59+
```
60+
61+
**Arguments**:
62+
63+
* `DIRECTORY`: Directory path for the new project. [required]
64+
65+
**Options**:
66+
67+
* `--template TEXT`: Template to use for the new repository. Can be a local path or a git repository URL. [default: https://github.com/opsmill/infrahub-template.git]
68+
* `--data PATH`: Path to YAML file containing answers to CLI prompt.
69+
* `--vcs-ref TEXT`: VCS reference to use for the template. Defaults to HEAD. [default: HEAD]
70+
* `--trust / --no-trust`: Trust the template repository. If set, the template will be cloned without verification. [default: no-trust]
71+
* `--config-file TEXT`: [env var: INFRAHUBCTL_CONFIG; default: infrahubctl.toml]
72+
* `--help`: Show this message and exit.
73+
5074
## `infrahubctl repository list`
5175

5276
**Usage**:

infrahub_sdk/ctl/repository.py

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
from __future__ import annotations
22

3+
import asyncio
34
from pathlib import Path
45
from typing import Optional
56

67
import typer
78
import yaml
9+
from copier import run_copy
810
from pydantic import ValidationError
911
from rich.console import Console
1012
from rich.table import Table
@@ -165,3 +167,52 @@ async def list(
165167
)
166168

167169
console.print(table)
170+
171+
172+
@app.command()
173+
async def init(
174+
directory: Path = typer.Argument(help="Directory path for the new project."),
175+
template: str = typer.Option(
176+
default="https://github.com/opsmill/infrahub-template.git",
177+
help="Template to use for the new repository. Can be a local path or a git repository URL.",
178+
),
179+
data: Optional[Path] = typer.Option(default=None, help="Path to YAML file containing answers to CLI prompt."),
180+
vcs_ref: Optional[str] = typer.Option(
181+
default="HEAD",
182+
help="VCS reference to use for the template. Defaults to HEAD.",
183+
),
184+
trust: Optional[bool] = typer.Option(
185+
default=False,
186+
help="Trust the template repository. If set, the template will be cloned without verification.",
187+
),
188+
_: str = CONFIG_PARAM,
189+
) -> None:
190+
"""Initialize a new Infrahub repository."""
191+
192+
config_data = None
193+
if data:
194+
try:
195+
with Path.open(data, encoding="utf-8") as file:
196+
config_data = yaml.safe_load(file)
197+
typer.echo(f"Loaded config: {config_data}")
198+
except Exception as exc:
199+
typer.echo(f"Error loading YAML file: {exc}", err=True)
200+
raise typer.Exit(code=1)
201+
202+
# Allow template to be a local path or a URL
203+
template_source = template or ""
204+
if template and Path(template).exists():
205+
template_source = str(Path(template).resolve())
206+
207+
try:
208+
await asyncio.to_thread(
209+
run_copy,
210+
template_source,
211+
str(directory),
212+
data=config_data,
213+
vcs_ref=vcs_ref,
214+
unsafe=trust,
215+
)
216+
except Exception as e:
217+
typer.echo(f"Error running copier: {e}", err=True)
218+
raise typer.Exit(code=1)

0 commit comments

Comments
 (0)