Skip to content

Commit 150ae06

Browse files
committed
feat: fixing some odd stuff + ci
1 parent 029f073 commit 150ae06

File tree

7 files changed

+112
-12
lines changed

7 files changed

+112
-12
lines changed

.github/workflows/build.yml

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
name: Build CargoDrop
2+
3+
on:
4+
push:
5+
branches: [ build ]
6+
pull_request:
7+
branches: [ build ]
8+
release:
9+
types: [ published ]
10+
11+
jobs:
12+
build:
13+
runs-on: ubuntu-latest
14+
strategy:
15+
matrix:
16+
goos: [linux, windows]
17+
goarch: [amd64]
18+
include:
19+
- goos: linux
20+
goarch: amd64
21+
ext: ""
22+
- goos: windows
23+
goarch: amd64
24+
ext: ".exe"
25+
26+
steps:
27+
- uses: actions/checkout@v4
28+
with:
29+
fetch-depth: 0 # Needed for git rev-parse to work
30+
31+
- name: Set up Go
32+
uses: actions/setup-go@v5
33+
with:
34+
go-version: '1.21'
35+
36+
- name: Get dependencies
37+
run: go mod download
38+
39+
- name: Get build info
40+
id: build_info
41+
run: |
42+
echo "commit_hash=$(git rev-parse --short HEAD)" >> $GITHUB_OUTPUT
43+
echo "build_date=$(date -u +'%Y-%m-%d_%H-%M-%S')" >> $GITHUB_OUTPUT
44+
45+
- name: Build
46+
env:
47+
GOOS: ${{ matrix.goos }}
48+
GOARCH: ${{ matrix.goarch }}
49+
run: |
50+
go build \
51+
-ldflags "-X github.com/cosmiclabstudio/cargodrop/internal/utils.BuildHash=${{ steps.build_info.outputs.commit_hash }}" \
52+
-o cargodrop-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }} \
53+
./cmd/cargodrop
54+
55+
- name: Upload artifact
56+
uses: actions/upload-artifact@v4
57+
with:
58+
name: cargodrop-${{ matrix.goos }}-${{ matrix.goarch }}
59+
path: cargodrop-${{ matrix.goos }}-${{ matrix.goarch }}${{ matrix.ext }}
60+
61+
release:
62+
needs: build
63+
runs-on: ubuntu-latest
64+
if: github.event_name == 'release'
65+
66+
steps:
67+
- name: Download all artifacts
68+
uses: actions/download-artifact@v4
69+
70+
- name: Display structure of downloaded files
71+
run: ls -la
72+
73+
- name: Upload release assets
74+
uses: softprops/action-gh-release@v1
75+
with:
76+
files: |
77+
cargodrop-linux-amd64/cargodrop-linux-amd64
78+
cargodrop-windows-amd64/cargodrop-windows-amd64.exe
79+
env:
80+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

cmd/cargodrop/main.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,27 @@ import (
1313
)
1414

