Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Steurer <[email protected]>

saving work

Signed-off-by: Andrew Steurer <[email protected]>

major changes

Signed-off-by: Andrew Steurer <[email protected]>

adding pluginify manifest

Signed-off-by: Andrew Steurer <[email protected]>

adding gitignore

Signed-off-by: Andrew Steurer <[email protected]>

small refactors

Signed-off-by: Andrew Steurer <[email protected]>

updating comments

Signed-off-by: Andrew Steurer <[email protected]>

saving work

Signed-off-by: Andrew Steurer <[email protected]>

saving work

Signed-off-by: Andrew Steurer <[email protected]>

saving work

Signed-off-by: Andrew Steurer <[email protected]>

saving work

Signed-off-by: Andrew Steurer <[email protected]>

update README and update comments

Signed-off-by: Andrew Steurer <[email protected]>

adding tests + other refactors

Signed-off-by: Andrew Steurer <[email protected]>

adding tests to actions

Signed-off-by: Andrew Steurer <[email protected]>

editing root command description

Signed-off-by: Andrew Steurer <[email protected]>

fixing bug

Signed-off-by: Andrew Steurer <[email protected]>

updating top-level var formatting

Signed-off-by: Andrew Steurer <[email protected]>

fixing version number

Signed-off-by: Andrew Steurer <[email protected]>
  • Loading branch information
asteurer committed Aug 29, 2024
1 parent 0d2ddaa commit 5a6f21b
Show file tree
Hide file tree
Showing 16 changed files with 1,230 additions and 0 deletions.
120 changes: 120 additions & 0 deletions .github/workflows/main.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
name: Release

on:
push:
branches: [main]
tags: ["v*"]
pull_request:
branches: [main]
workflow_dispatch:

env:
PROGRAM_NAME: blueprint
SPIN_VERSION: v2.7.0
jobs:
test-and-build:
name: Run the tests, and build plugin binaries
runs-on: ubuntu-latest
strategy:
matrix:
config:
# The architectures and operating systems accepted by Golang and the Pluginify tool are different for macos + arm64
- { goArch: "amd64", goOs: "linux", pluginifyArch: "amd64", pluginifyOs: linux}
- { goArch: "arm64", goOs: "linux", pluginifyArch: "aarch64", pluginifyOs: linux}
- { goArch: "arm64", goOs: "darwin", pluginifyArch: "amd64", pluginifyOs: macos}
- { goArch: "amd64", goOs: "darwin", pluginifyArch: "aarch64", pluginifyOs: macos}
steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup Go
uses: actions/setup-go@v5
with:
go-version: stable

- name: Run tests
run: make test

- name: Install Spin
uses: rajatjindal/setup-actions/spin@main
with:
version: ${{ env.SPIN_VERSION }}

- name: Install Pluginify
run: spin plugins install --url https://github.com/itowlson/spin-pluginify/releases/download/canary/pluginify.json --yes

- name: Build Plugin Binary
run: GOOS=${{ matrix.config.goOs }} GOARCH=${{ matrix.config.goArch }} go build -o ${{ env.PROGRAM_NAME }} main.go

- name: Create Arch-Specific Plugin Manifest
run: spin pluginify --arch ${{ matrix.config.pluginifyArch }} --os ${{ matrix.config.pluginifyOs }}

- name: Archive Binary and Manifest
uses: actions/upload-artifact@v4
with:
name: ${{ env.PROGRAM_NAME}}-${{ matrix.config.pluginifyOs }}-${{ matrix.config.pluginifyArch }}
path: |
*.tar.gz
*.json
package:
name: Package Plugin
runs-on: ubuntu-latest
permissions:
contents: write
needs: test-and-build
if: github.event_name == 'push'
steps:
- name: Install Spin
uses: rajatjindal/setup-actions/spin@main
with:
version: ${{ env.SPIN_VERSION }}
- name: Install Pluginify
run: spin plugins install --url https://github.com/itowlson/spin-pluginify/releases/download/canary/pluginify.json --yes

- name: set the release version (tag)
if: startsWith(github.ref, 'refs/tags/v')
run: echo "RELEASE_VERSION=${GITHUB_REF/refs\/tags\//}" >> $GITHUB_ENV
- name: set the release version (main)
if: github.ref == 'refs/heads/main'
run: echo "RELEASE_VERSION=canary" >> $GITHUB_ENV

