Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions .github/workflows/release.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -62,3 +62,27 @@ jobs:
env:
RUST_BACKTRACE: 1
CARGO_REGISTRY_TOKEN: ${{ secrets.CARGO_REGISTRY_TOKEN }}

release_maven:
runs-on: ubuntu-latest
if: "startsWith(github.ref, 'refs/tags/testutils/java/v')"
steps:
- uses: actions/checkout@v4
- uses: actions/setup-java@v4
with:
java-version: '11'
distribution: 'temurin'
server-id: 'central'
server-username: MAVEN_USERNAME
server-password: MAVEN_CENTRAL_TOKEN
gpg-private-key: ${{ secrets.MAVEN_GPG_PRIVATE_KEY }}
gpg-passphrase: MAVEN_GPG_PASSPHRASE

- name: Publish to Apache Maven Central
working-directory: testutils/java
env:
MAVEN_USERNAME: ${{ secrets.MAVEN_USERNAME }}
MAVEN_CENTRAL_TOKEN: ${{ secrets.MAVEN_CENTRAL_TOKEN }}
MAVEN_GPG_PASSPHRASE: ""
run:
./mvnw clean deploy -DskipTests=true
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,6 @@ go.work
go.work.sum
misc/*.gif
misc/questions.json

testutils/java/target/
testutils/java/.idea/
4 changes: 4 additions & 0 deletions .goreleaser.yaml
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
before:
hooks:
- go mod tidy
- go generate ./...
- ./scripts/completions.sh
builds:
- env:
Expand All @@ -12,6 +13,9 @@ builds:
goarch:
- amd64
- arm64
ignore:
- goos: linux
goarch: arm64
flags:
- -v
- -trimpath
Expand Down
4 changes: 4 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,7 @@ release-pypi:
release-cargo:
git tag -a $(shell svu patch --prefix 'testutils/rust/')
git push --tags

release-maven:
git tag -a $(shell svu patch --prefix 'testutils/java/')
git push --tags
10 changes: 7 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ Local testing requires more work to implement for each language, so not all lang
| Python | :white_check_mark: | :white_check_mark: |
| C++ | :white_check_mark: | :white_check_mark: |
| Rust | :white_check_mark: | :white_check_mark: |
| Java | :white_check_mark: | Not yet |
| Java | :white_check_mark: | :white_check_mark: |
| JavaScript | :white_check_mark: | Not yet |
| TypeScript | :white_check_mark: | Not yet |
| PHP | :white_check_mark: | Not yet |
Expand Down Expand Up @@ -150,7 +150,7 @@ Available Commands:

Flags:
-v, --version version for leetgo
-l, --lang string language of code to generate: cpp, go, python ...
-l, --lang string language of code to generate: cpp, go, python, java...
--site string leetcode site: cn, us
-y, --yes answer yes to all prompts
-h, --help help for leetgo
Expand Down Expand Up @@ -200,7 +200,7 @@ author: Bob
# Language of the question description: zh or en
language: zh
code:
# Language of code generated for questions: go, cpp, python, java...
# Language of code generated for questions: cpp, python, go, java...
# (will be overridden by command line flag -l/--lang)
lang: go
# The default template to generate filename (without extension), e.g. {{.Id}}.{{.Slug}}
Expand Down Expand Up @@ -234,6 +234,10 @@ code:
out_dir: rust
java:
out_dir: java
# Overrides the default code.filename_template, empty will be ignored
filename_template: p{{ .Id | padWithZero 4 }}{{ if .SlugIsMeaningful }}_{{ .Slug | lower | toUnderscore }}{{ end }}
# Maven group ID
group_id: ""
leetcode:
# LeetCode site, https://leetcode.com or https://leetcode.cn
site: https://leetcode.cn
Expand Down
10 changes: 7 additions & 3 deletions README_zh.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ func main() {
| Python | :white_check_mark: | :white_check_mark: |
| C++ | :white_check_mark: | :white_check_mark: |
| Rust | :white_check_mark: | :white_check_mark: |
| Java | :white_check_mark: | Not yet |
| Java | :white_check_mark: | :white_check_mark: |
| JavaScript | :white_check_mark: | Not yet |
| TypeScript | :white_check_mark: | Not yet |
| PHP | :white_check_mark: | Not yet |
Expand Down Expand Up @@ -148,7 +148,7 @@ Available Commands:

Flags:
-v, --version version for leetgo
-l, --lang string language of code to generate: cpp, go, python ...
-l, --lang string language of code to generate: cpp, go, python, java...
--site string leetcode site: cn, us
-y, --yes answer yes to all prompts
-h, --help help for leetgo
Expand Down Expand Up @@ -193,7 +193,7 @@ author: Bob
# Language of the question description: zh or en
language: zh
code:
# Language of code generated for questions: go, cpp, python, java...
# Language of code generated for questions: cpp, python, go, java...
# (will be overridden by command line flag -l/--lang)
lang: go
# The default template to generate filename (without extension), e.g. {{.Id}}.{{.Slug}}
Expand Down Expand Up @@ -227,6 +227,10 @@ code:
out_dir: rust
java:
out_dir: java
# Overrides the default code.filename_template, empty will be ignored
filename_template: p{{ .Id | padWithZero 4 }}{{ if .SlugIsMeaningful }}_{{ .Slug | lower | toUnderscore }}{{ end }}
# Maven group ID
group_id: ""
leetcode:
# LeetCode site, https://leetcode.com or https://leetcode.cn
site: https://leetcode.cn
Expand Down
2 changes: 1 addition & 1 deletion cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func initCommands() {
rootCmd.SetOut(os.Stdout)
rootCmd.InitDefaultVersionFlag()
rootCmd.Flags().SortFlags = false
rootCmd.PersistentFlags().StringP("lang", "l", "", "language of code to generate: cpp, go, python ...")
rootCmd.PersistentFlags().StringP("lang", "l", "", "language of code to generate: cpp, go, python, java...")
rootCmd.PersistentFlags().StringP("site", "", "", "leetcode site: cn, us")
rootCmd.PersistentFlags().BoolP("yes", "y", false, "answer yes to all prompts")
rootCmd.InitDefaultHelpFlag()
Expand Down
32 changes: 21 additions & 11 deletions config/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -70,16 +70,16 @@ type Modifier struct {
}

type CodeConfig struct {
Lang string `yaml:"lang" mapstructure:"lang" comment:"Language of code generated for questions: go, cpp, python, java... \n(will be overridden by command line flag -l/--lang)"`
FilenameTemplate string `yaml:"filename_template" mapstructure:"filename_template" comment:"The default template to generate filename (without extension), e.g. {{.Id}}.{{.Slug}}\nAvailable attributes: Id, Slug, Title, Difficulty, Lang, SlugIsMeaningful\nAvailable functions: lower, upper, trim, padWithZero, toUnderscore, group"`
SeparateDescriptionFile bool `yaml:"separate_description_file" mapstructure:"separate_description_file" comment:"Generate question description into a separate question.md file"`
Blocks []Block `yaml:"blocks,omitempty" mapstructure:"blocks" comment:"Default block definitions for all languages"`
Modifiers []Modifier `yaml:"modifiers,omitempty" mapstructure:"modifiers" comment:"Default modifiers for all languages"`
Go GoConfig `yaml:"go" mapstructure:"go"`
Python PythonConfig `yaml:"python3" mapstructure:"python3"`
Cpp CppConfig `yaml:"cpp" mapstructure:"cpp"`
Rust RustConfig `yaml:"rust" mapstructure:"rust"`
Java BaseLangConfig `yaml:"java" mapstructure:"java"`
Lang string `yaml:"lang" mapstructure:"lang" comment:"Language of code generated for questions: cpp, python, go, java... \n(will be overridden by command line flag -l/--lang)"`
FilenameTemplate string `yaml:"filename_template" mapstructure:"filename_template" comment:"The default template to generate filename (without extension), e.g. {{.Id}}.{{.Slug}}\nAvailable attributes: Id, Slug, Title, Difficulty, Lang, SlugIsMeaningful\nAvailable functions: lower, upper, trim, padWithZero, toUnderscore, group"`
SeparateDescriptionFile bool `yaml:"separate_description_file" mapstructure:"separate_description_file" comment:"Generate question description into a separate question.md file"`
Blocks []Block `yaml:"blocks,omitempty" mapstructure:"blocks" comment:"Default block definitions for all languages"`
Modifiers []Modifier `yaml:"modifiers,omitempty" mapstructure:"modifiers" comment:"Default modifiers for all languages"`
Go GoConfig `yaml:"go" mapstructure:"go"`
Python PythonConfig `yaml:"python3" mapstructure:"python3"`
Cpp CppConfig `yaml:"cpp" mapstructure:"cpp"`
Rust RustConfig `yaml:"rust" mapstructure:"rust"`
Java JavaConfig `yaml:"java" mapstructure:"java"`
// Add more languages here
}

Expand Down Expand Up @@ -110,6 +110,11 @@ type RustConfig struct {
BaseLangConfig `yaml:",inline" mapstructure:",squash"`
}

type JavaConfig struct {
BaseLangConfig `yaml:",inline" mapstructure:",squash"`
GroupID string `yaml:"group_id" mapstructure:"group_id" comment:"Maven group ID"`
}

type Credentials struct {
From string `yaml:"from" mapstructure:"from" comment:"How to provide credentials: browser, cookies, password or none"`
Browsers []string `yaml:"browsers" mapstructure:"browsers" comment:"Browsers to get cookies from: chrome, safari, edge or firefox. If empty, all browsers will be tried"`
Expand Down Expand Up @@ -219,7 +224,12 @@ func defaultConfig() *Config {
BaseLangConfig: BaseLangConfig{OutDir: "python"},
Executable: constants.DefaultPython,
},
Java: BaseLangConfig{OutDir: "java"},
Java: JavaConfig{
BaseLangConfig: BaseLangConfig{
OutDir: "java",
FilenameTemplate: `p{{ .Id | padWithZero 4 }}{{ if .SlugIsMeaningful }}_{{ .Slug | lower | toUnderscore }}{{ end }}`,
},
},
Rust: RustConfig{BaseLangConfig: BaseLangConfig{OutDir: "rust"}},
// Add more languages here
},
Expand Down
1 change: 1 addition & 0 deletions constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,5 @@ const (
GoTestUtilsModPath = "github.com/j178/leetgo/testutils/go"
RustTestUtilsCrate = "leetgo_rs"
PythonTestUtilsMode = "leetgo_py"
JavaTestUtilsGroupId = "io.github.j178"
)
12 changes: 6 additions & 6 deletions lang/cpp.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import (
"github.com/j178/leetgo/config"
"github.com/j178/leetgo/constants"
"github.com/j178/leetgo/leetcode"
cppUtils "github.com/j178/leetgo/testutils/cpp"
cppEmbed "github.com/j178/leetgo/testutils/cpp"
"github.com/j178/leetgo/utils"
)

Expand All @@ -19,21 +19,21 @@ type cpp struct {
}

func (c cpp) Initialize(outDir string) error {
headerPath := filepath.Join(outDir, cppUtils.HeaderName)
err := utils.WriteFile(headerPath, cppUtils.HeaderContent)
headerPath := filepath.Join(outDir, cppEmbed.HeaderName)
err := utils.WriteFile(headerPath, cppEmbed.HeaderContent)
if err != nil {
return err
}
stdCxxPath := filepath.Join(outDir, "bits", "stdc++.h")
err = utils.WriteFile(stdCxxPath, cppUtils.StdCxxContent)
err = utils.WriteFile(stdCxxPath, cppEmbed.StdCxxContent)
if err != nil {
return err
}
return nil
}

func (c cpp) HasInitialized(outDir string) (bool, error) {
headerPath := filepath.Join(outDir, cppUtils.HeaderName)
headerPath := filepath.Join(outDir, cppEmbed.HeaderName)
if !utils.IsExist(headerPath) {
return false, nil
}
Expand Down Expand Up @@ -278,7 +278,7 @@ func (c cpp) generateCodeFile(
#include "%s"
using namespace std;

`, cppUtils.HeaderName,
`, cppEmbed.HeaderName,
)
testContent, err := c.generateTestContent(q)
if err != nil {
Expand Down
Loading