Skip to content

Commit

Permalink
Add feature: OpenAPI Generator CLI (#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
lasuillard authored Sep 15, 2024
1 parent 63077f7 commit 09a1ecb
Show file tree
Hide file tree
Showing 19 changed files with 201 additions and 11 deletions.
7 changes: 4 additions & 3 deletions .devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@
"redhat.vscode-yaml",
"streetsidesoftware.code-spell-checker",
"editorconfig.editorconfig",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"timonwong.shellcheck",
"mkhl.shfmt"
]
}
},
Expand All @@ -27,6 +29,5 @@
},
"remoteUser": "node",
"onCreateCommand": "./.devcontainer/onCreateCommand.sh",
"postAttachCommand": "pre-commit install",
"updateContentCommand": "npm install -g @devcontainers/cli"
"postAttachCommand": "pre-commit install"
}
4 changes: 2 additions & 2 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,9 @@ jobs:
matrix:
features:
- aws-ssm-session-manager-plugin
- openapi-generator-cli
baseImage:
- debian:latest
- ubuntu:latest
- mcr.microsoft.com/devcontainers/base:ubuntu
steps:
- uses: actions/checkout@v4

Expand All @@ -48,6 +47,7 @@ jobs:
matrix:
features:
- aws-ssm-session-manager-plugin
- openapi-generator-cli
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
publish-features: "true"
base-path-to-features: "./src"
generate-docs: "true"

env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

Expand Down
5 changes: 5 additions & 0 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,8 @@ repos:
hooks:
- id: trailing-whitespace
- id: end-of-file-fixer

- repo: https://github.com/shellcheck-py/shellcheck-py
rev: v0.10.0.1
hooks:
- id: shellcheck
4 changes: 3 additions & 1 deletion .vscode/extensions.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
"redhat.vscode-yaml",
"streetsidesoftware.code-spell-checker",
"editorconfig.editorconfig",
"ms-azuretools.vscode-docker"
"ms-azuretools.vscode-docker",
"timonwong.shellcheck",
"mkhl.shfmt"
]
}
4 changes: 3 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
{
"cSpell.words": [
"lasuillard"
"devcontainers",
"lasuillard",
"openapi"
],
"editor.codeActionsOnSave": {
"source.fixAll": "explicit",
Expand Down
2 changes: 1 addition & 1 deletion .vscode/tasks.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@
"problemMatcher": []
}
]
}
}
54 changes: 54 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
#!/usr/bin/env -S make -f

MAKEFLAGS += --warn-undefined-variable
MAKEFLAGS += --no-builtin-rules
MAKEFLAGS += --silent

SHELL := bash
.ONESHELL:
.SHELLFLAGS := -eu -o pipefail -c
.DELETE_ON_ERROR:
.DEFAULT_GOAL := help

help: Makefile ## Show help
@grep -E '(^[a-zA-Z_-]+:.*?##.*$$)|(^##)' $(MAKEFILE_LIST) | awk 'BEGIN {FS = ":.*?## "}; {printf "\033[32m%-30s\033[0m %s\n", $$1, $$2}' | sed -e 's/\[32m##/[33m/'


# =============================================================================
# Common
# =============================================================================
install: ## Install deps
npm install -g @devcontainers/cli
pre-commit install --install-hooks
.PHONY: install

update: ## Update deps and tools
pre-commit autoupdate
.PHONY: update


# =============================================================================
# CI
# =============================================================================
ci: lint test ## Run CI tasks
.PHONY: ci

format: ## Run autoformatters

.PHONY: format

lint: ## Run all linters

.PHONY: lint

test: ## Run tests
devcontainer features test
.PHONY: test


# =============================================================================
# Handy Scripts
# =============================================================================
clean: ## Remove temporary files

.PHONY: clean
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
"id": "aws-ssm-session-manager-plugin",
"version": "0.1.0",
"description": "A feature to install AWS SSM Session Manager plugin."
}
}
7 changes: 7 additions & 0 deletions src/aws-ssm-session-manager-plugin/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ set -e

ARCH=$(uname -m)

echo "Preparing to download plugin for $ARCH"

case $ARCH in
x86_64)
download_url='https://s3.amazonaws.com/session-manager-downloads/plugin/latest/ubuntu_64bit/session-manager-plugin.deb'
Expand All @@ -20,8 +22,13 @@ case $ARCH in
;;
esac

