Skip to content

Commit

Permalink
Initial commit cli tool (#9)
Browse files Browse the repository at this point in the history
* Initial commit cli tool

* fix workflow for go tests
  • Loading branch information
bzarboni1 authored Sep 24, 2024
1 parent b813cc8 commit 0dc1726
Show file tree
Hide file tree
Showing 61 changed files with 6,534 additions and 12 deletions.
37 changes: 37 additions & 0 deletions .github/workflows/cli-tool-test.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
name: Gh Foundations CLI Tool Test

on:
pull_request:
paths:
- 'cli/**'
workflow_dispatch:

jobs:
build:

runs-on: ubuntu-latest
strategy:
matrix:
go-version: [ '1.21.x' ]

steps:
- uses: actions/checkout@v4
- name: Setup Go ${{ matrix.go-version }}
uses: actions/setup-go@v5
with:
go-version: ${{ matrix.go-version }}
- name: Install dependencies
run: |
go install .
working-directory: cli
- name: Build
run: go build -v ./...
working-directory: cli
- name: Test
run: go test ./... -json > TestResults-${{ matrix.go-version }}.json
working-directory: cli
- name: Upload test results
uses: actions/upload-artifact@v4
with:
name: Go-results-${{ matrix.go-version }}
path: ./cli/TestResults-${{ matrix.go-version }}.json
41 changes: 41 additions & 0 deletions .github/workflows/go-releaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# .github/workflows/release.yml
name: goreleaser

on:
push:
paths:
- 'cli/**'
# run only against tags
tags:
- "*"

permissions:
contents: write
# packages: write # write if you push Docker images to GitHub
# issues: write # write if you use milestone closing capability

jobs:
goreleaser:
runs-on: ubuntu-latest
steps:
- name: Checkout
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Set up Go
uses: actions/setup-go@v5
with:
go-version: stable
token: ${{ secrets.GITHUB_TOKEN }}

- name: Run GoReleaser
uses: goreleaser/goreleaser-action@v5
with:
# either 'goreleaser' (default) or 'goreleaser-pro'
distribution: goreleaser
# 'latest', 'nightly', or a semver
version: "~> v1"
args: release --clean
workdir: cli
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
2 changes: 2 additions & 0 deletions cli/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

dist/
65 changes: 65 additions & 0 deletions cli/.goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# This is an example .goreleaser.yml file with some sensible defaults.
# Make sure to check the documentation at https://goreleaser.com

# The lines below are called `modelines`. See `:help modeline`
# Feel free to remove those if you don't want/need to use them.
# yaml-language-server: $schema=https://goreleaser.com/static/schema.json
# vim: set ts=2 sw=2 tw=0 fo=cnqoj

version: 1

before:
hooks:
# You may remove this if you don't use go modules.
- go mod tidy
# you may remove this if you don't need go generate
- go generate ./...

builds:
- env:
- CGO_ENABLED=0
goos:
- linux
- windows
- darwin

archives:
- format: tar.gz
# this name template makes the OS and Arch compatible with the results of `uname`.
name_template: >-
{{ .ProjectName }}_
{{- title .Os }}_
{{- if eq .Arch "amd64" }}x86_64
{{- else if eq .Arch "386" }}i386
{{- else }}{{ .Arch }}{{ end }}
{{- if .Arm }}v{{ .Arm }}{{ end }}
# use zip for windows archives
format_overrides:
- goos: windows
format: zip

changelog:
sort: asc
filters:
exclude:
- "^docs:"
- "^test:"

release:
mode: replace
replace_existing_artifacts: true
# Header for the release body.
#
# Templates: allowed
header: |
## GitHub Foundations CLI ({{ .Date }})
The latest release of the GitHub Foundations CLI.
# Footer for the release body.
#
# Templates: allowed
footer: |
## Thanks
Changes for tag: {{ .Tag }}!
10 changes: 10 additions & 0 deletions cli/.mockery.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
with-expecter: true
packages:
gh_foundations/internal/pkg/types:
config:
recursive: true
all: true
filename: "mock_{{.InterfaceName}}.go"
dir: "{{.InterfaceDir}}/mocks"
mockname: "Mock{{.InterfaceName}}"
outpkg: "mocks"
178 changes: 178 additions & 0 deletions cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
# Github Foundations CLI
A command-line tool for the Github Foundations framework.

## Table of Contents

- [Usage](#usage)
- [Generate](#generate)
- [Import](#import)
- [Check](#check)
- [List](#list)
- [Help](#help)
- [Installation](#installation)
- [From releases](#from-releases)
- [Linux](#linux)
- [MacOS](#macos)
- [Windows](#windows)
- [From source](#from-source)

## Usage

There are a few main tools provided by the Github Foundations CLI:

```
Usage:
github-foundations-cli [command]
Available Commands:
gen Generate HCL input for GitHub Foundations.
import Starts an interactive import process for resources in a Terraform plan.
check Perform checks against a Github configuration.
list List various resources managed by the tool.
help Help about any command.
Flags:
-h, -- help help for github-foundations-cli
```

### Generate

#### Generate using the Interactive mode

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.

```
Usage:
github-foundations-cli gen <resource>
```

Where `<resource>` is one of the following:
- `repository_set`

Use `Shift + →` (right arrow) and `Shift + ←` (left arrow) to navigate through the questions.

Click on `Submit` to generate the HCL file.

### Import

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.

```
Usage:
github-foundations-cli import [module_path]
```

Where `<module_path>` is the path to the Terragrunt module to import.

### Check

Perform checks against a Github configuration and generate reports. This is used to validate the compliance stance of your GitHub configuration.

```
Usage:
github-foundations-cli check <org-slug>
```

Where `<org-slug>` is the organization slug to check.

### List

list various resources managed by the tool.


```
Usage:
github-foundations-cli list <resource> [options] [ProjectsDirectory|OrganzationsDirectory]
```

Where `<resource>` is one of the following:
- repos
- orgs


`[ProjectsDirectory]` is the path to the Terragrunt `Projects` directory when listing `repos`.

`[OrganzationsDirectory]` is the path to the Terragrunt `OrganzationsDirectory` directory when listing `orgs`.

`[options]` is a list of options to filter the list of resources. The options are:
- repos:
- `--ghas`, `-g` List repositories with GHAS enabled.

### Help

Display help for the tool.

## Installation

### From releases
Download the latest release from the [releases page](http:github.com/canada-ca/fondations-github-foundations/releases) and run the following commands:


#### Linux

**ADM64**
```
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Linux_x86_64.tar.gz
tar -xzf github-foundations-cli_Linux_x86_64.tar.gz
chmod +x github-foundations-cli
sudo mv github-foundations-cli /usr/local/bin
```

**ARM64**
```
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Linux_arm64.tar.gz
tar -xzf github-foundations-cli_Linux_arm64.tar.gz
chmod +x github-foundations-cli
sudo mv github-foundations-cli /usr/local/bin
```

#### MacOS

**ADM64**
```
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Darwin_x86_64.tar.gz
tar -xzf github-foundations-cli_Darwin_x86_64.tar.gz
chmod +x github-foundations-cli
sudo mv github-foundations-cli /usr/local/bin
```

**ARM64**
```
curl -LO https://github.com/canada-ca/fondations-github-foundations/releases/latest/download/github-foundations-cli_Darwin_arm64.tar.gz
tar -xzf github-foundations-cli_Darwin_arm64.tar.gz
chmod +x github-foundations-cli
sudo mv github-foundations-cli /usr/local/bin
```

#### Windows

---
**i386**

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)

**ADM64**
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)

**ARM64**
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)
---

2. Unzip the package
3. Place the `github-foundations-cli.exe` executable in a directory of your choice, for example: `%USERPROFILE%\gh-foundations`

* **Add to Path (Optional):**
4. Right-click on "This PC" and select "Properties".
5. Click on "Advanced system settings".
6. Click on the "Environment Variables" button.
7. Under "System variables", find the "Path" variable and click "Edit".
8. Click "New" and add the following path: `%USERPROFILE%\gh-foundations` (replace with your chosen directory)
9. Click "OK" on all open windows to save the changes.

### From source
1. Run `git clone git@github.com:canada-ca/fondations-github-foundations && cd github-foundations-cli/`
2. Run `go mod download`
3. Run `go build -v` for all providers OR build with one provider
Loading

0 comments on commit 0dc1726

Please sign in to comment.