Skip to content

Commit cd06d62

Browse files
committed
feat: CI/CD and update documentation
1 parent 13262c5 commit cd06d62

22 files changed

+595
-59
lines changed

.github/CONTRIBUTING.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
# CONTRIBUTING
2+
3+
## Pull Request
4+
5+
**Any PR for improvement is welcome!**
6+
7+
We will merge it as soon as it passes the CIs and not a prank-kind implementation. ;-)
8+
9+
- PR Branch: `main`
10+
- It is recommended to do a "[Draft-PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/)" before the actual implementation if the fix is big. However, feel free to discard it as well!
11+
- CI/CD: [Github Actions](./.github/workflows)
12+
- `go test ./...`
13+
- `golangci-lint run`
14+
- `golint ./...`
15+
- Code coverage check: 100% of coverage.
16+
17+
## Bug reports
18+
19+
- [Issues](https://github.com/KEINOS/go-noise/issues)
20+
- If possible, please attach a simple reproduction code sample of the error. PRs for the fixes are much appreciated. 🙏

.github/Dockerfile

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# =============================================================================
2+
# Test Container for Vaious Go Versions
3+
# =============================================================================
4+
# Default version
5+
ARG VARIANT="1.17-alpine"
6+
7+
# -----------------------------------------------------------------------------
8+
# Main Stage
9+
# -----------------------------------------------------------------------------
10+
FROM golang:${VARIANT}
11+
12+
RUN apk add --no-cache \
13+
git \
14+
alpine-sdk \
15+
build-base
16+
17+
WORKDIR /workspaces
18+
19+
ENTRYPOINT go mod download && go test -race ./...

.github/SECURITY.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Security Policy
2+
3+
## Supported Go Versions
4+
5+
The following Go versions are tested regularly every week. The version of the module contained in go.mod is also updated.
6+
7+
| Version | Supported |
8+
| :------ | :----------------: |
9+
| 1.17.10+ | :white_check_mark: |
10+
| 1.18.2+ | :white_check_mark: |
11+
12+
## Code Scaning
13+
14+
[![CodeQL](https://github.com/KEINOS/go-noise/actions/workflows/codeQL-analysis.yml/badge.svg)](https://github.com/KEINOS/go-noise/actions/workflows/codeQL-analysis.yml)
15+
16+
## Security Status
17+
18+
- Check the current "[Security overview](https://github.com/KEINOS/go-noise/security)" status.
19+
20+
## Reporting a Vulnerability
21+
22+
- Please [issue](https://github.com/KEINOS/go-noise/issues) them.

.github/docker-compose.yml

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
# =============================================================================
2+
# Docker Compose file for testing on Go versions 1.14~1.17 and latest.
3+
# =============================================================================
4+
# It is recommended to run specifying a specific Go version and not at once.
5+
#
6+
# Since the service `tidy` will update/re-write the "go.mod" file to the latest
7+
# version, during it's process the "go.mod" file will be gone temporarily. Thus,
8+
# it will cause failure in the other container becaue of missing "go.mod" file.
9+
#
10+
# Recommended usage:
11+
# docker-compose --file ./.github/docker-compose.yml run tidy && \
12+
# docker-compose --file ./.github/docker-compose.yml run v1_17
13+
#
14+
# NOT recommended to run all tests at once whith "up":
15+
# docker-compose --file ./.github/docker-compose.yml up
16+
version: "3.9"
17+
services:
18+
# Service tidy updates the go.mod to the latest on Go 1.17.
19+
tidy:
20+
build:
21+
context: ..
22+
dockerfile: ./.github/Dockerfile
23+
args:
24+
VARIANT: 1.17-alpine
25+
volumes:
26+
- ..:/workspaces
27+
entrypoint: [ "./.github/go-mod-tidy.sh" ]
28+
# Service v1_17 runs the tests on latest Go v1.17
29+
# Note that Go v1.14-16 are not supported.
30+
v1_17:
31+
build:
32+
context: ..
33+
dockerfile: ./.github/Dockerfile
34+
args:
35+
VARIANT: 1.17-alpine
36+
volumes:
37+
- ..:/workspaces
38+
# Service v1_18 runs the tests on latest Go v1.18
39+
v1_18:
40+
build:
41+
context: ..
42+
dockerfile: ./.github/Dockerfile
43+
args:
44+
VARIANT: 1.18-alpine
45+
volumes:
46+
- ..:/workspaces
47+
# Service latest runs the tests on latest Go
48+
latest:
49+
build:
50+
context: ..
51+
dockerfile: ./.github/Dockerfile
52+
args:
53+
VARIANT: alpine
54+
volumes:
55+
- ..:/workspaces

.github/go-mod-tidy.sh

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#!/bin/sh
2+
# =============================================================================
3+
# This script updates Go modules to the latest version.
4+
# =============================================================================
5+
# It will remove the go.mod file and run `go mod tidy` to get the latest moule
6+
# versions.
7+
# Then it will run the tests to make sure the code is still working, and fails
8+
# if any errors are found during the process.
9+
#
10+
# NOTE: This script is aimed to run in the container via docker-compose.
11+
# See "tidy" service: ./docker-compose.yml
12+
# =============================================================================
13+
14+
set -eu
15+
16+
echo '* Current Go version:' $(go version)
17+
18+
echo '* Backup modules ...'
19+
mv go.mod go.mod.bak
20+
mv go.sum go.sum.bak
21+
22+
echo '* Create new blank go.mod ...'
23+
< go.mod.bak head -n 4 > go.mod
24+
25+
echo '* Getting required Go modules ...'
26+
go get "github.com/aquilax/go-perlin"
27+
go get "github.com/ojrac/opensimplex-go"
28+
go get "github.com/pkg/errors"
29+
go get "github.com/stretchr/testify"
30+
31+
echo '* Run go tidy ...'
32+
go mod tidy
33+
34+
echo '* Run tests ...'
35+
go test ./... && {
36+
echo '* Testing passed. Removing old go.mod file ...'
37+
rm -f go.mod.bak
38+
rm -f go.sum.bak
39+
echo 'Successfully updated modules!'
40+
}

.github/mergify.yml

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
pull_request_rules:
2+
- name: Automatic merge on approval
3+
conditions:
4+
- author=KEINOS
5+
- base=main
6+
- title~=^Changes
7+
- files=go.mod
8+
- files=go.sum
9+
- "#files=2"
10+
- check-success=Analyze (go)
11+
- check-success=build
12+
- check-success=Unit test (ubuntu-latest)
13+
- check-success=Unit test (macos-latest)
14+
- check-success=Unit test (windows-latest)
15+
- check-success=CodeQL
16+
- check-success=codecov/patch
17+
- check-success=codecov/project
18+
actions:
19+
merge:
20+
method: merge
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# This workflow updates the code coverage of Codecov.
2+
# It runs the unit test and pushes the measured code coverage analysis.
3+
name: "Codecov"
4+
5+
on:
6+
push:
7+
branches: [ main ]
8+
pull_request:
9+
# The branches below must be a subset of the branches above
10+
branches: [ main ]
11+
12+
jobs:
13+
build:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v2
17+
with:
18+
fetch-depth: 2
19+
- uses: actions/setup-go@v2
20+
with:
21+
go-version: '1.17'
22+
- name: Run coverage
23+
run: go test -coverprofile=coverage.out -covermode=atomic ./...
24+
- name: Upload coverage to Codecov
25+
run: bash <(curl -s https://codecov.io/bash)
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
# For most projects, this workflow file will not need changing; you simply need
2+
# to commit it to your repository.
3+
#
4+
# You may wish to alter this file to override the set of languages analyzed,
5+
# or to provide custom queries or build logic.
6+
#
7+
name: "CodeQL"
8+
9+
on:
10+
push:
11+
branches: [ main ]
12+
pull_request:
13+
# The branches below must be a subset of the branches above
14+
branches: [ main ]
15+
schedule:
16+
# Runs at 18:30 UTC on day-of-month 1 (Every day-of-month 1 at AM 03:30 JST, my time)
17+
# See: https://crontab.guru/
18+
- cron: '30 18 1 * *'
19+
20+
jobs:
21+
analyze:
22+
name: Analyze
23+
runs-on: ubuntu-latest
24+
permissions:
25+
actions: read
26+
contents: read
27+
security-events: write
28+
29+
strategy:
30+
fail-fast: false
31+
matrix:
32+
language: [ 'go' ]
33+
# CodeQL supports [ 'cpp', 'csharp', 'go', 'java', 'javascript', 'python' ]
34+
# Learn more:
35+
# https://docs.github.com/en/free-pro-team@latest/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#changing-the-languages-that-are-analyzed
36+
37+
steps:
38+
- name: Checkout repository
39+
uses: actions/checkout@v2
40+
41+
# Initializes the CodeQL tools for scanning.
42+
- name: Initialize CodeQL
43+
uses: github/codeql-action/init@v2
44+
with:
45+
languages: ${{ matrix.language }}
46+
# If you wish to specify custom queries, you can do so here or in a config file.
47+
# By default, queries listed here will override any specified in a config file.
48+
# Prefix the list here with "+" to use these queries and those in the config file.
49+
# queries: ./path/to/local/query, your-org/your-repo/queries@main
50+
51+
# Autobuild attempts to build any compiled languages (C/C++, C#, or Java).
52+
# If this step fails, then you should remove it and run the build manually (see below)
53+
- name: Autobuild
54+
uses: github/codeql-action/autobuild@v2
55+
56+
# ℹ️ Command-line programs to run using the OS shell.
57+
# 📚 https://git.io/JvXDl
58+
59+
# ✏️ If the Autobuild fails above, remove it and uncomment the following three lines
60+
# and modify them (or add more) to build your code if your project
61+
# uses a compiled language
62+
63+
#- run: |
64+
# make bootstrap
65+
# make release
66+
67+
- name: Perform CodeQL Analysis
68+
uses: github/codeql-action/analyze@v2

.github/workflows/go-versions.yml

Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
# It runs unit tests on various versions of Go.
2+
name: go1.17+
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches: [ main ]
8+
schedule:
9+
# Runs at 19:10 UTC on day-of-month 1 (Every day-of-month 1 at AM 04:10 JST, my time)
10+
# See: https://crontab.guru/
11+
- cron: '10 19 1 * *'
12+
13+
env:
14+
PATH_CACHE: /tmp/docker-img-arch
15+
16+
jobs:
17+
go:
18+
name: Run tests on Go via container
19+
runs-on: ubuntu-latest
20+
steps:
21+
- name: Checkout repo
22+
uses: actions/checkout@v2
23+
24+
- name: Create hash for image tagging
25+
id: imagehash
26+
uses: KEINOS/gh-action-hash-for-cache@main
27+
with:
28+
path: |
29+
./.github/Dockerfile
30+
./go.mod
31+
variant: $(TZ=UTC-9 date '+%Y%m')
32+
33+
- name: Export cache paths and tags
34+
id: imagetag
35+
run: |
36+
HASH="${{ steps.imagehash.outputs.hash }}"
37+
TAG="${HASH:0:7}:cached"
38+
PATH_TAR=${{ env.PATH_CACHE }}"/tar"
39+
echo "::set-output name=TAG::${TAG}"
40+
echo "::set-output name=PATH_TAR::${PATH_TAR}"
41+
42+
- name: Enable cache/restore image archive
43+
id: cache
44+
uses: actions/cache@v2
45+
with:
46+
path: ${{ env.PATH_CACHE }}
47+
key: ${{ steps.imagehash.outputs.hash }}
48+
49+
- name: Load Docker images if exist
50+
if: steps.cache.outputs.cache-hit == 'true'
51+
run: |
52+
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar
53+
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_18_1.tar
54+
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar
55+
56+
- name: Pull base images if no-exist
57+
if: steps.cache.outputs.cache-hit != 'true'
58+
run: |
59+
: # Pull images one-by-one for stability
60+
docker pull golang:1.17-alpine
61+
docker pull golang:1.18-alpine
62+
docker pull golang:alpine
63+
64+
- name: Build Docker images if no-exists
65+
if: steps.cache.outputs.cache-hit != 'true'
66+
run: |
67+
mkdir -p ${{ steps.imagetag.outputs.PATH_TAR }}
68+
: # Build container images
69+
docker-compose --file ./.github/docker-compose.yml build
70+
71+
- name: Save built images if no-exists
72+
if: steps.cache.outputs.cache-hit != 'true'
73+
run: |
74+
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar github_v1_17:latest
75+
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_18_1.tar github_v1_18:latest
76+
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar github_latest:latest
77+
78+
- name: Run tests on Go 1.17
79+
run: docker-compose --file ./.github/docker-compose.yml run v1_17
80+
- name: Run tests on Go 1.18
81+
run: docker-compose --file ./.github/docker-compose.yml run v1_18
82+
- name: Run tests on latest Go
83+
run: docker-compose --file ./.github/docker-compose.yml run latest
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
# Details of this action see: https://github.com/golangci/golangci-lint-action
2+
name: golangci-lint
3+
4+
on:
5+
workflow_dispatch:
6+
push:
7+
branches: [ main ]
8+
9+
jobs:
10+
golangci:
11+
name: lint
12+
runs-on: ubuntu-latest
13+
steps:
14+
- uses: actions/checkout@v2
15+
- name: golangci-lint
16+
uses: golangci/golangci-lint-action@v2
17+
with:
18+
version: latest
19+
20+
# Optional: working directory, useful for monorepos
21+
# working-directory: somedir
22+
23+
# Optional: golangci-lint command line arguments.
24+
args: --config ./.golangci.yml
25+
26+
# Optional: show only new issues if it's a pull request. The default value is `false`.
27+
# only-new-issues: true
28+
29+
# Optional: if set to true then the action will use pre-installed Go
30+
# skip-go-installation: true

0 commit comments

Comments
 (0)