Skip to content

Commit 95c6a7f

Browse files
committed
feat: add go-tool and go-service
1 parent 490b544 commit 95c6a7f

File tree

15 files changed

+962
-44
lines changed

15 files changed

+962
-44
lines changed

.github/actions/check/service.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
@error() { echo "${@}" >&2; }
6+
@fatal() { @error "${@}" && exit 1; }
7+
8+
# TODO:implement
9+
echo not implemented yet

.github/actions/check/tool.bash

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
#!/usr/bin/env bash
2+
3+
set -euo pipefail
4+
5+
@error() { echo "${@}" >&2; }
6+
@fatal() { @error "${@}" && exit 1; }
7+
8+
# TODO:implement
9+
echo not implemented yet

.github/workflows/ci.godownloader.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
name: Continuous integration (godownloader)
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
reason:
7-
description: The reason for dispatching it manually.
8-
type: string
9-
default: manual healthcheck
10-
required: true
11-
124
push:
135
branches: [ main ]
146
paths:
@@ -19,6 +11,14 @@ on:
1911
schedule:
2012
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
2113

14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
2222
jobs:
2323
check:
2424
name: Checking

.github/workflows/ci.goimports.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
name: Continuous integration (goimports)
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
reason:
7-
description: The reason for dispatching it manually.
8-
type: string
9-
default: manual healthcheck
10-
required: true
11-
124
push:
135
branches: [ main ]
146
paths:
@@ -19,6 +11,14 @@ on:
1911
schedule:
2012
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
2113

14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
2222
jobs:
2323
check:
2424
name: Checking

.github/workflows/ci.golangci-lint.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
name: Continuous integration (golangci-lint)
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
reason:
7-
description: The reason for dispatching it manually.
8-
type: string
9-
default: manual healthcheck
10-
required: true
11-
124
push:
135
branches: [ main ]
146
paths:
@@ -19,6 +11,14 @@ on:
1911
schedule:
2012
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
2113

14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
2222
jobs:
2323
check:
2424
name: Checking

.github/workflows/ci.maintainer.yml

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,6 @@
11
name: Continuous integration (maintainer)
22

33
on:
4-
workflow_dispatch:
5-
inputs:
6-
reason:
7-
description: The reason for dispatching it manually.
8-
type: string
9-
default: manual healthcheck
10-
required: true
11-
124
push:
135
branches: [ main ]
146
paths:
@@ -19,6 +11,14 @@ on:
1911
schedule:
2012
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
2113

14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
2222
jobs:
2323
check:
2424
name: Checking

.github/workflows/ci.service.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Continuous integration (service template)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- '.github/actions/check/service.bash'
8+
- '.github/workflows/ci.service.yml'
9+
- 'dist/service'
10+
11+
schedule:
12+
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
13+
14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
22+
jobs:
23+
check:
24+
name: Checking
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout the repository
29+
uses: actions/checkout@v3
30+
with: { fetch-depth: 0 }
31+
32+
- name: Check consistency
33+
uses: ./.github/actions/check
34+
with: { script: service.bash }
35+
36+
notify:
37+
name: Notifying
38+
needs: [ check ]
39+
runs-on: ubuntu-latest
40+
if: failure() || success()
41+
42+
steps:
43+
- name: Checkout the repository
44+
uses: actions/checkout@v3
45+
with: { fetch-depth: 0 }
46+
47+
- name: Send notification
48+
uses: ./.github/actions/notify
49+
continue-on-error: true
50+
with:
51+
channel: ${{ secrets.SLACK_WEBHOOK }}
52+
success: ${{ ! contains(needs.*.result, 'failure') }}

.github/workflows/ci.tool.yml

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
name: Continuous integration (tool template)
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
paths:
7+
- '.github/actions/check/tool.bash'
8+
- '.github/workflows/ci.tool.yml'
9+
- 'dist/tool'
10+
11+
schedule:
12+
- cron: '0 7 * * 1' # at 07:00 on Monday, UTC
13+
14+
workflow_dispatch:
15+
inputs:
16+
reason:
17+
description: The reason for dispatching it manually.
18+
type: string
19+
default: manual healthcheck
20+
required: true
21+
22+
jobs:
23+
check:
24+
name: Checking
25+
runs-on: ubuntu-latest
26+
27+
steps:
28+
- name: Checkout the repository
29+
uses: actions/checkout@v3
30+
with: { fetch-depth: 0 }
31+
32+
- name: Check consistency
33+
uses: ./.github/actions/check
34+
with: { script: tool.bash }
35+
36+
notify:
37+
name: Notifying
38+
needs: [ check ]
39+
runs-on: ubuntu-latest
40+
if: failure() || success()
41+
42+
steps:
43+
- name: Checkout the repository
44+
uses: actions/checkout@v3
45+
with: { fetch-depth: 0 }
46+
47+
- name: Send notification
48+
uses: ./.github/actions/notify
49+
continue-on-error: true
50+
with:
51+
channel: ${{ secrets.SLACK_WEBHOOK }}
52+
success: ${{ ! contains(needs.*.result, 'failure') }}

