From acc5afc4285246bbfa2357d405b46b3b5bceb78c Mon Sep 17 00:00:00 2001 From: techknowlogick Date: Mon, 24 Apr 2023 10:45:51 +0800 Subject: [PATCH] allow building act_runner with cgo (#137) for platforms not supported by moderc.org/sqlite Co-authored-by: Jason Song Reviewed-on: https://gitea.com/gitea/act_runner/pulls/137 Reviewed-by: Lunny Xiao Reviewed-by: Jason Song Co-authored-by: techknowlogick Co-committed-by: techknowlogick --- go.mod | 1 + internal/app/artifactcache/db_cgo.go | 11 +++++++++++ internal/app/artifactcache/db_nocgo.go | 11 +++++++++++ internal/app/artifactcache/handler.go | 3 +-- 4 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 internal/app/artifactcache/db_cgo.go create mode 100644 internal/app/artifactcache/db_nocgo.go diff --git a/go.mod b/go.mod index c3635a3..d32911e 100644 --- a/go.mod +++ b/go.mod @@ -12,6 +12,7 @@ require ( github.com/go-chi/render v1.0.2 github.com/joho/godotenv v1.5.1 github.com/mattn/go-isatty v0.0.17 + github.com/mattn/go-sqlite3 v1.14.9 github.com/nektos/act v0.0.0 github.com/sirupsen/logrus v1.9.0 github.com/spf13/cobra v1.6.1 diff --git a/internal/app/artifactcache/db_cgo.go b/internal/app/artifactcache/db_cgo.go new file mode 100644 index 0000000..fcaf04f --- /dev/null +++ b/internal/app/artifactcache/db_cgo.go @@ -0,0 +1,11 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build cgo +// +build cgo + +package artifactcache + +import _ "github.com/mattn/go-sqlite3" + +var sqliteDriverName = "sqlite3" diff --git a/internal/app/artifactcache/db_nocgo.go b/internal/app/artifactcache/db_nocgo.go new file mode 100644 index 0000000..ce83d85 --- /dev/null +++ b/internal/app/artifactcache/db_nocgo.go @@ -0,0 +1,11 @@ +// Copyright 2023 The Gitea Authors. All rights reserved. +// SPDX-License-Identifier: MIT + +//go:build !cgo +// +build !cgo + +package artifactcache + +import _ "modernc.org/sqlite" + +var sqliteDriverName = "sqlite" diff --git a/internal/app/artifactcache/handler.go b/internal/app/artifactcache/handler.go index 2e063fc..478b84b 100644 --- a/internal/app/artifactcache/handler.go +++ b/internal/app/artifactcache/handler.go @@ -19,7 +19,6 @@ import ( "github.com/go-chi/chi/v5/middleware" "github.com/go-chi/render" log "github.com/sirupsen/logrus" - _ "modernc.org/sqlite" "xorm.io/builder" "xorm.io/xorm" ) @@ -56,7 +55,7 @@ func StartHandler(dir, outboundIP string, port uint16) (*Handler, error) { return nil, err } - e, err := xorm.NewEngine("sqlite", filepath.Join(dir, "sqlite.db")) + e, err := xorm.NewEngine(sqliteDriverName, filepath.Join(dir, "sqlite.db")) if err != nil { return nil, err }