Skip to content

Commit 0dc1726

Browse files
authored
Initial commit cli tool (#9)
* Initial commit cli tool * fix workflow for go tests
1 parent b813cc8 commit 0dc1726

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

61 files changed

+6534
-12
lines changed

.github/workflows/cli-tool-test.yaml

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Gh Foundations CLI Tool Test
2+
3+
on:
4+
pull_request:
5+
paths:
6+
- 'cli/**'
7+
workflow_dispatch:
8+
9+
jobs:
10+
build:
11+
12+
runs-on: ubuntu-latest
13+
strategy:
14+
matrix:
15+
go-version: [ '1.21.x' ]
16+
17+
steps:
18+
- uses: actions/checkout@v4
19+
- name: Setup Go ${{ matrix.go-version }}
20+
uses: actions/setup-go@v5
21+
with:
22+
go-version: ${{ matrix.go-version }}
23+
- name: Install dependencies
24+
run: |
25+
go install .
26+
working-directory: cli
27+
- name: Build
28+
run: go build -v ./...
29+
working-directory: cli
30+
- name: Test
31+
run: go test ./... -json > TestResults-${{ matrix.go-version }}.json
32+
working-directory: cli
33+
- name: Upload test results
34+
uses: actions/upload-artifact@v4
35+
with:
36+
name: Go-results-${{ matrix.go-version }}
37+
path: ./cli/TestResults-${{ matrix.go-version }}.json

.github/workflows/go-releaser.yaml

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
# .github/workflows/release.yml
2+
name: goreleaser
3+
4+
on:
5+
push:
6+
paths:
7+
- 'cli/**'
8+
# run only against tags
9+
tags:
10+
- "*"
11+
12+
permissions:
13+
contents: write
14+
# packages: write # write if you push Docker images to GitHub
15+
# issues: write # write if you use milestone closing capability
16+
17+
jobs:
18+
goreleaser:
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout
22+
uses: actions/checkout@v4
23+
with:
24+
fetch-depth: 0
25+
- name: Set up Go
26+
uses: actions/setup-go@v5
27+
with:
28+
go-version: stable
29+
token: ${{ secrets.GITHUB_TOKEN }}
30+
31+
- name: Run GoReleaser
32+
uses: goreleaser/goreleaser-action@v5
33+
with:
34+
# either 'goreleaser' (default) or 'goreleaser-pro'
35+
distribution: goreleaser
36+
# 'latest', 'nightly', or a semver
37+
version: "~> v1"
38+
args: release --clean
39+
workdir: cli
40+
env:
41+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cli/.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
2+
dist/

cli/.goreleaser.yaml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
# This is an example .goreleaser.yml file with some sensible defaults.
2+
# Make sure to check the documentation at https://goreleaser.com
3+
4+
# The lines below are called `modelines`. See `:help modeline`
5+
# Feel free to remove those if you don't want/need to use them.
6+
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
7+
# vim: set ts=2 sw=2 tw=0 fo=cnqoj
8+
9+
version: 1
10+
11+
before:
12+
hooks:
13+
# You may remove this if you don't use go modules.
14+
- go mod tidy
15+
# you may remove this if you don't need go generate
16+
- go generate ./...
17+
18+
builds:
19+
- env:
20+
- CGO_ENABLED=0
21+
goos:
22+
- linux
23+
- windows
24+
- darwin
25+
26+
archives:
27+
- format: tar.gz
28+
# this name template makes the OS and Arch compatible with the results of `uname`.
29+
name_template: >-
30+
{{ .ProjectName }}_
31+
{{- title .Os }}_
32+
{{- if eq .Arch "amd64" }}x86_64
33+
{{- else if eq .Arch "386" }}i386
34+
{{- else }}{{ .Arch }}{{ end }}
35+
{{- if .Arm }}v{{ .Arm }}{{ end }}
36+
# use zip for windows archives
37+
format_overrides:
38+
- goos: windows
39+
format: zip
40+
41+
changelog:
42+
sort: asc
43+
filters:
44+
exclude:
45+
- "^docs:"
46+
- "^test:"
47+
48+
release:
49+
mode: replace
50+
replace_existing_artifacts: true
51+
# Header for the release body.
52+
#
53+
# Templates: allowed
54+
header: |
55+
## GitHub Foundations CLI ({{ .Date }})
56+
57+
The latest release of the GitHub Foundations CLI.
58+
59+
# Footer for the release body.
60+
#
61+
# Templates: allowed
62+
footer: |
63+
## Thanks
64+
65+
Changes for tag: {{ .Tag }}!

cli/.mockery.yaml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
with-expecter: true
2+
packages:
3+
gh_foundations/internal/pkg/types:
4+
config:
5+
recursive: true
6+
all: true
7+
filename: "mock_{{.InterfaceName}}.go"
8+
dir: "{{.InterfaceDir}}/mocks"
9+
mockname: "Mock{{.InterfaceName}}"
10+
outpkg: "mocks"

cli/README.md

Lines changed: 178 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,178 @@
1+
# Github Foundations CLI
2+
A command-line tool for the Github Foundations framework.
3+
4+
## Table of Contents
5+
6+
- [Usage](#usage)
7+
- [Generate](#generate)
8+
- [Import](#import)
9+
- [Check](#check)
10+
- [List](#list)
11+
- [Help](#help)
12+
- [Installation](#installation)
13+
- [From releases](#from-releases)
14+
- [Linux](#linux)
15+
- [MacOS](#macos)
16+
- [Windows](#windows)
17+
- [From source](#from-source)
18+
19+
## Usage
20+
21+
There are a few main tools provided by the Github Foundations CLI:
22+
23+
```
24+
Usage:
25+
github-foundations-cli [command]
26+
27+
Available Commands:
28+
gen Generate HCL input for GitHub Foundations.
29+
import Starts an interactive import process for resources in a Terraform plan.
30+
check Perform checks against a Github configuration.
31+
list List various resources managed by the tool.
32+
help Help about any command.
33+
34+
Flags:
35+
-h, -- help help for github-foundations-cli
36+
```
37+
38+
### Generate
39+
40+
#### Generate using the Interactive mode
41+
42+
This command is used to generate HCL input for GitHub Foundations. This tool is used to generate HCL input for GitHub Foundations from state files output by terraformer.
43+
44+
```
45+
Usage:
46+
github-foundations-cli gen <resource>
47+
```
48+
49+
Where `<resource>` is one of the following:
50+
- `repository_set`
51+
52+
Use `Shift + →` (right arrow) and `Shift + ←` (left arrow) to navigate through the questions.
53+
54+
Click on `Submit` to generate the HCL file.
55+
56+
### Import
57+
58+
This command will start an interactive process to import resources into Terraform state. It uses the results of a terraform plan to determine which resources are available for import.
59+
60+
```
61+
Usage:
62+
github-foundations-cli import [module_path]
63+
64+
```
65+
66+
Where `<module_path>` is the path to the Terragrunt module to import.
67+
68+
### Check
69+
70+
Perform checks against a Github configuration and generate reports. This is used to validate the compliance stance of your GitHub configuration.
71+
72+
```
73+
Usage:
74+
github-foundations-cli check <org-slug>
75+
76+
```
77+
78+
Where `<org-slug>` is the organization slug to check.
79+
80+
### List
81+
82+
list various resources managed by the tool.
83+
84+
85+
```
86+
Usage:
87+
github-foundations-cli list <resource> [options] [ProjectsDirectory|OrganzationsDirectory]
88+
89+
```
90+
91+
Where `<resource>` is one of the following:
92+
- repos
93+
- orgs
94+
95+
96+
`[ProjectsDirectory]` is the path to the Terragrunt `Projects` directory when listing `repos`.
97+
98+
`[OrganzationsDirectory]` is the path to the Terragrunt `OrganzationsDirectory` directory when listing `orgs`.
99+
100+
`[options]` is a list of options to filter the list of resources. The options are:
101+
- repos:
102+
- `--ghas`, `-g` List repositories with GHAS enabled.
103+
104+
### Help
105+
106+
Display help for the tool.
107+
108+
## Installation
109+
110+
### From releases
111+
Download the latest release from the [releases page](http:github.com/canada-ca/fondations-github-foundations/releases) and run the following commands:
112+
113+
114+
#### Linux
115+
116+
**ADM64**
117+
```
118+
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Linux_x86_64.tar.gz
119+
tar -xzf github-foundations-cli_Linux_x86_64.tar.gz
120+
chmod +x github-foundations-cli
121+
sudo mv github-foundations-cli /usr/local/bin
122+
```
123+
124+
**ARM64**
125+
```
126+
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Linux_arm64.tar.gz
127+
tar -xzf github-foundations-cli_Linux_arm64.tar.gz
128+
chmod +x github-foundations-cli
129+
sudo mv github-foundations-cli /usr/local/bin
130+
```
131+
132+
#### MacOS
133+
134+
**ADM64**
135+
```
136+
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Darwin_x86_64.tar.gz
137+
tar -xzf github-foundations-cli_Darwin_x86_64.tar.gz
138+
chmod +x github-foundations-cli
139+
sudo mv github-foundations-cli /usr/local/bin
140+
```
141+
142+
**ARM64**
143+
```
144+
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Darwin_arm64.tar.gz
145+
tar -xzf github-foundations-cli_Darwin_arm64.tar.gz
146+
chmod +x github-foundations-cli
147+
sudo mv github-foundations-cli /usr/local/bin
148+
```
149+
150+
#### Windows
151+
152+
---
153+
**i386**
154+
155+
1. Download the [latest release here](https://github.com/canada-ca/fondations-github-foundations/releases/download/v0.0.5/github-foundations-cli_Windows_i386.zip)
156+
157+
**ADM64**
158+
1. Download the [latest release here](https://github.com/canada-ca/fondations-github-foundations/releases/download/v0.0.5/github-foundations-cli_Windows_i386.zip)
159+
160+
**ARM64**
161+
1. Download the [latest release here](https://github.com/canada-ca/fondations-github-foundations/releases/download/v0.0.5/github-foundations-cli_Windows_i386.zip)
162+
---
163+
164+
2. Unzip the package
165+
3. Place the `github-foundations-cli.exe` executable in a directory of your choice, for example: `%USERPROFILE%\gh-foundations`
166+
167+
* **Add to Path (Optional):**
168+
4. Right-click on "This PC" and select "Properties".
169+
5. Click on "Advanced system settings".
170+
6. Click on the "Environment Variables" button.
171+
7. Under "System variables", find the "Path" variable and click "Edit".
172+
8. Click "New" and add the following path: `%USERPROFILE%\gh-foundations` (replace with your chosen directory)
173+
9. Click "OK" on all open windows to save the changes.
174+
175+
### From source
176+
1. Run `git clone git@github.com:canada-ca/fondations-github-foundations && cd github-foundations-cli/`
177+
2. Run `go mod download`
178+
3. Run `go build -v` for all providers OR build with one provider

0 commit comments

Comments
 (0)