git-fit 0.9.1 → 0.9.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/db/migrations/001_full_schema.rb +64 -0
- data/db/migrations/002_iso8601_time_format.rb +54 -0
- data/lib/git_fit/fit/decoder.js +1 -0
- data/lib/git_fit/install/actions/db-store/restore.yml.erb +94 -0
- data/lib/git_fit/install/actions/db-store/save.yml.erb +115 -0
- data/lib/git_fit/version.rb +1 -1
- metadata +6 -1
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
name: DB Store Restore
|
|
2
|
+
description: Restore DB from cache and/or git with SHA256SUMS verification. Use 'db-from-git' to enable git restore; 'shall-commit-db' is deprecated.
|
|
3
|
+
inputs:
|
|
4
|
+
path:
|
|
5
|
+
required: false
|
|
6
|
+
default: <%= db_path %>
|
|
7
|
+
key-prefix:
|
|
8
|
+
required: false
|
|
9
|
+
default: db
|
|
10
|
+
db-schema-hash:
|
|
11
|
+
required: false
|
|
12
|
+
default: ""
|
|
13
|
+
db-from-git:
|
|
14
|
+
required: false
|
|
15
|
+
default: 'false'
|
|
16
|
+
description: "Whether to restore DB from the git branch (read-only)"
|
|
17
|
+
shall-commit-db:
|
|
18
|
+
required: false
|
|
19
|
+
default: 'false'
|
|
20
|
+
description: "Deprecated: use 'db-from-git' instead"
|
|
21
|
+
git-branch:
|
|
22
|
+
required: false
|
|
23
|
+
default: _/db
|
|
24
|
+
outputs:
|
|
25
|
+
clean:
|
|
26
|
+
description: "Whether the restored DB passed SHA256 verification"
|
|
27
|
+
value: ${{ steps.db-restore-check.outputs.clean }}
|
|
28
|
+
runs:
|
|
29
|
+
using: composite
|
|
30
|
+
steps:
|
|
31
|
+
- name: Deprecation warning for shall-commit-db
|
|
32
|
+
if: inputs.shall-commit-db == 'true'
|
|
33
|
+
shell: bash
|
|
34
|
+
run: |
|
|
35
|
+
echo "::warning::shall-commit-db is deprecated in restore context; use 'db-from-git' instead"
|
|
36
|
+
|
|
37
|
+
- name: Build cache key
|
|
38
|
+
id: ck
|
|
39
|
+
shell: bash
|
|
40
|
+
run: |
|
|
41
|
+
mhash="${{ inputs.db-schema-hash }}"
|
|
42
|
+
[[ -n "$mhash" ]] && mhash="-${mhash}"
|
|
43
|
+
echo "key=${{ inputs.key-prefix }}-v1${mhash}-${{ github.run_id }}" >> $GITHUB_OUTPUT
|
|
44
|
+
|
|
45
|
+
- name: Check DB git branch
|
|
46
|
+
id: db-git-check
|
|
47
|
+
if: inputs.db-from-git == 'true' || inputs.shall-commit-db == 'true'
|
|
48
|
+
shell: bash
|
|
49
|
+
run: |
|
|
50
|
+
if git ls-remote --exit-code origin refs/heads/${{ inputs.git-branch }} >/dev/null 2>&1; then
|
|
51
|
+
echo "exists=true" >> $GITHUB_OUTPUT
|
|
52
|
+
else
|
|
53
|
+
echo "exists=false" >> $GITHUB_OUTPUT
|
|
54
|
+
fi
|
|
55
|
+
|
|
56
|
+
- name: Restore DB from git
|
|
57
|
+
if: (inputs.db-from-git == 'true' || inputs.shall-commit-db == 'true') && steps.db-git-check.outputs.exists == 'true'
|
|
58
|
+
shell: bash
|
|
59
|
+
run: |
|
|
60
|
+
dir=$(dirname "${{ inputs.path }}")
|
|
61
|
+
git fetch origin "${{ inputs.git-branch }}"
|
|
62
|
+
mkdir -p "$dir"
|
|
63
|
+
git archive --format=tar "origin/${{ inputs.git-branch }}" \
|
|
64
|
+
"${{ inputs.path }}" "${{ inputs.path }}.SHA256SUMS" \
|
|
65
|
+
"${{ inputs.path }}-wal" "${{ inputs.path }}-shm" 2>/dev/null | tar xf - || true
|
|
66
|
+
|
|
67
|
+
- name: Restore DB cache
|
|
68
|
+
uses: actions/cache/restore@v4
|
|
69
|
+
id: restore-db
|
|
70
|
+
with:
|
|
71
|
+
path: |-
|
|
72
|
+
${{ inputs.path }}
|
|
73
|
+
${{ inputs.path }}.SHA256SUMS
|
|
74
|
+
${{ inputs.path }}-wal
|
|
75
|
+
${{ inputs.path }}-shm
|
|
76
|
+
key: ${{ steps.ck.outputs.key }}
|
|
77
|
+
restore-keys: ${{ inputs.key-prefix }}-v1-
|
|
78
|
+
|
|
79
|
+
- name: Verify DB restore
|
|
80
|
+
id: db-restore-check
|
|
81
|
+
shell: bash
|
|
82
|
+
run: |
|
|
83
|
+
db="${{ inputs.path }}"
|
|
84
|
+
ck="${db}.SHA256SUMS"
|
|
85
|
+
if [ ! -f "$db" ]; then
|
|
86
|
+
echo "clean=true" >> $GITHUB_OUTPUT
|
|
87
|
+
exit 0
|
|
88
|
+
fi
|
|
89
|
+
if [ -f "$ck" ] && sha256sum -c "$ck" --quiet >/dev/null 2>&1; then
|
|
90
|
+
echo "clean=true" >> $GITHUB_OUTPUT
|
|
91
|
+
else
|
|
92
|
+
echo "clean=false" >> $GITHUB_OUTPUT
|
|
93
|
+
[ ! -f "$ck" ] && sha256sum "$db" > "$ck"
|
|
94
|
+
fi
|
|
@@ -0,0 +1,115 @@
|
|
|
1
|
+
name: DB Store Save
|
|
2
|
+
description: Save DB to cache and/or git with SHA256SUMS, skip if unchanged
|
|
3
|
+
inputs:
|
|
4
|
+
path:
|
|
5
|
+
required: false
|
|
6
|
+
default: <%= db_path %>
|
|
7
|
+
key-prefix:
|
|
8
|
+
required: false
|
|
9
|
+
default: db
|
|
10
|
+
db-schema-hash:
|
|
11
|
+
required: false
|
|
12
|
+
default: ""
|
|
13
|
+
db-to-git:
|
|
14
|
+
required: false
|
|
15
|
+
default: 'false'
|
|
16
|
+
description: "Whether to save DB to the git branch"
|
|
17
|
+
shall-commit-db:
|
|
18
|
+
required: false
|
|
19
|
+
default: 'false'
|
|
20
|
+
description: "Deprecated: use 'db-to-git' instead"
|
|
21
|
+
git-branch:
|
|
22
|
+
required: false
|
|
23
|
+
default: _/db
|
|
24
|
+
commit-author-name:
|
|
25
|
+
required: false
|
|
26
|
+
default: "git-fit-bot"
|
|
27
|
+
commit-author-email:
|
|
28
|
+
required: false
|
|
29
|
+
default: "bot@git-fit"
|
|
30
|
+
outputs:
|
|
31
|
+
db-changed:
|
|
32
|
+
description: "Whether the DB changed and needs saving"
|
|
33
|
+
value: ${{ steps.check.outputs.db-changed }}
|
|
34
|
+
saved:
|
|
35
|
+
description: "Whether the DB was actually saved (cache or git)"
|
|
36
|
+
value: ${{ steps.check.outputs.db-changed }}
|
|
37
|
+
runs:
|
|
38
|
+
using: composite
|
|
39
|
+
steps:
|
|
40
|
+
- name: Deprecation warning for shall-commit-db
|
|
41
|
+
if: inputs.shall-commit-db == 'true'
|
|
42
|
+
shell: bash
|
|
43
|
+
run: |
|
|
44
|
+
echo "::warning::shall-commit-db is deprecated; use 'db-to-git' instead"
|
|
45
|
+
|
|
46
|
+
- name: Check DB changed
|
|
47
|
+
id: check
|
|
48
|
+
shell: bash
|
|
49
|
+
run: |
|
|
50
|
+
db="${{ inputs.path }}"
|
|
51
|
+
ck="${db}.SHA256SUMS"
|
|
52
|
+
if [ ! -f "$db" ]; then
|
|
53
|
+
echo "db-changed=false" >> $GITHUB_OUTPUT
|
|
54
|
+
exit 0
|
|
55
|
+
fi
|
|
56
|
+
if [ -f "$ck" ] && sha256sum -c "$ck" --quiet >/dev/null 2>&1; then
|
|
57
|
+
echo "db-changed=false" >> $GITHUB_OUTPUT
|
|
58
|
+
else
|
|
59
|
+
echo "db-changed=true" >> $GITHUB_OUTPUT
|
|
60
|
+
fi
|
|
61
|
+
|
|
62
|
+
- name: Generate DB SHA256SUMS
|
|
63
|
+
if: steps.check.outputs.db-changed == 'true'
|
|
64
|
+
shell: bash
|
|
65
|
+
run: sha256sum "${{ inputs.path }}" > "${{ inputs.path }}.SHA256SUMS"
|
|
66
|
+
|
|
67
|
+
- name: Save DB git
|
|
68
|
+
if: (inputs.db-to-git == 'true' || inputs.shall-commit-db == 'true') && steps.check.outputs.db-changed == 'true'
|
|
69
|
+
shell: bash
|
|
70
|
+
run: |
|
|
71
|
+
BRANCH="${{ inputs.git-branch }}"
|
|
72
|
+
DB="${{ inputs.path }}"
|
|
73
|
+
CK="${DB}.SHA256SUMS"
|
|
74
|
+
TEMP_INDEX=".git/cache-index-$$"
|
|
75
|
+
cleanup() { rm -f "$TEMP_INDEX"; }
|
|
76
|
+
trap cleanup EXIT
|
|
77
|
+
if ! git fetch origin "$BRANCH" 2>/dev/null; then
|
|
78
|
+
echo "Git fetch failed for $BRANCH, skipping git save" >&2
|
|
79
|
+
exit 0
|
|
80
|
+
fi
|
|
81
|
+
GIT_INDEX_FILE="$TEMP_INDEX" git read-tree --empty
|
|
82
|
+
GIT_INDEX_FILE="$TEMP_INDEX" git add -f "$DB" "$CK" "$DB-wal" "$DB-shm"
|
|
83
|
+
GIT_INDEX_FILE="$TEMP_INDEX" git diff-index --cached --quiet "origin/$BRANCH" 2>/dev/null && {
|
|
84
|
+
echo "No changes to $BRANCH" >&2
|
|
85
|
+
exit 0
|
|
86
|
+
}
|
|
87
|
+
TREE=$(GIT_INDEX_FILE="$TEMP_INDEX" git write-tree)
|
|
88
|
+
if git rev-parse --verify "origin/$BRANCH" >/dev/null 2>&1; then
|
|
89
|
+
PARENT=$(git rev-parse "origin/$BRANCH")
|
|
90
|
+
COMMIT=$(git -c user.name="${{ inputs.commit-author-name }}" -c user.email="${{ inputs.commit-author-email }}" \
|
|
91
|
+
commit-tree -p "$PARENT" -m "store($BRANCH): $(date -u +%Y%m%d-%H%M%S)" "$TREE")
|
|
92
|
+
else
|
|
93
|
+
COMMIT=$(git -c user.name="${{ inputs.commit-author-name }}" -c user.email="${{ inputs.commit-author-email }}" \
|
|
94
|
+
commit-tree -m "store($BRANCH): $(date -u +%Y%m%d-%H%M%S)" "$TREE")
|
|
95
|
+
fi
|
|
96
|
+
git push origin "$COMMIT:refs/heads/$BRANCH"
|
|
97
|
+
|
|
98
|
+
- name: Build cache key
|
|
99
|
+
id: ck
|
|
100
|
+
shell: bash
|
|
101
|
+
run: |
|
|
102
|
+
mhash="${{ inputs.db-schema-hash }}"
|
|
103
|
+
[[ -n "$mhash" ]] && mhash="-${mhash}"
|
|
104
|
+
echo "key=${{ inputs.key-prefix }}-v1${mhash}-${{ github.run_id }}" >> $GITHUB_OUTPUT
|
|
105
|
+
|
|
106
|
+
- name: Save DB cache
|
|
107
|
+
uses: actions/cache/save@v4
|
|
108
|
+
if: steps.check.outputs.db-changed == 'true'
|
|
109
|
+
with:
|
|
110
|
+
path: |-
|
|
111
|
+
${{ inputs.path }}
|
|
112
|
+
${{ inputs.path }}.SHA256SUMS
|
|
113
|
+
${{ inputs.path }}-wal
|
|
114
|
+
${{ inputs.path }}-shm
|
|
115
|
+
key: ${{ steps.ck.outputs.key }}
|
data/lib/git_fit/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: git-fit
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.9.
|
|
4
|
+
version: 0.9.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Lax
|
|
@@ -186,6 +186,8 @@ executables:
|
|
|
186
186
|
extensions: []
|
|
187
187
|
extra_rdoc_files: []
|
|
188
188
|
files:
|
|
189
|
+
- db/migrations/001_full_schema.rb
|
|
190
|
+
- db/migrations/002_iso8601_time_format.rb
|
|
189
191
|
- exe/git-fit
|
|
190
192
|
- lib/git-fit.rb
|
|
191
193
|
- lib/git_fit/cli.rb
|
|
@@ -205,6 +207,7 @@ files:
|
|
|
205
207
|
- lib/git_fit/export/defaults.rb
|
|
206
208
|
- lib/git_fit/export/json.rb
|
|
207
209
|
- lib/git_fit/fit.rb
|
|
210
|
+
- lib/git_fit/fit/decoder.js
|
|
208
211
|
- lib/git_fit/fit/decoder.rb
|
|
209
212
|
- lib/git_fit/geo.rb
|
|
210
213
|
- lib/git_fit/geo/amap_client.rb
|
|
@@ -217,6 +220,8 @@ files:
|
|
|
217
220
|
- lib/git_fit/import/apple_health.rb
|
|
218
221
|
- lib/git_fit/import/local_file.rb
|
|
219
222
|
- lib/git_fit/install/actions.rb
|
|
223
|
+
- lib/git_fit/install/actions/db-store/restore.yml.erb
|
|
224
|
+
- lib/git_fit/install/actions/db-store/save.yml.erb
|
|
220
225
|
- lib/git_fit/parser.rb
|
|
221
226
|
- lib/git_fit/parser/base.rb
|
|
222
227
|
- lib/git_fit/parser/fit.rb
|