.github/workflows/cleanup.runs.yml

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ on:
1616
- Continuous integration (goimports)
1717
- Continuous integration (golangci-lint)
1818
- Continuous integration (maintainer)
19+
- Continuous integration (service template)
20+
- Continuous integration (tool template)
1921
- Workflow runs cleanup
2022
default: Workflow runs cleanup
2123
required: true
@@ -44,6 +46,18 @@ jobs:
4446
dry_run: ${{ fromJSON('["", "true"]')[github.event.inputs.dry_run == 'true'] }}
4547
retain_days: 0
4648
keep_minimum_runs: 0
49+
- name: Cleanup workflow runs
50+
run: |
51+
gh run list \
52+
-R '${{ github.repository }}' \
53+
--status completed \
54+
--limit 100 \
55+
--json databaseId \
56+
--jq '.[] | .databaseId' |
57+
xargs -n1 --no-run-if-empty gh run delete -R '${{ github.repository }}'
58+
env:
59+
GITHUB_TOKEN: ${{ github.token }}
60+
if: github.event.inputs.pattern == 'All'
4761

4862
notify:
4963
name: Notifying

README.md

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,31 @@ golangci-lint version
5757
[golangci-lint]: https://golangci-lint.octolab.org/
5858

5959

60+
### 🧩 [go-service][]
61+
62+
```bash
63+
curl -sSfL https://install.octolab.org/service | sh -s -- -b /usr/local/bin
64+
server help
65+
server version
66+
67+
serverctl help
68+
serverctl version
69+
```
70+
71+
[go-service]: https://go-service.octolab.org/
72+
73+
74+
### 🧩 [go-tool][]
75+
76+
```bash
77+
curl -sSfL https://install.octolab.org/tool | sh -s -- -b /usr/local/bin
78+
tool help
79+
tool version
80+
```
81+
82+
[go-tool]: https://go-tool.octolab.org/
83+
84+
6085
### 👨‍🔧 [maintainer][]
6186

6287
```bash

Taskfile

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ set -euo pipefail
77
exit 1
88
}
99

10+
root=$(git rev-parse --show-toplevel)
1011
include=(
11-
bin/lib/utils/*.bash
12-
bin/lib/git/*.bash
13-
bin/lib/tools/*.bash
14-
bin/lib/config/*.bash
15-
bin/lib/main.bash
12+
"${root}"/bin/lib/utils/*.bash
13+
"${root}"/bin/lib/git/*.bash
14+
"${root}"/bin/lib/tools/*.bash
15+
"${root}"/bin/lib/config/*.bash
16+
"${root}"/bin/lib/*.bash
1617
)
1718

1819
for script in "${include[@]}"; do

bin/lib/config/global.bash

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,14 @@ config['dryrun']=false
1313
case "${arg}" in
1414
-d | --dry-run)
1515
config['dryrun']=true
16-
1716
config['shift']=$((config['shift'] + 1))
1817
shift
1918
;;
20-
2119
--trace)
2220
set -x
23-
2421
config['shift']=$((config['shift'] + 1))
2522
shift
2623
;;
27-
2824
*) break ;;
2925
esac
3026
done

bin/lib/tools/_.bash

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,27 @@ if [[ ":${PATH}:" != *":${_BINPATH}:"* ]]; then
66
export PATH="${_BINPATH}:${PATH}"
77
fi
88
[ -d "${_BINPATH}" ] || mkdir -p "${_BINPATH}"
9+
export GOBIN="${_BINPATH}"
910

10-
# Example: run @install dist/vendor/gum
11-
# Example: run @install dist/vendor/gum ./bin/{os}/{arch}
12-
# Example: run @install https://install.octolab.org/vendor/gum
11+
# Example: run @install path/to/gum
12+
# Example: run @install vendor/gum ./bin/{os}/{arch}
1313
# Example: run @install https://install.octolab.org/vendor/gum ./bin/{os}/{arch}
1414
@install() {
1515
local script=${1} path=${2:-${_BINPATH}}
1616
path=${path/'{os}'/$(@os)}
1717
path=${path/'{arch}'/$(@arch)}
18+
19+
if [[ "${script}" =~ ^vendor/ ]]; then
20+
script="https://install.octolab.org/${script}"
21+
fi
22+
if [[ ! "${script}" =~ ^https:// ]] && [ ! -f "${script}" ]; then
23+
script="https://install.octolab.org/${script}"
24+
fi
25+
26+
[[ "${script}" =~ ^https:// ]] && [ \
27+
"$(curl -s -o /dev/null -w '%{http_code}' --head "${script}")" -eq "200" \
28+
]
29+
1830
if [[ "${script}" =~ ^https://install.octolab.org/vendor ]]; then
1931
curl -sSfL "${script}" | bash -s -- "${path}"
2032
return $?

0 commit comments

Comments
 (0)