From cb0062e01ad8455c20e1fa8437cb7db52b925093 Mon Sep 17 00:00:00 2001 From: Eric Ho Date: Sat, 12 Nov 2022 11:21:08 +0800 Subject: [PATCH 1/4] feat: add actionlint --- .github/workflows/test.yaml | 1 + README.md | 1 + src/actionlint/NOTES.md | 11 +++ src/actionlint/devcontainer-feature.json | 20 +++++ src/actionlint/install.sh | 95 ++++++++++++++++++++++++ test/_global/all.sh | 1 + test/_global/scenarios.json | 1 + test/actionlint/test.sh | 19 +++++ 8 files changed, 149 insertions(+) create mode 100644 src/actionlint/NOTES.md create mode 100644 src/actionlint/devcontainer-feature.json create mode 100644 src/actionlint/install.sh create mode 100644 test/actionlint/test.sh diff --git a/.github/workflows/test.yaml b/.github/workflows/test.yaml index 7d6bf56..7317526 100644 --- a/.github/workflows/test.yaml +++ b/.github/workflows/test.yaml @@ -29,6 +29,7 @@ jobs: "mizu", "oras", "stern", + "actionlint", ] baseImage: [ diff --git a/README.md b/README.md index 0704c43..4d7abc8 100644 --- a/README.md +++ b/README.md @@ -19,6 +19,7 @@ This repository contains following features: - [mizu](./src/mizu/README.md): Install mizu - [oras](./src/oras/README.md): Install oras - [stern](./src/stern/README.md): Install stern +- [actionlint](./src/actionlint/README.md): Install actionlint ## Usage diff --git a/src/actionlint/NOTES.md b/src/actionlint/NOTES.md new file mode 100644 index 0000000..06be3b9 --- /dev/null +++ b/src/actionlint/NOTES.md @@ -0,0 +1,11 @@ +## Reference + +actionlint: https://github.com/rhysd/actionlint + +## Changelog + +### 1.0.0 + +#### Added + +- Initial release diff --git a/src/actionlint/devcontainer-feature.json b/src/actionlint/devcontainer-feature.json new file mode 100644 index 0000000..3334296 --- /dev/null +++ b/src/actionlint/devcontainer-feature.json @@ -0,0 +1,20 @@ +{ + "name": "actionlint", + "id": "actionlint", + "version": "1.0.0", + "description": "Install [actionlint](https://rhysd.github.io/actionlint/) - Static checker for GitHub Actions workflow files", + "documentationURL": "https://github.com/dhoeric/features/tree/main/src/actionlint", + "options": { + "version": { + "type": "string", + "proposal": [ + "latest" + ], + "default": "latest", + "description": "Select or enter actionlint version" + } + }, + "installsAfter": [ + "ghcr.io/devcontainers/features/common-utils" + ] +} diff --git a/src/actionlint/install.sh b/src/actionlint/install.sh new file mode 100644 index 0000000..67ec123 --- /dev/null +++ b/src/actionlint/install.sh @@ -0,0 +1,95 @@ +#!/usr/bin/env bash + +set -e + +# Clean up +rm -rf /var/lib/apt/lists/* + +FEATURE_VERSION=${VERSION:-"latest"} + +if [ "$(id -u)" -ne 0 ]; then + echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.' + exit 1 +fi + +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 + apt_get_update + fi + apt-get -y install --no-install-recommends "$@" + fi +} + +export DEBIAN_FRONTEND=noninteractive + +# Figure out correct version of a three part version number is not passed +find_version_from_git_tags() { + local variable_name=$1 + local requested_version=${!variable_name} + if [ "${requested_version}" = "none" ]; then return; fi + local repository=$2 + local prefix=${3:-"tags/v"} + local separator=${4:-"."} + local last_part_optional=${5:-"false"} + if [ "$(echo "${requested_version}" | grep -o "." | wc -l)" != "2" ]; then + local escaped_separator=${separator//./\\.} + local last_part + if [ "${last_part_optional}" = "true" ]; then + last_part="(${escaped_separator}[0-9]+)?" + else + last_part="${escaped_separator}[0-9]+" + fi + local regex="${prefix}\\K[0-9]+${escaped_separator}[0-9]+${last_part}$" + local version_list="$(git ls-remote --tags ${repository} | grep -oP "${regex}" | tr -d ' ' | tr "${separator}" "." | sort -rV)" + if [ "${requested_version}" = "latest" ] || [ "${requested_version}" = "current" ] || [ "${requested_version}" = "lts" ]; then + declare -g ${variable_name}="$(echo "${version_list}" | head -n 1)" + else + set +e + declare -g ${variable_name}="$(echo "${version_list}" | grep -E -m 1 "^${requested_version//./\\.}([\\.\\s]|$)")" + set -e + fi + fi + if [ -z "${!variable_name}" ] || ! echo "${version_list}" | grep "^${!variable_name//./\\.}$" > /dev/null 2>&1; then + echo -e "Invalid ${variable_name} value: ${requested_version}\nValid values:\n${version_list}" >&2 + exit 1 + fi + echo "${variable_name}=${!variable_name}" +} + +# Install dependencies +check_packages curl git tar + +architecture="$(uname -m)" +case $architecture in + x86_64) architecture="amd64";; + aarch64 | armv8* | arm64) architecture="arm64";; + *) echo "(!) Architecture $architecture unsupported"; exit 1 ;; +esac + +# Use a temporary locaiton for actionlint archive +export TMP_DIR="/tmp/tmp-actionlint" +mkdir -p ${TMP_DIR} +chmod 700 ${TMP_DIR} + +# Install actionlint +echo "(*) Installing actionlint..." +find_version_from_git_tags FEATURE_VERSION https://github.com/rhysd/actionlint + +FEATURE_VERSION="${FEATURE_VERSION#"v"}" +curl -sSL --fail -o ${TMP_DIR}/actionlint.tar.gz "https://github.com/rhysd/actionlint/releases/download/v${FEATURE_VERSION}/actionlint_${FEATURE_VERSION}_linux_${architecture}.tar.gz" +tar -xzf "${TMP_DIR}/actionlint.tar.gz" -C "${TMP_DIR}" actionlint +mv ${TMP_DIR}/actionlint /usr/local/bin/actionlint +chmod 0755 /usr/local/bin/actionlint + +# Clean up +rm -rf /var/lib/apt/lists/* + +echo "Done!" diff --git a/test/_global/all.sh b/test/_global/all.sh index c5d04ea..2073b31 100644 --- a/test/_global/all.sh +++ b/test/_global/all.sh @@ -34,6 +34,7 @@ check "hadolint version" hadolint --version check "mizu version" mizu version check "oras version" oras version check "stern version" stern --version +check "actionlint version" actionlint --version # Report result # If any of the checks above exited with a non-zero exit code, the test will fail. diff --git a/test/_global/scenarios.json b/test/_global/scenarios.json index 5ddf468..d01edeb 100644 --- a/test/_global/scenarios.json +++ b/test/_global/scenarios.json @@ -18,6 +18,7 @@ "mizu": {}, "oras": {}, "stern": {}, + "actionlint": {}, } } } diff --git a/test/actionlint/test.sh b/test/actionlint/test.sh new file mode 100644 index 0000000..c47cc63 --- /dev/null +++ b/test/actionlint/test.sh @@ -0,0 +1,19 @@ +#!/usr/bin/env bash + +# This test can be run with the following command (from the root of this repo) +# devcontainer features test \ +# --features actionlint \ +# --base-image mcr.microsoft.com/devcontainers/base:ubuntu . + +set -e + +# Optional: Import test library bundled with the devcontainer CLI +source dev-container-features-test-lib + +# Feature-specific tests +# The 'check' command comes from the dev-container-features-test-lib. +check "actionlint version" actionlint --version + +# Report result +# If any of the checks above exited with a non-zero exit code, the test will fail. +reportResults From ec1061ee36bdbbd83d114c3ea97c323b7371c77f Mon Sep 17 00:00:00 2001 From: Eric Ho Date: Sat, 12 Nov 2022 11:23:12 +0800 Subject: [PATCH 2/4] docs: add commitizen config --- .czrc | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 .czrc diff --git a/.czrc b/.czrc new file mode 100644 index 0000000..d1bcc20 --- /dev/null +++ b/.czrc @@ -0,0 +1,3 @@ +{ + "path": "cz-conventional-changelog" +} From c68445bf4154048f802346faef7fc230bc5aebf5 Mon Sep 17 00:00:00 2001 From: github-actions Date: Sat, 12 Nov 2022 04:28:22 +0000 Subject: [PATCH 3/4] Automated documentation update [skip ci] --- src/actionlint/README.md | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 src/actionlint/README.md diff --git a/src/actionlint/README.md b/src/actionlint/README.md new file mode 100644 index 0000000..cdd4422 --- /dev/null +++ b/src/actionlint/README.md @@ -0,0 +1,37 @@ + +# actionlint (actionlint) + +Install [actionlint](https://rhysd.github.io/actionlint/) - Static checker for GitHub Actions workflow files + +## Example Usage + +```json +"features": { + "ghcr.io/dhoeric/features/actionlint:1": { + "version": "latest" + } +} +``` + +## Options + +| Options Id | Description | Type | Default Value | +|-----|-----|-----|-----| +| version | Select or enter actionlint version | string | latest | + +## Reference + +actionlint: https://github.com/rhysd/actionlint + +## Changelog + +### 1.0.0 + +#### Added + +- Initial release + + +--- + +_Note: This file was auto-generated from the [devcontainer-feature.json](https://github.com/dhoeric/features/blob/main/src/actionlint/devcontainer-feature.json). Add additional notes to a `NOTES.md`._ From 2962741492170a3aa33881e94a346fb38f31e092 Mon Sep 17 00:00:00 2001 From: Eric Ho Date: Sat, 12 Nov 2022 12:35:33 +0800 Subject: [PATCH 4/4] chore: empty commit