Skip to content

Commit 70180df

Browse files
authored
feat: #27 go install testing and update docs (PR #28)
* feat: go install test * feat: merge test * Update Dockerfile * fix: image tag closing #27
1 parent c3537f4 commit 70180df

File tree

8 files changed

+112
-13
lines changed

8 files changed

+112
-13
lines changed

.github/Dockerfile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# =============================================================================
2-
# Test Container for Vaious Go Versions
2+
# Test Container for Vaious Go Versions (ver. 2021.11.26)
33
# =============================================================================
4+
45
# Default version
56
ARG VARIANT="1.15-alpine"
67

.github/docker-compose.yml

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,4 +71,34 @@ services:
7171
args:
7272
VARIANT: alpine
7373
volumes:
74-
- ..:/workspaces
74+
- ..:/workspaces
75+
# Service gogetu runs the test of installation functionality via 'go get -u'.
76+
gogetu:
77+
build:
78+
context: ..
79+
dockerfile: ./.github/Dockerfile
80+
args:
81+
VARIANT: 1.15-alpine
82+
volumes:
83+
- ..:/workspaces
84+
entrypoint: [ "./.github/run-tests-go-get-u.sh" ]
85+
# Service goinstall runs the test of installation functionality via 'go install'.
86+
goinstall:
87+
build:
88+
context: ..
89+
dockerfile: ./.github/Dockerfile
90+
args:
91+
VARIANT: 1.16-alpine
92+
volumes:
93+
- ..:/workspaces
94+
entrypoint: [ "./.github/run-tests-go-install.sh" ]
95+
# Service mergeability runs all the tests to be merged.
96+
mergeability:
97+
build:
98+
context: ..
99+
dockerfile: ./.devcontainer/Dockerfile
100+
args:
101+
VARIANT: latest
102+
volumes:
103+
- ..:/workspaces
104+
entrypoint: [ "./.github/run-tests-merge.sh" ]

.github/mergify.yml

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,20 @@ pull_request_rules:
22
- name: automatic merge on CI success and 2 approved reviews
33
conditions:
44
- "#approved-reviews-by>=2"
5-
- "check-success=merge_tests"
65
- base=main
6+
- check-success=lint
7+
- check-success=Analyze (go)
8+
- check-success=Run tests on Go via container
9+
- check-success=Platform test (ubuntu-latest)
10+
- check-success=Platform test (macos-latest)
11+
- check-success=Platform test (windows-latest)
712
- -draft
813
actions:
914
merge:
1015
method: squash
11-
- name: automatic merge on CI success if only markdown and/or Golang files were changed
16+
- name: automatic merge on CI success if only markdown files were changed
1217
conditions:
13-
- "check-success=merge_tests"
14-
- files~=.\.(?i)(md|go)$
18+
- files~=.\.(?i)(md)$
1519
- base=main
1620
- check-success=lint
1721
- check-success=Analyze (go)
@@ -23,7 +27,7 @@ pull_request_rules:
2327
actions:
2428
merge:
2529
method: squash
26-
- name: Automatic merge on approval
30+
- name: Automatic merge on bot's PR (go.mod and go.sum updateonly)
2731
conditions:
2832
- author=KEINOS
2933
- base=main

.github/run-tests-go-get-u.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
# =============================================================================
3+
# `go get -u` test (Go 1.15)
4+
# =============================================================================
5+
6+
cd /tmp || {
7+
echo >&2 "failed to move temp dir"
8+
exit 1
9+
}
10+
11+
GO111MODULE="on" go get -u "github.com/KEINOS/Hello-Cobra/hello-cobra@latest" || {
12+
echo >&2 "failed to install hello-cobra command via 'go get -u'"
13+
exit 1
14+
}
15+
16+
hello-cobra --version | grep "hello-cobra version v" || {
17+
echo >&2 "failed to execute command. Version info is missing"
18+
exit 1
19+
}

.github/run-tests-go-install.sh

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
#!/bin/sh
2+
# =============================================================================
3+
# `go install` test (Go 1.16+)
4+
# =============================================================================
5+
6+
cd /tmp || {
7+
echo >&2 "failed to move temp dir"
8+
exit 1
9+
}
10+
11+
go install "github.com/KEINOS/Hello-Cobra/hello-cobra@latest" || {
12+
echo >&2 "failed to install hello-cobra command via 'go install'"
13+
exit 1
14+
}
15+
16+
hello-cobra --version | grep "hello-cobra version v" || {
17+
echo >&2 "failed to execute command. Version info is missing"
18+
exit 1
19+
}

