Skip to content

Add actionlint #12

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .czrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"path": "cz-conventional-changelog"
}
1 change: 1 addition & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
"mizu",
"oras",
"stern",
"actionlint",
]
baseImage:
[
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
11 changes: 11 additions & 0 deletions src/actionlint/NOTES.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
## Reference

actionlint: https://github.com/rhysd/actionlint

## Changelog

### 1.0.0

#### Added

- Initial release
37 changes: 37 additions & 0 deletions src/actionlint/README.md
Original file line number Diff line number Diff line change
@@ -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`._
20 changes: 20 additions & 0 deletions src/actionlint/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -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"
]
}
95 changes: 95 additions & 0 deletions src/actionlint/install.sh
Original file line number Diff line number Diff line change
@@ -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!"
1 change: 1 addition & 0 deletions test/_global/all.sh
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
1 change: 1 addition & 0 deletions test/_global/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
"mizu": {},
"oras": {},
"stern": {},
"actionlint": {},
}
}
}
19 changes: 19 additions & 0 deletions test/actionlint/test.sh
Original file line number Diff line number Diff line change
@@ -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