1515
func main() {
16+
baseDir := flag.String("base-dir", ".", "The directory containing the base files")
1617
configPath := flag.String("config", "", "Path to config file")
1718
resourcesPath := flag.String("resources", "", "Path to resources file")
1819
isGenResource := flag.Bool("generate-metadata", false, "Whether to generate metadata for server")
1920
isServiceModrinth := flag.Bool("modrinth", false, "Use Modrinth to add download links")
2021
flag.Parse()
2122

22-
utils.LogMessage("Config file: " + *configPath)
23-
utils.LogMessage("Resources file: " + *resourcesPath)
24-
2523
config, err := parsers.LoadConfig(*configPath)
2624
if err != nil {
2725
utils.LogError(err)
2826
return
2927
}
28+
utils.LogMessage("Config file: " + *configPath)
3029

3130
resources, err := parsers.LoadResource(*resourcesPath)
3231
if err != nil {
3332
resources = &parsers.ResourceSet{
3433
Name: config.Name,
3534
LocalVersion: "1.0.0",
3635
ResourceSetHash: "",
36+
Patches: []parsers.Patches{},
3737
Resources: []parsers.Resource{},
3838
}
3939

@@ -45,6 +45,7 @@ func main() {
4545
}
4646
utils.LogWarning("Missing resource.json! Creating one at " + *resourcesPath)
4747
}
48+
utils.LogMessage("Resources file: " + *resourcesPath)
4849

4950
a := app.New()
5051
mw := gui.NewMainWindow(a, config, resources)
@@ -58,9 +59,9 @@ func main() {
5859
go func() {
5960
if *isGenResource {
6061
utils.LogMessage("Generating metadata for server...")
61-
workers.RunGenSourceSequence(config, resources, ".", *resourcesPath, mw.UpdateProgress, mw.HandleError, *isServiceModrinth)
62+
workers.RunGenSourceSequence(config, resources, *baseDir, *resourcesPath, mw.UpdateProgress, mw.HandleError, *isServiceModrinth)
6263
} else {
63-
workers.RunUpdateSequence(config, resources, ".", mw.UpdateProgress, mw.HandleError)
64+
workers.RunUpdateSequence(config, resources, *baseDir, *resourcesPath, mw.UpdateProgress, mw.HandleError)
6465
}
6566
}()
6667

internal/gui/gui.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ func NewMainWindow(a fyne.App, config *parsers.Config, resources *parsers.Resour
134134
utils.LogMessage("You may close this window to continue launching your game.")
135135
}
136136

137-
creditLeft := canvas.NewText("CargoDrop ver.1.0 (build abcd1234)", color.White)
137+
creditLeft := canvas.NewText(utils.GetFullVersionString(), color.White)
138138
creditLeft.TextSize = 12
139139
creditRight := canvas.NewText("Made with ❤️ by Cosmic Lab Studio", color.White)
140140
creditRight.TextSize = 12

internal/parsers/resource.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,16 @@ type Resource struct {
1212
URL string `json:"url"`
1313
}
1414

15+
type Patches struct {
16+
Version string `json:"version"`
17+
URL string `json:"url"`
18+
}
19+
1520
type ResourceSet struct {
1621
Name string `json:"name"`
1722
LocalVersion string `json:"version"`
1823
ResourceSetHash string `json:"resource_set_hash"`
24+
Patches []Patches `json:"patches"`
1925
Resources []Resource `json:"resources"`
2026
}
2127

internal/utils/version.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package utils
2+
3+
const (
4+
Version = "1.0"
5+
)
6+
7+
// BuildHash can be set at build time using ldflags
8+
// Example: go build -ldflags "-X github.com/cosmiclabstudio/cargodrop/internal/utils.BuildHash=$(git rev-parse --short HEAD)"
9+
var BuildHash = "dev"
10+
11+
// GetFullVersionString returns the version with build hash for GUI display
12+
func GetFullVersionString() string {
13+
return "CargoDrop ver." + Version + " (build " + BuildHash + ")"
14+
}

internal/workers/gensource.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515

1616
func RunGenSourceSequence(config *parsers.Config, resources *parsers.ResourceSet, baseDir string, resourcesPath string, progressCb func(fileName string, downloadedBytes, totalBytes int64, processed, total int), errorCb func(string, error), isServiceModrinth bool) {
1717
// some introduction
18-
utils.LogRaw("Cargodrop ver.1.0 by Cosmic Lab Studio")
18+
utils.LogRaw(utils.GetFullVersionString())
1919
utils.LogRaw("By using this software, you agree to the Terms of Conditions and the License of this program.")
2020
utils.LogRaw("Read more at: https://github.com/cosmiclabstudio/cargodrop") // TODO: Replace this link
2121

internal/workers/sequencer.go

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ import (
1111
)
1212

1313
// RunUpdateSequence sequence for the app to start updating stuff
14-
func RunUpdateSequence(config *parsers.Config, resources *parsers.ResourceSet, baseDir string, progressCb func(fileName string, downloadedBytes, totalBytes int64, processed, total int), errorCb func(string, error)) {
14+
func RunUpdateSequence(config *parsers.Config, resources *parsers.ResourceSet, baseDir string, resourcePath string, progressCb func(fileName string, downloadedBytes, totalBytes int64, processed, total int), errorCb func(string, error)) {
1515
// some introduction
16-
utils.LogRaw("Cargodrop ver.1.0 by Cosmic Lab Studio")
16+
utils.LogRaw(utils.GetFullVersionString())
1717
utils.LogRaw("By using this software, you agree to the Terms of Conditions and the License of this program.")
1818
utils.LogRaw("Read more at: https://github.com/cosmiclabstudio/cargodrop") // TODO: Replace this link
1919

@@ -24,8 +24,7 @@ func RunUpdateSequence(config *parsers.Config, resources *parsers.ResourceSet, b
2424
// Download resources.json from server
2525
utils.LogMessage("Checking for updates...")
2626

27-
resourcesPath := filepath.Join(baseDir, "resources.json")
28-
err := DownloadFile(config.UpdateServer, resourcesPath, "cargodrop.json", 0, func(fileName string, downloadedBytes, totalBytes int64) {
27+
err := DownloadFile(config.UpdateServer, resourcePath, "resources.json", 0, func(fileName string, downloadedBytes, totalBytes int64) {
2928
// callback
3029
})
3130
if err != nil {
@@ -35,7 +34,7 @@ func RunUpdateSequence(config *parsers.Config, resources *parsers.ResourceSet, b
3534
}
3635

3736
// Parse the downloaded resources.json file
38-
remoteSet, err := parsers.LoadResource(resourcesPath)
37+
remoteSet, err := parsers.LoadResource(resourcePath)
3938
if err != nil {
4039
utils.LogError(err)
4140
errorCb("Failed to parse remote resources file.", err)

0 commit comments

Comments
 (0)