-
Notifications
You must be signed in to change notification settings - Fork 5
116 lines (108 loc) · 3.73 KB
/
Copy pathci.yml
File metadata and controls
116 lines (108 loc) · 3.73 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
name: CI
on:
push:
branches: [master]
pull_request:
branches: [master]
schedule:
- cron: '0 7 * * 1'
jobs:
shellcheck:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
- name: ShellCheck
run: |
shellcheck -s bash --severity=warning \
launch.sh dashboard.sh harvest.sh \
costs.sh progress.sh \
lib/*.sh lib/drivers/*.sh \
tests/*.sh
unit-tests:
strategy:
fail-fast: false
matrix:
os: [ubuntu-latest, macos-latest]
runs-on: ${{ matrix.os }}
steps:
- uses: actions/checkout@v5
- name: Install dependencies (Linux)
if: runner.os == 'Linux'
run: sudo apt-get update -qq && sudo apt-get install -y -qq jq bc
- name: Install dependencies (macOS)
if: runner.os == 'macOS'
run: brew install jq bash
- name: Unit tests
run: ./tests/test.sh --unit
commit-lint:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
ref: ${{ github.event.pull_request.head.sha }}
fetch-depth: 0
- name: Fetch master
run: |
git fetch origin master:refs/remotes/origin/master
- name: Ensure branch is up to date with master
run: |
head="${{ github.event.pull_request.head.sha }}"
if ! git merge-base --is-ancestor origin/master "$head"; then
echo "::error::PR branch is behind master. Please rebase onto"
echo "::error::master (we keep master linear -- don't merge"
echo "::error::master into your branch)."
exit 1
fi
- name: Validate commit messages
run: |
base="${{ github.event.pull_request.base.sha }}"
head="${{ github.event.pull_request.head.sha }}"
ok=true
while IFS= read -r sha; do
subject=$(git log -1 --format='%s' "$sha")
# Skip merge commits.
if git log -1 --format='%P' "$sha" | grep -q ' '; then
continue
fi
# Reject cleanup commits that should not land in history.
if echo "$subject" | grep -qEi '^(fixup|squash|wip)!?'; then
echo "::error::Commit $sha must be cleaned up: $subject"
ok=false
fi
done < <(git rev-list "$base".."$head")
[ "$ok" = true ]
semver-check:
if: github.event_name == 'pull_request'
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v5
with:
fetch-depth: 0
- name: Validate semver and changelog
run: |
git fetch origin master --depth=1
new=$(cat VERSION | tr -d '[:space:]')
old=$(git show origin/master:VERSION 2>/dev/null | tr -d '[:space:]' || echo "0.0.0")
# If VERSION unchanged, nothing to check.
if [ "$new" = "$old" ]; then
echo "VERSION unchanged ($new), skipping."
exit 0
fi
# Validate semver format.
if ! echo "$new" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "::error::VERSION '$new' is not valid semver (expected X.Y.Z)"
exit 1
fi
# Check version was incremented.
newer=$(printf '%s\n%s' "$old" "$new" | sort -V | tail -1)
if [ "$newer" != "$new" ] || [ "$new" = "$old" ]; then
echo "::error::VERSION must increment: $old -> $new"
exit 1
fi
# Check CHANGELOG has entry for new version.
if ! grep -qF "## $new" CHANGELOG.md; then
echo "::error::CHANGELOG.md missing entry for version $new"
exit 1
fi
echo "Version bump OK: $old -> $new"