Skip to content

Commit eed1d12

Browse files
authored
dev: refactor items and update repo deploy (#278)
* refactor: Refactor file paths and use map to store item names - Refactored file paths for various browsing data types to use a consistent method of generating temporary file names - Modified parsing functions in many browsing data types to use the new temporary file naming scheme - Renamed `FileName` to `Filename` for consistency in the `item` package - Removed unnecessary code and comments throughout various files - Made minor improvements to some Item methods such as `TempFilename` and `FileName` * ci: Optimize GitHub actions and update Go versions. (#274) * ci: Optimize GitHub actions and update Go versions. - Add GitHub actions for unit testing, linting, building, and releasing - Use a matrix strategy to test on different versions and platforms - Update setup-go and go-version options for compatibility - Format code and build zip files for different operating systems - Upload releases to GitHub with specific asset names and types * fix: Refactor item file naming convention - Update `filename()` function to return `UnsupportedItem` in specific cases - Replace `UnknownItem` with `UnsupportedItem` in `Filename` method of `Item` struct - Refactor code for clarity and consistency * ci: Update GitHub workflow with latest setup-go version - Update setup-go action to v3 in lint.yml GitHub workflow - Omits some big changes in file diff summary - Improve overall workflow reliability and efficiency * ci: Improve GitHub actions across platforms - Improve Windows compatibility in build workflow - Optimize unit testing for pull requests - Upgrade Coveralls GitHub action to v2 for improved coverage tracking * build: Optimize build process for consistency and efficiency - Ensure consistency of line endings by disabling Git's automatic conversion - Add format check for Windows systems - Update Go version in strategy matrix to `1.21.x` - Remove unused dependencies from build process - Include all packages in repository in build command * ci: Refactor GitHub workflow configuration - Remove unnecessary checks for `windows-latest` in github workflow - Change `gofmt` check to `diff` for formatting - Remove unneeded Git configuration for encoding of line endings - Close #273 * ci: Update default branch references in GitHub Actions workflows (#277) - Update Github Actions workflows to use `main` branch instead of `master`. - Rename `master` branch to `main` in `lint.yml` and `build.yml` files. - Change default branch to `main` in `contributors.yml` workflow file.
1 parent f4b4ad1 commit eed1d12

23 files changed

Lines changed: 330 additions & 229 deletions

File tree

.github/workflows/build.yml

Lines changed: 31 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,42 @@
11
name: build
2+
23
on:
34
push:
45
branches:
5-
- master
6+
- main
67
pull_request:
8+
79
jobs:
810
build:
9-
name: Build
10-
runs-on: ubuntu-latest
11+
name: Build on ${{ matrix.os }}
12+
runs-on: ${{ matrix.os }}
1113
strategy:
1214
matrix:
13-
goVer: ["1.21"]
15+
os: [ubuntu-latest, windows-latest, macos-latest]
16+
goVer: ["1.21.x"]
1417

1518
steps:
16-
- name: Set up Go ${{ matrix.goVer }}
17-
uses: actions/setup-go@v1
18-
with:
19-
go-version: ${{ matrix.goVer }}
20-
id: go
21-
22-
- name: Check out code into the Go module directory
23-
uses: actions/checkout@v2
24-
25-
- name: Get dependencies
26-
run: |
27-
go get -v -t -d ./...
28-
go get gopkg.in/check.v1
29-
30-
- name: Format
31-
run: diff -u <(echo -n) <(gofmt -d .)
32-
33-
- name: Build
34-
run: go build -v ./...
19+
- name: Set up Go ${{ matrix.goVer }}
20+
uses: actions/setup-go@v1
21+
with:
22+
go-version: ${{ matrix.goVer }}
23+
id: go
24+
25+
- name: Check out code into the Go module directory
26+
uses: actions/checkout@v2
27+
28+
- name: Set Git to handle line endings consistently
29+
run: git config --global core.autocrlf false
30+
31+
- name: Format Check
32+
if: matrix.os != 'windows-latest'
33+
run: |
34+
diff -u <(echo -n) <(gofmt -d .)
35+
36+
- name: Get dependencies
37+
run: |
38+
go get -v -t -d ./...
39+
go get gopkg.in/check.v1
40+
41+
- name: Build
42+
run: go build -v ./...

.github/workflows/contributors.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ on:
44
- cron: '0 1 * * 0' # At 01:00 on Sunday.
55
push:
66
branches:
7-
- master
7+
- main
88
workflow_dispatch:
99
inputs:
1010
logLevel:

.github/workflows/lint.yml

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,8 @@ name: Lint
22
on:
33
push:
44
branches:
5-
- master
5+
- main
66
pull_request:
7-
87
jobs:
98
lint:
109
name: Lint
@@ -13,7 +12,7 @@ jobs:
1312
- name: Set Golang
1413
uses: actions/setup-go@v3
1514
with:
16-
go-version: "1.21"
15+
go-version: "1.21.x"
1716
- name: Checkout code
1817
uses: actions/checkout@v3
1918
- name: Lint

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ jobs:
1313
- name: Use Golang
1414
uses: actions/setup-go@v3
1515
with:
16-
go-version: "1.21"
16+
go-version: "1.21.x"
1717

1818
- name: Build with xgo
1919
uses: crazy-max/ghaction-xgo@v2

.github/workflows/unittest.yml

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
on:
2+
[pull_request]
3+
4+
name: run tests
5+
jobs:
6+
test:
7+
strategy:
8+
matrix:
9+
go-version: [ "1.21.x" ]
10+
platform: [ubuntu-latest]
11+
runs-on: ${{ matrix.platform }}
12+
steps:
13+
- name: Install Go
14+
if: success()
15+
uses: actions/setup-go@v3
16+
with:
17+
go-version: ${{ matrix.go-version }}
18+
- name: Checkout code
19+
uses: actions/checkout@v2
20+
- name: Run tests
21+
run: go test -v ./... -covermode=count
22+
23+
coverage:
24+
runs-on: ubuntu-latest
25+
steps:
26+
- name: Install Go
27+
if: success()
28+
uses: actions/setup-go@v3
29+
with:
30+
go-version: "1.21.x"
31+
- name: Checkout code
32+
uses: actions/checkout@v2
33+
- name: Calc coverage
34+
run: |
35+
go test -v ./... -covermode=count -coverprofile=coverage.out
36+
37+
- name: Convert coverage.out to coverage.lcov
38+
uses: jandelgado/gcov2lcov-action@v1
39+
- name: Coveralls
40+
uses: coverallsapp/github-action@v2
41+
with:
42+
github-token: ${{ secrets.github_token }}
43+
path-to-lcov: coverage.lcov

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,3 +194,6 @@ hack-browser-data
194194
!/browsingdata/history
195195
!/browsingdata/history/history.go
196196
!/browsingdata/history/history_test.go
197+
198+
# github action
199+
!/.github/workflows/unittest.yml

browser/chromium/chromium.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (c *Chromium) BrowsingData(isFullExport bool) (*browsingdata.Data, error) {
7676

7777
func (c *Chromium) copyItemToLocal() error {
7878
for i, path := range c.itemPaths {
79-
filename := i.String()
79+
filename := i.TempFilename()
8080
var err error
8181
switch {
8282
case fileutil.IsDirExists(path):
@@ -109,7 +109,7 @@ func (c *Chromium) userItemPaths(profilePath string, items []item.Item) (map[str
109109
var dir string
110110
for userDir, v := range multiItemPaths {
111111
for _, p := range v {
112-
if strings.HasSuffix(p, item.ChromiumKey.FileName()) {
112+
if strings.HasSuffix(p, item.ChromiumKey.Filename()) {
113113
keyPath = p
114114
dir = userDir
115115
break
@@ -132,7 +132,7 @@ func (c *Chromium) userItemPaths(profilePath string, items []item.Item) (map[str
132132
func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item]string) filepath.WalkFunc {
133133
return func(path string, info fs.FileInfo, err error) error {
134134
for _, v := range items {
135-
if info.Name() == v.FileName() {
135+
if info.Name() == v.Filename() {
136136
if strings.Contains(path, "System Profile") {
137137
continue
138138
}
@@ -153,7 +153,7 @@ func chromiumWalkFunc(items []item.Item, multiItemPaths map[string]map[item.Item
153153

154154
func fillLocalStoragePath(itemPaths map[item.Item]string, storage item.Item) {
155155
if p, ok := itemPaths[item.ChromiumHistory]; ok {
156-
lsp := filepath.Join(filepath.Dir(p), storage.FileName())
156+
lsp := filepath.Join(filepath.Dir(p), storage.Filename())
157157
if fileutil.IsDirExists(lsp) {
158158
itemPaths[item.ChromiumLocalStorage] = lsp
159159
}

browser/chromium/chromium_darwin.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ var (
2424

2525
func (c *Chromium) GetMasterKey() ([]byte, error) {
2626
// don't need chromium key file for macOS
27-
defer os.Remove(item.TempChromiumKey)
27+
defer os.Remove(item.ChromiumKey.TempFilename())
2828
// Get the master key from the keychain
2929
// $ security find-generic-password -wa 'Chrome'
3030
var (

browser/chromium/chromium_linux.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
func (c *Chromium) GetMasterKey() ([]byte, error) {
1919
// what is d-bus @https://dbus.freedesktop.org/
2020
// don't need chromium key file for Linux
21-
defer os.Remove(item.TempChromiumKey)
21+
defer os.Remove(item.ChromiumKey.TempFilename())
2222

2323
conn, err := dbus.SessionBus()
2424
if err != nil {

browser/chromium/chromium_windows.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@ import (
1818
var errDecodeMasterKeyFailed = errors.New("decode master key failed")
1919

2020
func (c *Chromium) GetMasterKey() ([]byte, error) {
21-
b, err := fileutil.ReadFile(item.TempChromiumKey)
21+
b, err := fileutil.ReadFile(item.ChromiumKey.TempFilename())
2222
if err != nil {
2323
return nil, err
2424
}
25-
defer os.Remove(item.TempChromiumKey)
25+
defer os.Remove(item.ChromiumKey.TempFilename())
2626

2727
encryptedKey := gjson.Get(b, "os_crypt.encrypted_key")
2828
if !encryptedKey.Exists() {

0 commit comments

Comments
 (0)