mirror of
https://gitea.com/gitea/act_runner.git
synced 2024-11-10 04:37:22 +01:00
552dbcdda9
Add copyright header Co-authored-by: sillyguodong <gedong_1994@163.com> Reviewed-on: https://gitea.com/gitea/act_runner/pulls/29 Reviewed-by: Jason Song <i@wolfogre.com> Reviewed-by: Zettat123 <zettat123@noreply.gitea.io> Co-authored-by: sillyguodong <sillyguodong@noreply.gitea.io> Co-committed-by: sillyguodong <sillyguodong@noreply.gitea.io>
38 lines
622 B
Go
38 lines
622 B
Go
// Copyright 2022 The Gitea Authors. All rights reserved.
|
|
// SPDX-License-Identifier: MIT
|
|
|
|
package main
|
|
|
|
import (
|
|
"context"
|
|
"os"
|
|
"os/signal"
|
|
"syscall"
|
|
|
|
"gitea.com/gitea/act_runner/cmd"
|
|
)
|
|
|
|
func withContextFunc(ctx context.Context, f func()) context.Context {
|
|
ctx, cancel := context.WithCancel(ctx)
|
|
go func() {
|
|
c := make(chan os.Signal, 1)
|
|
signal.Notify(c, syscall.SIGINT, syscall.SIGTERM)
|
|
defer signal.Stop(c)
|
|
|
|
select {
|
|
case <-ctx.Done():
|
|
case <-c:
|
|
cancel()
|
|
f()
|
|
}
|
|
}()
|
|
|
|
return ctx
|
|
}
|
|
|
|
func main() {
|
|
ctx := withContextFunc(context.Background(), func() {})
|
|
// run the command
|
|
cmd.Execute(ctx)
|
|
}
|