.github/workflows/update-mod-monthly.yml

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
# =============================================================================
22
# Weekly Module Update
33
# =============================================================================
4-
# This workflow runs monthly to update and test the latest `go.mod` version.
4+
# This workflow runs monthly to update and test the latest `go.mod` version and
5+
# `go install` (or `go get -u`) functionality.
56
#
67
# If all the tests succeeds to run in all Go versions, it will create a new PR
78
# of the `go.mod` and `go.sum`.
@@ -37,11 +38,16 @@ jobs:
3738
- name: Update go.mod and run tests
3839
run: |
3940
set -eu
40-
docker-compose --file ./.github/docker-compose.yml up tidy && \
41-
docker-compose --file ./.github/docker-compose.yml up v1_15 && \
42-
docker-compose --file ./.github/docker-compose.yml up v1_16 && \
43-
docker-compose --file ./.github/docker-compose.yml up v1_17 && \
41+
: # Update go.mod and go.sum
42+
docker-compose --file ./.github/docker-compose.yml up tidy
43+
: # Check mod version compatibility
44+
docker-compose --file ./.github/docker-compose.yml up v1_15
45+
docker-compose --file ./.github/docker-compose.yml up v1_16
46+
docker-compose --file ./.github/docker-compose.yml up v1_17
4447
docker-compose --file ./.github/docker-compose.yml up latest
48+
: # Check go install functionality
49+
docker-compose --file ./.github/docker-compose.yml up gogetu
50+
docker-compose --file ./.github/docker-compose.yml up gointall
4551
4652
- name: Create Pull Request on Change
4753
uses: peter-evans/create-pull-request@v3

.github/workflows/version-tests.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ jobs:
4242
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_16_1.tar
4343
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar
4444
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar
45+
docker load --input ${{ steps.imagetag.outputs.PATH_TAR }}/github_mergeability_1.tar
4546
4647
- name: Pull base images if no-exist
4748
if: steps.cache.outputs.cache-hit != 'true'
@@ -51,6 +52,7 @@ jobs:
5152
docker pull golang:1.16-alpine
5253
docker pull golang:1.17-alpine
5354
docker pull golang:alpine
55+
docker pull ghcr.io/keinos/vscode-dev-container-go:latest
5456
5557
- name: Build Docker images if no-exists
5658
if: steps.cache.outputs.cache-hit != 'true'
@@ -66,6 +68,7 @@ jobs:
6668
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_16_1.tar github_v1_16:latest
6769
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_v1_17_1.tar github_v1_17:latest
6870
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_latest_1.tar github_latest:latest
71+
docker save --output ${{ steps.imagetag.outputs.PATH_TAR }}/github_mergeability_1.tar github_mergeability:latest
6972
7073
- name: Run tests on Go 1.15
7174
run: docker-compose --file ./.github/docker-compose.yml up v1_15
@@ -74,4 +77,6 @@ jobs:
7477
- name: Run tests on Go 1.17
7578
run: docker-compose --file ./.github/docker-compose.yml up v1_17
7679
- name: Run tests on latest Go
77-
run: docker-compose --file ./.github/docker-compose.yml up latest
80+
run: docker-compose --file ./.github/docker-compose.yml up latest
81+
- name: Run tests for mergeability
82+
run: docker-compose --file ./.github/docker-compose.yml up mergeability

README.md

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,21 @@ This repo aims to implement best-practices of `Cobra` but keeping the code cover
2929

3030
## Note
3131

32+
- This package auto-detects the app version from the `git` tag if the app was installed via `go install` (on Go v1.16+) or `go get -u` (on Go 1.15). Try:
33+
```bash
34+
# For Go 1.16 or above
35+
cd /tmp
36+
go install "github.com/KEINOS/Hello-Cobra/hello-cobra@latest"
37+
hello-cobra --version
38+
# Output: hello-cobra version v1.3.0
39+
```
40+
```bash
41+
# For Go 1.15
42+
cd /tmp
43+
GO111MODULE="on" go get -u "github.com/KEINOS/Hello-Cobra/hello-cobra@latest"
44+
hello-cobra --version
45+
# Output: hello-cobra version v1.3.0
46+
```
3247
- This repo is [GitHub Codespaces](https://github.com/features/codespaces) compatible. Press the `.`(dot) key to open VSCode online. (You may need to register to use Codespaces)
3348
- This repo is [VS Code + Docker](https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack) compatible as well. See the [./.devcontainer/README.md](./.devcontainer/README.md) for more details.
3449
- This repo updates monthly the `go.mod` and `go.sum` files if all the tests succeeds to run in all Go versions (Go v1.15~latest).

0 commit comments

Comments
 (0)