-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Speed up workflow testing by getting away from Docker (PR #21)
## Feature * feat: requirement checker for merge testing * feat: use `golangci-lint` v1.36.0 -> latest * feat: coverage action w/out docker * feat: merge-tests.yaml w/out docker * feat: use pre-installed shellcheck * feat: ".shellceckrc" - For older version compatibility. (CI uses old version) ## Fixes * fix: shell check errors * fix: golangci-lint.yaml as dispatch workflow only - Since merge-tests.yaml does the same thing limit it to `workflow_dispatch` as an individual test
- Loading branch information
Showing
11 changed files
with
251 additions
and
59 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,26 @@ | ||
<!-- markdownlint-disable MD033 --> | ||
# Dockerfile for CIs and Development | ||
# Dockerfile for GitHub and VSCode Users To Develop | ||
|
||
## For CIs | ||
This directory is for [GitHub Codespaces](https://github.com/features/codespaces) and/or [VS Code + Docker](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) users for development. | ||
|
||
The [CI](https://en.wikipedia.org/wiki/Continuous_integration) will run the [Dockerfile](Dockerfile) to build the image and then run the tests in a container. | ||
It includes most of the necessary packages and tools for developing Golang app. Aiming to provide the same environment to develop the app. | ||
|
||
- Current CI | ||
- [GitHub Actions](https://docs.github.com/en/free-pro-team@latest/actions): [../.github/workflows/](https://github.com/KEINOS/Hello-Cobra/tree/main/.github/workflows) | ||
## Developing Online | ||
|
||
## For DEVs | ||
If GitHub detects this directory (`.devcontainer`) in the repo, then you will be able to develop online via [GitHub Codespaces](https://github.com/features/codespaces). | ||
|
||
This directory is for [GitHub Codespaces](https://github.com/features/codespaces) and [VS Code + Docker](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) users to develop the cloned/forked repo. | ||
## VS Code + Docker User | ||
|
||
### VS Code + Docker User | ||
The container contains VS Code Server as well. If you already have installed the "[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)" extension, then press "<kbd>F1</kbd>" and select "`Remote-Containers: Open in Container`". | ||
|
||
If you already have installed the "[Remote - Containers](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers)" extension, press "<kbd>F1</kbd>" and select "`Remote-Containers: Open in Container`". After a while, you'll get most of the environment needed to develop and debug. | ||
After a while, you'll get most of the environment needed to develop and debug. | ||
|
||
- File Description | ||
- [cobra.yaml](cobra.yaml): Default `cobra` command Settings. | ||
- [devcontainer.json](devcontainer.json): VSCode Extensions to be installed. | ||
- [Dockerfile](Dockerfile): Alpine based Golang development container. | ||
- [postCreateCommand.sh](postCreateCommand.sh): Initialization script that runs after the container and the VSCode server is up and before connection from VSCode. | ||
- [settings.vscode.json](settings.vscode.json): Additional VSCode Settings. | ||
- [welcome.sh](welcome.sh): Bash script to display the welcome message in the terminal when first login. It will display the basic info and TIPs to use. | ||
## File Description | ||
|
||
- [cobra.yaml](cobra.yaml): Default `cobra` command Settings. Used for `$ cobra add ..` | ||
- [devcontainer.env](devcontainer.env): ENV variables to be loaded once when the container's created. | ||
- [devcontainer.json](devcontainer.json): VSCode Extensions to be installed and env settings. | ||
- [Dockerfile](Dockerfile): Debian 10 (buster) based Golang development container. | ||
- [postCreateCommand.sh](postCreateCommand.sh): Initialization script that runs after the container and the VSCode server is up. | ||
- [README.md](README.md): This file. ;-) | ||
- [welcome.sh](welcome.sh): Bash script to display the basic info and TIPs to use in the first shell login. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
#!/bin/sh | ||
# ============================================================================= | ||
# This script checks if the commands and packages required for merge testing | ||
# are installed. | ||
# ============================================================================= | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Constants | ||
# ----------------------------------------------------------------------------- | ||
SUCCESS=0 | ||
FAILURE=1 | ||
TRUE=0 | ||
FALSE=1 | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Functions | ||
# ----------------------------------------------------------------------------- | ||
isAvailable() { | ||
command_tmp="${1:?Command name missing}" | ||
msg_error="${2:?Error message missing}" | ||
url_reference="${3:?'URL for reference missing'}" | ||
|
||
printf -- ' %s ... ' "$command_tmp" | ||
if ! which "$command_tmp" 1>/dev/null 2>/dev/null; then | ||
flag_covered_all=$FALSE | ||
echo 'NG' | ||
echo >&2 " - ABOUT : ${msg_error}" | ||
echo >&2 " - DETAILS: ${url_reference}" | ||
return $FALSE | ||
fi | ||
echo 'OK' | ||
} | ||
|
||
# ----------------------------------------------------------------------------- | ||
# Main | ||
# ----------------------------------------------------------------------------- | ||
flag_covered_all=$TRUE | ||
|
||
echo 'Checking requirements for:' | ||
|
||
echo | ||
echo 'Shell scripts:' | ||
isAvailable \ | ||
shellcheck \ | ||
'"shellcheck" is a static analysis tool for shell scripts.' \ | ||
'https://github.com/koalaman/shellcheck' | ||
|
||
isAvailable shfmt \ | ||
'"shfmt" is a linter for shell scripts to support POSIX Shell, Bash, and mksh.' \ | ||
'https://github.com/mvdan/sh' | ||
|
||
echo | ||
echo 'Go programs:' | ||
isAvailable \ | ||
go \ | ||
'"go" is required as a matter of course.' \ | ||
'https://golang.org/' | ||
|
||
isAvailable \ | ||
gofmt \ | ||
'"gofmt" is a formatter for golang.' \ | ||
'https://golang.org/cmd/gofmt/' | ||
|
||
isAvailable \ | ||
golangci-lint \ | ||
'"golangci-lint" is is a Go linters aggregator.' \ | ||
'https://golangci-lint.run/' | ||
|
||
if [ $flag_covered_all -ne 0 ]; then | ||
echo | ||
echo >&2 "Some requirements missing." | ||
exit $FAILURE | ||
fi | ||
|
||
echo | ||
echo 'OK - All requirements were installed! You are good to Go testing!' | ||
exit $SUCCESS |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,6 @@ name: golangci-lint | |
|
||
on: | ||
workflow_dispatch: | ||
pull_request: | ||
|
||
jobs: | ||
golangci: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,21 +5,53 @@ on: | |
pull_request: | ||
|
||
jobs: | ||
docker_test: | ||
merge_tests: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- name: Checkout the code | ||
uses: actions/checkout@v2 | ||
- name: Build the test image | ||
|
||
- uses: actions/setup-go@v2 | ||
with: | ||
go-version: 1.15.x | ||
|
||
- name: Use Cache | ||
uses: actions/cache@v2 | ||
with: | ||
path: ~/go/pkg/mod | ||
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }} | ||
restore-keys: | | ||
${{ runner.os }}-go- | ||
- name: Download Modules | ||
if: steps.cache.outputs.cache-hit != 'true' | ||
run: go mod download | ||
|
||
- name: Run shellcheck (pre-installed) | ||
run: | | ||
pwd && \ | ||
cd ./.devcontainer && \ | ||
docker build -t test:ci . | ||
- name: Run full-tests on the container | ||
find . -name '*.sh' -type f -print0 | xargs -0 shellcheck | ||
- name: Install and run shfmt | ||
run: | | ||
GO111MODULE=on go get mvdan.cc/sh/v3/cmd/shfmt | ||
find . -name '*.sh' -type f -print0 | xargs -0 shfmt -d | ||
- name: Run gofmt | ||
uses: Jerome1337/[email protected] | ||
with: | ||
gofmt-path: '.' | ||
gofmt-flags: '-d -e' # display diffs and report all errors | ||
|
||
- name: Run golangci-lint | ||
uses: golangci/golangci-lint-action@v2 | ||
with: | ||
version: v1.36 | ||
args: --config ./.github/golangci.yml | ||
# use pre-installed Go | ||
skip-go-installation: true | ||
|
||
- name: Run requirement check | ||
run: | | ||
pwd && \ | ||
docker run \ | ||
-v $(pwd):/workspaces/Hello-Cobra \ | ||
-w /workspaces/Hello-Cobra \ | ||
test:ci \ | ||
/bin/bash ./.github/run-tests-merge.sh | ||
curl -sSfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin | ||
./.github/check-requirements.sh | ||
./.github/run-tests-merge.sh |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
# ============================================================================= | ||
# ShellCheck Configuration | ||
# ============================================================================= | ||
# See: https://github.com/koalaman/shellcheck/wiki/ | ||
|
||
# Disable | ||
# SC2230: https://github.com/koalaman/shellcheck/wiki/SC2230 | ||
disable=SC2230 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,6 @@ | ||
# We do not want to version control the built binary. | ||
# Though we need this directory for access control purposes. | ||
# Output directory of built/compiled application via "../build-app.sh" | ||
# | ||
# We do not want to version control the built binary. Though we need | ||
# this directory for access control purposes. | ||
* | ||
!.gitignore |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.