Skip to content

Commit b739826

Browse files
authored
The fifth revision (#52)
1 parent 4ebf10d commit b739826

39 files changed

Lines changed: 1681 additions & 808 deletions

.github/workflows/lints.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,16 @@ jobs:
2222
with:
2323
go-version: stable
2424

25+
- name: Cache Go Modules
26+
uses: actions/cache@v4
27+
with:
28+
path: |
29+
~/.cache/go-build
30+
~/go/pkg/mod
31+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
32+
restore-keys: |
33+
${{ runner.os }}-go-
34+
2535
- name: Install Dependencies
2636
run: |
2737
make install-deps

.github/workflows/tests.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,16 @@ jobs:
2727
with:
2828
go-version: ${{ matrix.go-version }}
2929

30+
- name: Cache Go Modules
31+
uses: actions/cache@v4
32+
with:
33+
path: |
34+
~/.cache/go-build
35+
~/go/pkg/mod
36+
key: ${{ runner.os }}-go-${{ hashFiles('**/go.sum') }}
37+
restore-keys: |
38+
${{ runner.os }}-go-
39+
3040
- name: Install Dependencies
3141
run: |
3242
sudo apt-get update

.pre-commit-config.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
default_stages: [ pre-push ]
12
repos:
23
- repo: https://github.com/pre-commit/pre-commit-hooks
34
rev: v5.0.0
@@ -16,18 +17,17 @@ repos:
1617
entry: make format
1718
language: system
1819
pass_filenames: false
19-
types: [ go ]
20+
types: [ 'go' ]
2021

2122
- id: lint
2223
name: Check code style
2324
entry: make lint
2425
language: system
2526
pass_filenames: false
26-
types: [ go ]
27+
types: [ 'go' ]
2728

2829
- id: test
2930
name: Run tests
3031
entry: make test
3132
language: system
3233
pass_filenames: false
33-
stages: [ pre-push ]

CONTRIBUTING.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ sudo apt-get install -y golang-go make
3434
```
3535

3636
- Use the `make install-deps` command to install the development dependencies.
37+
- Use the `make setup-hooks` command to set up Git hooks for pre-commit checks.
3738

3839
### Code Style
3940

Makefile

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ run: build ## Build and run the binary
7777
.PHONY: clean
7878
clean: ## Remove artifacts and temporary files
7979
$(ECHO) "Cleaning up..."
80-
@$(GO) clean -cache -testcache -modcache
80+
@$(GO) clean #-cache -testcache -modcache
8181
@find . -type f -name '*.got.*' -delete
8282
@find . -type f -name '*.out' -delete
8383
@find . -type f -name '*.snap' -delete
@@ -100,7 +100,7 @@ install-snap: ## Install Snap (for Debian-based systems)
100100
install-deps: ## Install development dependencies (for Debian-based systems)
101101
$(ECHO) "Installing dependencies..."
102102
@sudo apt-get install -y make libgl1-mesa-dev libx11-dev xorg-dev \
103-
libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev pkg-config
103+
libxcursor-dev libxrandr-dev libxinerama-dev libxi-dev pkg-config libasound2-dev
104104
@$(MAKE) install-snap
105105
@sudo snap install go --classic
106106
@sudo snap install golangci-lint --classic
@@ -139,15 +139,17 @@ release-macos: ## Build release binary for macOS (v14 and newer; arm64)
139139
echo "Build complete: $(BINARY)"
140140

141141
.PHONY: setup-hooks
142-
setup-hooks: ## Set up pre-commit hooks
143-
@echo "Setting up pre-commit hooks..."
142+
setup-hooks: ## Install Git hooks (pre-commit and pre-push)
143+
@echo "Setting up Git hooks..."
144144
@if ! command -v pre-commit &> /dev/null; then \
145145
echo "pre-commit not found. Please install it using 'pip install pre-commit'"; \
146146
exit 1; \
147147
fi
148-
@pre-commit install --install-hooks
148+
@pre-commit install --hook-type pre-commit
149+
@pre-commit install --hook-type pre-push
150+
@pre-commit install-hooks
149151

150152
.PHONY: test-hooks
151-
test-hooks: ## Test pre-commit hooks on all files
152-
@echo "Testing pre-commit hooks..."
153-
@pre-commit run --all-files
153+
test-hooks: ## Test Git hooks on all files
154+
@echo "Testing Git hooks..."
155+
@pre-commit run --all-files --show-diff-on-failure

client/catalogue.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,15 @@ func RefreshCatalogue(
4444
totalGames := float64(len(gameIDs))
4545

4646
workerFunc := func(ctx context.Context, id int) error {
47+
// Defer the counter increment to guarantee it runs even if a fetch fails.
48+
defer func() {
49+
count := processedCount.Add(1)
50+
if progressCb != nil {
51+
progress := float64(count) / totalGames
52+
progressCb(progress)
53+
}
54+
}()
55+
4756
url := fmt.Sprintf("https://embed.gog.com/account/gameDetails/%d.json", id)
4857
details, raw, fetchErr := FetchGameData(token.AccessToken, url)
4958
if fetchErr != nil {
@@ -56,11 +65,6 @@ func RefreshCatalogue(
5665
}
5766
}
5867

59-
count := processedCount.Add(1)
60-
if progressCb != nil {
61-
progress := float64(count) / totalGames
62-
progressCb(progress)
63-
}
6468
return nil
6569
}
6670

0 commit comments

Comments
 (0)