Skip to content

Commit

Permalink
fix: fix cicd build project
Browse files Browse the repository at this point in the history
  • Loading branch information
cubxxw committed Mar 16, 2024
1 parent 95da5c4 commit 065a723
Show file tree
Hide file tree
Showing 6 changed files with 90 additions and 16 deletions.
3 changes: 1 addition & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,5 @@ FROM alpine:latest
WORKDIR /app

COPY --from=builder /build/_output/bin/platforms/linux/amd64/cld .
COPY --from=builder /build/config.yaml .

ENTRYPOINT ["./cld", "-config", "config.yaml"]
ENTRYPOINT ["./cld"]
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,53 @@
# comment-lang-detector

A GitHub Action for detecting specified languages (e.g., Chinese or Japanese) in comments within code files across multiple programming languages (YAML, Go, Java, Rust). Ideal for projects aiming to adhere to internationalization standards or maintain language-specific coding guidelines.

## Use





## Configuration Strategy for Code Language Detector

The Code Language Detector (CLD) Action offers a flexible approach to configuration, allowing users to specify the path to their configuration file in several ways. This ensures ease of use and adaptability to various workflows. Below is the hierarchy in which the CLD Action searches for the configuration file:

1. **Command-Line Argument**:
- The Action first checks if the configuration file path is provided as a command-line argument (`--config`). This method is ideal for users who wish to specify a custom configuration path directly in their workflow file.

```yaml
steps:
- name: Detect specified languages in comments
uses: kubecub/comment-lang-detector@v1
with:
args: --config path/to/your/config.yaml
```
2. **Environment Variable**:
- If the configuration file path is not specified as a command-line argument, the Action then looks for an environment variable named `CLD_CONFIG_PATH`. This method provides a flexible way to set the configuration path without modifying the workflow file.

```yaml
steps:
- name: Detect specified languages in comments
uses: kubecub/comment-lang-detector@v1
env:
CLD_CONFIG_PATH: path/to/your/config.yaml
```

3. **Default Configuration Paths**:
- In the absence of both a command-line argument and an environment variable, the Action attempts to locate the configuration file at default paths:
- `config.yaml`: The root directory of the repository.
- `.github/code-language-detector.yml`: Inside the `.github` folder, allowing for a clean repository structure.

The Action will search for these files in the specified order. If `config.yaml` is found, it will be used; if not, the Action will look for `.github/code-language-detector.yml`.

4. **Error on Missing Configuration**:
- If the Action cannot locate a configuration file through any of the aforementioned methods, it will terminate with an error message. This ensures that the Action only runs when it is properly configured, preventing unexpected behavior.

### Important Notes

- **Configuration File Format**: The configuration file must be in YAML format. Ensure that your configuration adheres to the required schema, which includes the languages and programming languages to be detected, among other settings.

- **Customizing the Configuration Path**: We recommend using the command-line argument or environment variable methods for specifying the configuration path when you have multiple workflows or need to adhere to different coding standards across projects.

This configuration strategy is designed to maximize flexibility and ease of use, ensuring that users can integrate the CLD Action into their workflows efficiently and effectively.
40 changes: 28 additions & 12 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ package config

import (
"flag"
"log"
"fmt"
"os"

"gopkg.in/yaml.v2"
Expand All @@ -30,20 +30,36 @@ type Config struct {

func ParseConfig() (Config, error) {
var configPath string
flag.StringVar(&configPath, "config", "./", "Path to config file")
flag.StringVar(&configPath, "config", "", "Path to config file")
flag.Parse()

var config Config
if configPath != "" {
configFile, err := os.ReadFile(configPath)
if err != nil {
return Config{}, err
}
if err := yaml.Unmarshal(configFile, &config); err != nil {
return Config{}, err
if configPath == "" {
configPath = os.Getenv("CLD_CONFIG_PATH")
}

if configPath == "" {
defaultPaths := []string{"config.yaml", ".github/code-language-detector.yml"}
for _, path := range defaultPaths {
if _, err := os.Stat(path); err == nil {
configPath = path
break
}
}
} else {
log.Fatal("Config file must be provided")
}

if configPath == "" {
return Config{}, fmt.Errorf("config file not found")
}

configFile, err := os.ReadFile(configPath)
if err != nil {
return Config{}, err
}

var config Config
if err := yaml.Unmarshal(configFile, &config); err != nil {
return Config{}, err
}

return config, nil
}
2 changes: 1 addition & 1 deletion deploy/cld/Dockerfile.cld
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@ RUN cd /app; go build -o _output/bin/cld cmd/cld/main.go

FROM scratch
COPY --from=builder /app/_output/bin/cld /app
ENTRYPOINT ["/app/cld --help"]
ENTRYPOINT ["/app/cld"]
7 changes: 6 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,9 @@ module github.com/kubecub/comment-lang-detector

go 1.19

require gopkg.in/yaml.v2 v2.4.0
require (
github.com/bugsnag/bugsnag-go v2.3.0+incompatible
gopkg.in/yaml.v2 v2.4.0
)

require github.com/pkg/errors v0.9.1 // indirect
4 changes: 4 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
github.com/bugsnag/bugsnag-go v2.3.0+incompatible h1:NobKC6g8bl3hbZ0XHSfb/Y9Ut4ynhJMh0uEhHaLingU=
github.com/bugsnag/bugsnag-go v2.3.0+incompatible/go.mod h1:2oa8nejYd4cQ/b0hMIopN0lCRxU0bueqREvZLWFrtK8=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/yaml.v2 v2.4.0 h1:D8xgwECY7CYvx+Y2n4sBz93Jn9JRvxdiyyo8CTfuKaY=
Expand Down

0 comments on commit 065a723

Please sign in to comment.