- name: Download artifacts
uses: actions/download-artifact@v4
- name: Display structure of downloaded files
run: ls -R
- name: pluginify it
run: |
spin pluginify --merge --release-url-base https://github.com/fermyon/blueprint-plugin/releases/download/${{ env.RELEASE_VERSION }}/ >${{ env.PROGRAM_NAME }}.json
- name: Display merged manifest
run: cat ${{ env.PROGRAM_NAME }}.json
- name: Archive Combined Manifest
uses: actions/upload-artifact@v4
with:
path: ${{ env.PROGRAM_NAME }}.json

- name: Gather all new release files
run: |
mkdir release-assets
find . -name "*.tar.gz" -exec cp {} release-assets/ \;
cp ${{ env.PROGRAM_NAME }}.json release-assets/
ls release-assets/
# Handle versioned release
- name: Create versioned release
if: startsWith(github.ref, 'refs/tags/v')
run: gh release create ${{ env.RELEASE_VERSION }} --title "${{ env.RELEASE_VERSION }}" --repo ${{ github.repository }} release-assets/*
env:
GH_TOKEN: ${{ github.token }}

# Handle canary release
- name: Delete canary release
if: github.ref == 'refs/heads/main'
run: gh release delete ${{ env.RELEASE_VERSION }} --repo ${{ github.repository }} --cleanup-tag || echo "Release not found, continuing..."
env:
GH_TOKEN: ${{ github.token }}
- name: Recreate canary release
if: github.ref == 'refs/heads/main'
run: gh release create ${{ env.RELEASE_VERSION }} --title "${{ env.RELEASE_VERSION }}" --prerelease --repo ${{ github.repository }} release-assets/*
env:
GH_TOKEN: ${{ github.token }}
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
blueprint
*.json
*.tar.gz
Empty file added LICENSE
Empty file.
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
.PHONY: test

test:
go test ./... -v
85 changes: 85 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
# Spin Blueprint Plugin

This is a plugin that helps to visualize the different components within a Spin application.

# Installation

## Install the latest version of the plugin

The latest stable release of the blueprint plugin can be installed like so:

```sh
spin plugins update
spin plugin install blueprint
```

## Install the canary version of the plugin

The canary release of the command trigger plugin represents the most recent commits on `main` and may not be stable, with some features still in progress.

```sh
spin plugins install --url https://github.com/fermyon/blueprint-plugin/releases/download/canary/blueprint.json
```

## Install from a local build

Alternatively, use the `spin pluginify` plugin to install from a fresh build. This will use the pluginify manifest (`spin-pluginify.toml`) to package the plugin and proceed to install it:

```sh
spin plugins install pluginify
go build -o blueprint main.go
spin pluginify --install
```

# Usage

This plugin will read a `spin.toml` file within the same directory--or whatever path specified in the `--file` flag--and output tables detailing the Spin application as a whole, as well as individual components.

## See all available commands and flags:

```sh
spin blueprint --help
```

## Show all components

If in your terminal you are in the same directory as a spin.toml file:

```sh
spin blueprint show
```

If your spin.toml file is somewhere else:

```sh

spin blueprint show --file path/to/spin.toml
```

## Show a specific component

If in your terminal you are in the same directory as a spin.toml file:

```sh
spin blueprint show component-name
```

If your spin.toml file is somewhere else:

```sh
spin blueprint show --file path/to/spin.toml component-name
```

## Loading environment variables

You can pass environment variables directly:

```sh
SPIN_VARIABLE_FOO=bar spin blueprint show --file path/to/spin.toml
```

Or read a `.env` file:

```sh
spin blueprint --env path/to/file.env show component-name
```
26 changes: 26 additions & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package cmd

import (
"os"

"github.com/spf13/cobra"
)

// rootCmd represents the base command when called without any subcommands
var rootCmd = &cobra.Command{
Use: "blueprint",
Short: "This is a plugin that helps to visualize the different components within a Spin application",
}

func Execute() {
err := rootCmd.Execute()
if err != nil {
os.Exit(1)
}
}

func init() {
showCmd.PersistentFlags().StringP("file", "f", "", "Specifies the path to the spin.toml file you wish to visualize")
showCmd.PersistentFlags().StringP("env", "e", "", "Specifies the path to the \".env\" file containing your Spin variables")
rootCmd.AddCommand(showCmd)
}
Loading

0 comments on commit 5a6f21b

Please sign in to comment.