Skip to content

Commit 3342f6e

Browse files
committed
feat: CI (GitHub Actions)
1 parent 131ef5f commit 3342f6e

File tree

8 files changed

+156
-0
lines changed

8 files changed

+156
-0
lines changed

.devcontainer/Dockerfile

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# =============================================================================
2+
# Docker Container for LinuxBrew Download and Basic Execution Test
3+
# =============================================================================
4+
# [Choice] https://hub.docker.com/r/homebrew/brew/tags
5+
ARG VARIANT="latest"
6+
7+
# -----------------------------------------------------------------------------
8+
# Main Stage
9+
# -----------------------------------------------------------------------------
10+
FROM homebrew/brew:${VARIANT}
11+
12+
RUN \
13+
brew install shellspec/shellspec/shellspec && \
14+
# Smoke test
15+
shellspec -v

.devcontainer/devcontainer.json

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
2+
// https://github.com/microsoft/vscode-dev-containers/tree/v0.209.6/containers/alpine
3+
{
4+
"name": "homebrew",
5+
"build": {
6+
"dockerfile": "Dockerfile",
7+
// Available 'VARIANT': https://hub.docker.com/r/homebrew/brew/tags
8+
"args": { "VARIANT": "latest" }
9+
},
10+
11+
// Set *default* container specific settings.json values on container create.
12+
"settings": {},
13+
14+
// Add the IDs of extensions you want installed when the container is created.
15+
// Note that some extensions may not work in Alpine Linux. See https://aka.ms/vscode-remote/linux.
16+
"extensions": [],
17+
18+
// Use 'forwardPorts' to make a list of ports inside the container available locally.
19+
// "forwardPorts": [],
20+
21+
// Use 'postCreateCommand' to run commands after the container is created.
22+
// "postCreateCommand": "uname -a",
23+
24+
// Replace when using a ptrace-based debugger like C++, Go, and Rust
25+
// "runArgs": [ "--init", "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ],
26+
27+
// Comment out connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
28+
//"remoteUser": "vscode"
29+
}

.github/workflows/go-pallet.yml

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
name: "go-pallet"
2+
3+
on:
4+
workflow_dispatch:
5+
push:
6+
schedule:
7+
# Runs at 16:30 UTC on day-of-month 2 (Every day-of-month 2 at AM 01:30 JST, my time)
8+
# See: https://crontab.guru/
9+
- cron: '30 16 2 * *'
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- uses: actions/checkout@v2
16+
- name: Run tests on container
17+
run: docker-compose run go-pallet

Tests/.shellspec

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--require spec_helper
2+
3+
## Default kcov (coverage) options
4+
# --kcov-options "--include-path=. --path-strip-level=1"
5+
# --kcov-options "--include-pattern=.sh"
6+
# --kcov-options "--exclude-pattern=/.shellspec,/spec/,/coverage/,/report/"
7+
8+
## Example: Include script "myprog" with no extension
9+
# --kcov-options "--include-pattern=.sh,myprog"
10+
11+
## Example: Only specified files/directories
12+
# --kcov-options "--include-pattern=myprog,/lib/"

Tests/README.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# Tests To Download via Homebrew on Linux
2+
3+
This directory contains simple [ShellSpec](https://github.com/shellspec/shellspec) tests.
4+
For example, download and run its basic commands.
5+
See [go-pallet_spec.sh](./spec/go-pallet_spec.sh) for example.
6+
7+
## Note
8+
9+
- Create Test Files
10+
- Place them under `./spec/` dir.
11+
- File name format: `<app_name>_spec.sh`
12+
- Ex.) `go-pallet_spec.sh`
13+
- Add test runner to [docker-compose.yml](../docker-compose.yml)
14+
- Add the workflow to [workflows](../.github/workflows)
15+
- Add the status workflow status badge to [README.md](../README.md) as well.
16+
17+
## Reference
18+
19+
- [Examples to write tests](https://github.com/shellspec/shellspec/tree/master/examples/spec) @ github.com/shellspec/shellspec
20+
- [Syntax References](https://github.com/shellspec/shellspec/blob/master/docs/references.md) @ github.com/shellspec/shellspec

Tests/spec/go-pallet_spec.sh

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
#shellcheck shell=sh
2+
3+
Describe 'go-pallet'
4+
# Download Test
5+
It 'should success on install via brew'
6+
When call brew install KEINOS/apps/go-pallet
7+
The status should be success
8+
The stderr should include "Tapping keinos/apps"
9+
The output should include "🍺 /home/linuxbrew/.linuxbrew/Cellar/go-pallet"
10+
End
11+
12+
# Smoke Test
13+
It 'should success and contain "pallet" in the output on version print'
14+
When run pallet -v
15+
The status should be success
16+
The output should match pattern "pallet *"
17+
End
18+
End

Tests/spec/spec_helper.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# shellcheck shell=sh
2+
3+
# Defining variables and functions here will affect all specfiles.
4+
# Change shell options inside a function may cause different behavior,
5+
# so it is better to set them here.
6+
# set -eu
7+
8+
# This callback function will be invoked only once before loading specfiles.
9+
spec_helper_precheck() {
10+
# Available functions: info, warn, error, abort, setenv, unsetenv
11+
# Available variables: VERSION, SHELL_TYPE, SHELL_VERSION
12+
: minimum_version "0.28.1"
13+
}
14+
15+
# This callback function will be invoked after a specfile has been loaded.
16+
spec_helper_loaded() {
17+
:
18+
}
19+
20+
# This callback function will be invoked after core modules has been loaded.
21+
spec_helper_configure() {
22+
# Available functions: import, before_each, after_each, before_all, after_all
23+
: import 'support/custom_matcher'
24+
}

docker-compose.yml

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
# =============================================================================
2+
# LinuxBrew Download & Basic Functionality Test on Docker Container
3+
# =============================================================================
4+
# - Requirements: docker
5+
# - How to test:
6+
# - All-in-one
7+
# docker-compose up
8+
# - à-la-carte
9+
# docker-compose run go-pallet
10+
version: "3.9"
11+
services:
12+
go-pallet:
13+
build:
14+
context: ./.devcontainer
15+
dockerfile: ./Dockerfile
16+
args:
17+
VARIANT: latest
18+
volumes:
19+
- ./Tests:/workspaces/Tests
20+
working_dir: /workspaces/Tests
21+
entrypoint: shellspec ./spec/go-pallet_spec.sh

0 commit comments

Comments
 (0)