echo "Downloading plugin from $download_url"

apt-get update && apt-get install -y curl

curl -sL "$download_url" -o /tmp/session-manager-plugin.deb

echo "Installing plugin"

dpkg -i /tmp/session-manager-plugin.deb
rm /tmp/session-manager-plugin.deb
26 changes: 26 additions & 0 deletions src/openapi-generator-cli/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@

# My Favorite Color (color)

A feature to remind you of your favorite color

## Example Usage

```json
"features": {
"ghcr.io/devcontainers/feature-starter/color:1": {
"version": "latest"
}
}
```

## Options

| Options Id | Description | Type | Default Value |
|-----|-----|-----|-----|
| favorite | Choose your favorite color. | string | red |



---

_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/devcontainers/feature-starter/blob/main/src/color/devcontainer-feature.json). Add additional notes to a `NOTES.md`._
16 changes: 16 additions & 0 deletions src/openapi-generator-cli/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"name": "OpenAPI Generator CLI",
"id": "openapi-generator-cli",
"version": "0.1.0",
"description": "A feature to install OpenAPI Generator CLI. Java is required but not included in this feature.",
"options": {
"version": {
"type": "string",
"default": "latest",
"description": "The version of OpenAPI Generator CLI to install."
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/java"
]
}
28 changes: 28 additions & 0 deletions src/openapi-generator-cli/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#!/bin/sh

set -e

apt-get update && apt-get install -y curl

if [ "$VERSION" = 'latest' ]; then
echo "Resolving latest version of OpenAPI Generator CLI"
VERSION=$(
curl https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/maven-metadata.xml \
| grep -Eo '<latest>(.+)</latest>' \
| sed -E 's/<latest>(.+)<\/latest>/\1/'
)
fi

echo "Installing OpenAPI Generator CLI with version ${VERSION}"

curl -o /usr/local/lib/openapi-generator-cli.jar \
"https://repo1.maven.org/maven2/org/openapitools/openapi-generator-cli/${VERSION}/openapi-generator-cli-${VERSION}.jar"

echo "Creating wrapper script for OpenAPI Generator CLI"

cat <<EOF > /usr/local/bin/openapi-generator-cli
#!/bin/sh
java -jar /usr/local/lib/openapi-generator-cli.jar "\$@"
EOF
chmod +x /usr/local/bin/openapi-generator-cli
2 changes: 1 addition & 1 deletion test/_global/scenarios.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{}
{}
1 change: 1 addition & 0 deletions test/aws-ssm-session-manager-plugin/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

set -e

# shellcheck source=/dev/null
source dev-container-features-test-lib

check "verify session manager plugin installation" session-manager-plugin --version | grep -Eo '[0-9\.]+'
Expand Down
10 changes: 10 additions & 0 deletions test/openapi-generator-cli/latest.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

# shellcheck source=/dev/null
source dev-container-features-test-lib

check "verify OpenAPI Generator CLI installation" openapi-generator-cli --version | grep -Eo '^openapi-generator-cli .+$'

reportResults
18 changes: 18 additions & 0 deletions test/openapi-generator-cli/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"latest": {
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
"features": {
"ghcr.io/devcontainers/features/java:1": {},
"openapi-generator-cli": {}
}
},
"specific-version": {
"image": "mcr.microsoft.com/devcontainers/base:bookworm",
"features": {
"ghcr.io/devcontainers/features/java:1": {},
"openapi-generator-cli": {
"version": "7.8.0"
}
}
}
}
10 changes: 10 additions & 0 deletions test/openapi-generator-cli/specific-version.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

# shellcheck source=/dev/null
source dev-container-features-test-lib

check "verify OpenAPI Generator CLI installation" openapi-generator-cli --version | grep -Eo '^openapi-generator-cli 7\.8\.0$'

reportResults
10 changes: 10 additions & 0 deletions test/openapi-generator-cli/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#!/bin/bash

set -e

# shellcheck source=/dev/null
source dev-container-features-test-lib

check "can be installed even java not installed" openapi-generator-cli --version 2>&1 | grep 'java: not found'

reportResults

0 comments on commit 09a1ecb

Please sign in to comment.