Skip to content

Commit

Permalink
feat: Add clasp feature
Browse files Browse the repository at this point in the history
  • Loading branch information
hankei6km committed May 2, 2024
1 parent b1a192c commit 5fa7cd8
Show file tree
Hide file tree
Showing 11 changed files with 197 additions and 0 deletions.
6 changes: 6 additions & 0 deletions .github/labeler.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@
- any-glob-to-any-file:
- "src/semver-tool/**"
- "test/semver-tool/**"
"scope: clasp":
- all:
- changed-files:
- any-glob-to-any-file:
- "src/clasp/**"
- "test/clasp/**"
1 change: 1 addition & 0 deletions .github/workflows/lint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
features:
- prepare-commit-msg-context
- semver-tool
- google-clasp
steps:
- uses: actions/checkout@v4

Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ jobs:
features:
- prepare-commit-msg-context
- semver-tool
# - google-clasp
baseImage:
- debian:latest
- ubuntu:latest
Expand All @@ -36,6 +37,7 @@ jobs:
features:
- prepare-commit-msg-context
- semver-tool
- google-clasp
steps:
- uses: actions/checkout@v4

Expand Down
1 change: 1 addition & 0 deletions scripts/init-labels.sh
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ LABELS_TEXT_COLOR_DESCRIPTIOM=(
"sem-pr: breaking change,#e99695,This change may affect existing functionality or APIs"
"scope: prepare-commit-msg-context,#C2E0C6,prepare-commit-msg-context-related changes"
"scope: semver-tool,#FEF2C0,semver-tool changes"
"scope: clasp,#63559F,clasp changes"
)

for label_color_description in "${LABELS_TEXT_COLOR_DESCRIPTIOM[@]}"; do
Expand Down
24 changes: 24 additions & 0 deletions src/google-clasp/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"name": "@google/clasp (via npm)",
"id": "google-clasp",
"version": "1.0.0",
"description": "Install the @google/clasp with @types/google-apps-script package via NPM registry",
"options": {
"version": {
"type": "string",
"proposals": ["latest"],
"default": "latest",
"description": "Select or enter a @google/clasp version."
},
"types": {
"type": "string",
"proposals": ["latest"],
"default": "latest",
"description": "Select or enter a @types/google-apps-script version(pass blank to not install)."
}
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils",
"ghcr.io/devcontainers/features/node"
]
}
40 changes: 40 additions & 0 deletions src/google-clasp/install.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
#!/usr/bin/env bash

TARGET_PACKAGE="@google/clasp"
TARGET_VERSION=${VERSION:-"latest"}
TARGET_TYPES_PACKAGE="@types/google-apps-script"
TARGET_TYPES_VERSION=${TYPES:-"latest"}

set -e


# https://github.com/Balazs23/devcontainers-features/blob/main/src/nx/install.sh
command_exists() {
command -v "$@" > /dev/null 2>&1
}
install_packages() {
# Use a custom cache since it is unclear how the cache is handled in the feature.
# (whether it should be deleted or kept)
local TEMP_CACHE
TEMP_CACHE=$(mktemp -d)
trap 'rm -rf "${TEMP_CACHE}"' EXIT

echo "Installing npm package: ${TARGET_PACKAGE}@${TARGET_VERSION}"
npm install --global --omit=dev --no-progress --cache "${TEMP_CACHE}" "${TARGET_PACKAGE}@${TARGET_VERSION}"
if test "${TARGET_TYPES_PACKAGE}" != ""; then
echo "Installing npm package: ${TARGET_TYPES_PACKAGE}@${TARGET_TYPES_VERSION}"
npm install --global --omit=dev --no-progress --cache "${TEMP_CACHE}" "${TARGET_TYPES_PACKAGE}@${TARGET_TYPES_VERSION}"
fi
}

# Check if npm is installed
if ! command_exists npm; then
echo -e 'Feature requires npm to be installed. Please use a node-based image like:'
# shellcheck disable=SC2016
echo -e ' - mcr.microsoft.com/vscode/devcontainers/typescript-node:${VARIANT}'
echo -e 'You can also add as feature like:'
echo -e ' - "ghcr.io/devcontainers/features/node:1": {}'
fi

# Instal pacakges
install_packages
50 changes: 50 additions & 0 deletions test/google-clasp/scenarios.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
{
"v2.4.0": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false,
"username": "node"
},
"ghcr.io/devcontainers/features/node:1": {},
"google-clasp": {
"version": "2.4.0"
}
},
"remoteUser": "node"
},
"types_v1.0.0": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false,
"username": "node"
},
"ghcr.io/devcontainers/features/node:1": {},
"google-clasp": {
"types": "1.0.0"
}
},
"remoteUser": "node"
},
"types_none": {
"image": "mcr.microsoft.com/devcontainers/base:ubuntu",
"features": {
"ghcr.io/devcontainers/features/common-utils:1": {
"installZsh": false,
"installOhMyZsh": false,
"upgradePackages": false,
"username": "node"
},
"ghcr.io/devcontainers/features/node:1": {},
"google-clasp": {
"types": ""
}
},
"remoteUser": "node"
}
}
21 changes: 21 additions & 0 deletions test/google-clasp/test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/bin/bash

set -e

# -i で npm が使えるイメージを指定する必要がある。
# test-autogenerated ジョブでは matrix から外す。

# Optional: Import test library bundled with the devcontainer CLI
# Provides the 'check' and 'reportResults' commands.
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.

check "Check @google/clasp is installed" clasp --version
check "Check types(@types/google-apps-script) is installed" npm list --global --depth 0 | grep -q "@types/google-apps-script@"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
17 changes: 17 additions & 0 deletions test/google-clasp/types_none.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# Provides the 'check' and 'reportResults' commands.
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.
check "Check @google/clasp is installed" clasp --version
check "Check types(@types/google-apps-script) is not installed" npm list --global --depth 0 | grep -v -q "@types/google-apps-script@"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
17 changes: 17 additions & 0 deletions test/google-clasp/types_v1.0.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# Provides the 'check' and 'reportResults' commands.
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.
check "Check @google/clasp is installed" clasp --version
check "Check types(@types/google-apps-script) is installed" npm list --global --depth 0 | grep -q "@types/google-apps-script@1.0.0"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults
18 changes: 18 additions & 0 deletions test/google-clasp/v2.4.0.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash

set -e

# Optional: Import test library bundled with the devcontainer CLI
# Provides the 'check' and 'reportResults' commands.
# shellcheck source=/dev/null
source dev-container-features-test-lib

# Feature-specific tests
# The 'check' command comes from the dev-container-features-test-lib.
# clasp 2.4.0 は動作しないので、パッケージの存在確認のみ行う。
check "Check @google/clasp@2.4.0 is installed" npm list --global --depth 0 | grep -q "@google/clasp@2.4.0"
check "Check types(@types/google-apps-script) is installed" npm list --global --depth 0 | grep -q "@types/google-apps-script@"

# Report result
# If any of the checks above exited with a non-zero exit code, the test will fail.
reportResults

0 comments on commit 5fa7cd8

Please sign in to comment.