Skip to content

Commit

Permalink
Add action to run a few Linux tools (#8)
Browse files Browse the repository at this point in the history
Co-authored-by: Pedro Rodrigues <[email protected]>
  • Loading branch information
hpedrorodrigues and hpedrorodrigues authored Sep 12, 2024
1 parent eaaa2d4 commit c3bb912
Show file tree
Hide file tree
Showing 10 changed files with 103 additions and 17 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
- [kustomize](./kustomize)
- [setup-sphynx](./setup-sphynx)
- [tf-check](./tf-check)
- [tools](./tools)

## Release

Expand Down
14 changes: 7 additions & 7 deletions envsubst/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Simple wrapper action for running [envsubst] over a file or set of files.
## Usage

```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
# One or more files to apply substitutions on (separated by space).
input: ''
Expand Down Expand Up @@ -35,7 +35,7 @@ Simple wrapper action for running [envsubst] over a file or set of files.
### Apply substitutions on a single file
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: template.yml
output: deployment.yml
Expand All @@ -44,7 +44,7 @@ Simple wrapper action for running [envsubst] over a file or set of files.
### Apply substitutions on multiple files
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: template.yml package.txt config.toml
output: result.yml output.txt result.toml
Expand All @@ -53,7 +53,7 @@ Simple wrapper action for running [envsubst] over a file or set of files.
### Apply substitutions in-place
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: deployment.yml
in_place: true
Expand All @@ -62,7 +62,7 @@ Simple wrapper action for running [envsubst] over a file or set of files.
### Apply substitutions with custom environment variables
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: template.yml
output: result.yml
Expand All @@ -74,15 +74,15 @@ Simple wrapper action for running [envsubst] over a file or set of files.
### Apply substitutions and print result to stdout
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: template.yml
```
### Apply substitutions restricting to specific environment variables
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
input: template.yml
format: '${CUSTOM_VAR} ${GITHUB_SHA}'
Expand Down
16 changes: 8 additions & 8 deletions kustomize/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ An action to validate kustomization files and outputs using [Kustomize].
## Usage

```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
# Strategy to use for detecting kustomization directories.
# Possible values
Expand Down Expand Up @@ -40,9 +40,9 @@ An action to validate kustomization files and outputs using [Kustomize].
### Validate all kustomization directories
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
# or
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: all
```
Expand All @@ -53,15 +53,15 @@ An action to validate kustomization files and outputs using [Kustomize].
- uses: actions/checkout@v4
with:
fetch-depth: 0 # This is required to allow this action to detect modified files.
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: modified
```
### Validate specific kustomization directories
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: static
path: kustomize/base kustomize/overlays/production
Expand All @@ -70,7 +70,7 @@ An action to validate kustomization files and outputs using [Kustomize].
### Validate kustomization directories with custom log level
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: all
log_level: verbose
Expand All @@ -79,7 +79,7 @@ An action to validate kustomization files and outputs using [Kustomize].
### Validate kustomization directories with custom flags
```yaml
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: all
flags: --load-restrictor=LoadRestrictionsNone --enable-alpha-plugins
Expand All @@ -92,7 +92,7 @@ An action to validate kustomization files and outputs using [Kustomize].
- uses: alexellis/arkade-get@master
with:
kustomize: latest
- uses: hpedrorodrigues/actions/[email protected].4
- uses: hpedrorodrigues/actions/[email protected].5
with:
auto_discovery: all
```
Expand Down
2 changes: 1 addition & 1 deletion setup-sphynx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ An action that sets up [Sphynx CLI].

```yaml
- name: Set up Sphynx
uses: hpedrorodrigues/actions/[email protected].4
uses: hpedrorodrigues/actions/[email protected].5
```
[Sphynx CLI]: https://github.com/hpedrorodrigues/sphynx
2 changes: 1 addition & 1 deletion tf-check/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Checks files recursively against a canonical format using [Terraform][terraform]

```yaml
- name: Lint
uses: hpedrorodrigues/actions/[email protected].4
uses: hpedrorodrigues/actions/[email protected].5
```
[terraform]: https://www.terraform.io
Expand Down
3 changes: 3 additions & 0 deletions tools/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FROM ghcr.io/hpedrorodrigues/tools
COPY entrypoint.sh /
ENTRYPOINT ["/entrypoint.sh"]
16 changes: 16 additions & 0 deletions tools/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# tools

Action that let you run a few Linux tools without the necessity to install them on the runner.

List of pre-installed tools is [here](https://github.com/hpedrorodrigues/images/blob/main/tools/tools.apko.yaml).

## Usage

```yaml
- name: Compress an example file
uses: hpedrorodrigues/actions/[email protected]
with:
script: |
FILE_NAME='example-file'
zip -r ${FILE_NAME}.zip .
```
13 changes: 13 additions & 0 deletions tools/action.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
name: tools
author: Pedro Rodrigues
description: Let you run a few pre-installed Linux tools without the necessity to install them on the runner.
inputs:
script:
description: Shell script to run inside the container.
required: true
branding:
icon: activity
color: gray-dark
runs:
using: docker
image: Dockerfile
38 changes: 38 additions & 0 deletions tools/entrypoint.bats
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#!/usr/bin/env bats

setup() {
export SINGLE_LINE_SCRIPT='echo "Hello!"'
export MULTILINE_SCRIPT='
echo "Hi!"
echo "Hello, world!"
'
}

main() {
sh "${BATS_TEST_DIRNAME}/entrypoint.sh"
}

@test 'Allow to run single line scripts' {
# GitHub-provided environment variables
export INPUT_SCRIPT="${SINGLE_LINE_SCRIPT}"

run main
[ "${status}" -eq 0 ]
[ "${lines[0]}" = 'Hello!' ]
}

@test 'Allow to run multiline scripts' {
# GitHub-provided environment variables
export INPUT_SCRIPT="${MULTILINE_SCRIPT}"

run main
[ "${status}" -eq 0 ]
[ "${lines[0]}" = 'Hi!' ]
[ "${lines[1]}" = 'Hello, world!' ]
}

@test 'Print error message when no script is provided' {
run main
[ "${status}" -eq 1 ]
[ "${lines[0]}" = 'No script provided!' ]
}
15 changes: 15 additions & 0 deletions tools/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#!/bin/bash

set -o errexit
set -o nounset

if ${VERBOSE:-false}; then
set -o xtrace
fi

if [ -z "${INPUT_SCRIPT:-}" ]; then
echo 'No script provided!' >&2
exit 1
fi

eval "${INPUT_SCRIPT}"

0 comments on commit c3bb912

Please sign in to comment.