From ad450f829ea13afb4e9dda5df686d95f1b050634 Mon Sep 17 00:00:00 2001 From: ashing Date: Thu, 25 Jan 2024 23:36:12 +0800 Subject: [PATCH 1/5] feat: add leetcode today Signed-off-by: ashing --- .github/workflows/today.yaml | 57 ++++++++++++++++++++++++++++++++++++ go.mod | 11 +++++-- 2 files changed, 66 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/today.yaml diff --git a/.github/workflows/today.yaml b/.github/workflows/today.yaml new file mode 100644 index 0000000..1b8809e --- /dev/null +++ b/.github/workflows/today.yaml @@ -0,0 +1,57 @@ +name: "leetcode-question-today" + +on: + pull_request: + branches: + - main + schedule: + - cron: "0 2 * * *" # 2 + 8 = 10 北京时间上午 10 点 + workflow_dispatch: + +jobs: + today: + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v2 + with: + fetch-depth: 0 + + - name: Checkout External Go Repo + uses: actions/checkout@v2 + with: + repository: 'cloud-org/leetcode-question-today' + path: 'today' + + - name: Set up Go + uses: actions/setup-go@v2 + with: + go-version: 1.21.3 + + - name: run cmd + id: log + working-directory: ./today + run: | + go mod tidy + go build -o ./main + ./main > run.log 2>&1 + content=$(cat run.log) + echo "::set-output name=content::$content" + + - name: Parse log and create issue + uses: actions/github-script@v5 + with: + script: | + const logContent = `${{ steps.log.outputs.content }}`; + const lines = logContent.split('\n'); + const titleLine = lines.find(line => line.startsWith('Title: ')); + if (titleLine) { + const title = titleLine.replace('Title: ', ''); + const bodyLines = lines.slice(lines.indexOf(titleLine) + 1, lines.indexOf(titleLine) + 5).join('\n'); + github.rest.issues.create({ + owner: context.repo.owner, + repo: context.repo.repo, + title: title, + body: bodyLines + }); + } diff --git a/go.mod b/go.mod index 1fea736..3d4101b 100644 --- a/go.mod +++ b/go.mod @@ -1,9 +1,16 @@ module algorithm -go 1.19 +go 1.21 require ( github.com/bmizerany/assert v0.0.0-20160611221934-b7ed37b82869 - github.com/kr/pretty v0.2.1 // indirect github.com/stretchr/testify v1.6.1 ) + +require ( + github.com/davecgh/go-spew v1.1.0 // indirect + github.com/kr/pretty v0.2.1 // indirect + github.com/kr/text v0.1.0 // indirect + github.com/pmezard/go-difflib v1.0.0 // indirect + gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c // indirect +) From 0b1494225917fcc2797162a61d2db6644a89fee9 Mon Sep 17 00:00:00 2001 From: ashing Date: Thu, 25 Jan 2024 23:44:50 +0800 Subject: [PATCH 2/5] fix: r Signed-off-by: ashing --- .github/workflows/today.yaml | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/.github/workflows/today.yaml b/.github/workflows/today.yaml index 1b8809e..9433e87 100644 --- a/.github/workflows/today.yaml +++ b/.github/workflows/today.yaml @@ -29,29 +29,29 @@ jobs: go-version: 1.21.3 - name: run cmd - id: log working-directory: ./today run: | go mod tidy go build -o ./main ./main > run.log 2>&1 - content=$(cat run.log) - echo "::set-output name=content::$content" - name: Parse log and create issue uses: actions/github-script@v5 with: script: | - const logContent = `${{ steps.log.outputs.content }}`; + const fs = require('fs'); + const path = require('path'); + const logPath = path.join(process.env.GITHUB_WORKSPACE, 'today','run.log'); + const logContent = fs.readFileSync(logPath, 'utf8'); const lines = logContent.split('\n'); - const titleLine = lines.find(line => line.startsWith('Title: ')); - if (titleLine) { - const title = titleLine.replace('Title: ', ''); - const bodyLines = lines.slice(lines.indexOf(titleLine) + 1, lines.indexOf(titleLine) + 5).join('\n'); + const titleIndex = lines.findIndex(line => line.startsWith('Title: ')); + if (titleIndex !== -1) { + const title = lines[titleIndex].substring('Title: '.length); + const body = lines.slice(titleIndex + 1, titleIndex + 5).join('\n'); github.rest.issues.create({ owner: context.repo.owner, repo: context.repo.repo, title: title, - body: bodyLines + body: body }); } From 3b0929aac9988b5438d9aa908dd1949ea5cd55cb Mon Sep 17 00:00:00 2001 From: ashing Date: Thu, 25 Jan 2024 23:45:18 +0800 Subject: [PATCH 3/5] fix: err Signed-off-by: ashing --- .github/workflows/codecov.yml | 2 +- .github/workflows/go-lint.yml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/codecov.yml b/.github/workflows/codecov.yml index 7c20616..840e7c9 100644 --- a/.github/workflows/codecov.yml +++ b/.github/workflows/codecov.yml @@ -11,7 +11,7 @@ jobs: strategy: matrix: go: - - 1.19 + - 1.21.3 steps: - uses: actions/checkout@v2 diff --git a/.github/workflows/go-lint.yml b/.github/workflows/go-lint.yml index ad6a176..11bf69b 100644 --- a/.github/workflows/go-lint.yml +++ b/.github/workflows/go-lint.yml @@ -32,7 +32,7 @@ jobs: - name: Setup Go Environment uses: actions/setup-go@v1 with: - go-version: '1.19.2' + go-version: '1.21.3' - name: check gofmt run: | diffs=`gofmt -l . | wc -l` From 153c4bff75923a3278fc9b84735d330cf428841e Mon Sep 17 00:00:00 2001 From: ashing Date: Thu, 25 Jan 2024 23:50:34 +0800 Subject: [PATCH 4/5] fix: cron Signed-off-by: ashing --- .github/workflows/today.yaml | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/.github/workflows/today.yaml b/.github/workflows/today.yaml index 9433e87..241c5c2 100644 --- a/.github/workflows/today.yaml +++ b/.github/workflows/today.yaml @@ -1,11 +1,8 @@ name: "leetcode-question-today" on: - pull_request: - branches: - - main schedule: - - cron: "0 2 * * *" # 2 + 8 = 10 北京时间上午 10 点 + - cron: "0 1 * * *" # beijing 9am. workflow_dispatch: jobs: @@ -46,7 +43,7 @@ jobs: const lines = logContent.split('\n'); const titleIndex = lines.findIndex(line => line.startsWith('Title: ')); if (titleIndex !== -1) { - const title = lines[titleIndex].substring('Title: '.length); + const title = lines[titleIndex]; const body = lines.slice(titleIndex + 1, titleIndex + 5).join('\n'); github.rest.issues.create({ owner: context.repo.owner, From 535a6d3f6100aaa1ddc594d68a03629114e3a87b Mon Sep 17 00:00:00 2001 From: ashing Date: Thu, 25 Jan 2024 23:53:11 +0800 Subject: [PATCH 5/5] fix: r Signed-off-by: ashing --- .github/workflows/today.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/.github/workflows/today.yaml b/.github/workflows/today.yaml index 241c5c2..0d27966 100644 --- a/.github/workflows/today.yaml +++ b/.github/workflows/today.yaml @@ -49,6 +49,7 @@ jobs: owner: context.repo.owner, repo: context.repo.repo, title: title, - body: body + body: body, + labels: ['leetcode'] }); }