Skip to content

Commit e5d64fd

Browse files
committed
added package to handle distribution of action
1 parent 42f2c29 commit e5d64fd

File tree

5 files changed

+45
-19
lines changed

5 files changed

+45
-19
lines changed

.github/workflows/action.yml renamed to .github/WORKFLOWS/solution.yaml

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ on:
77
jobs:
88
build:
99
runs-on: ubuntu-latest
10-
10+
1111
steps:
1212
- uses: actions/checkout@v2
1313
- name: Setup node
@@ -17,16 +17,16 @@ jobs:
1717
- uses: actions/checkout@v2
1818
with:
1919
ref: ${{ github.head_ref }}
20-
20+
2121
# Runs a single command using the runners shell
22-
- name: Run the downloader script
22+
- name: Run the fetching script
23+
uses : ./
2324
run: |
2425
cd .github/src/
25-
echo ${{ secrets.COOKIE_SECRET }}
26-
npm install --save
26+
npm install --save
2727
node app.js
28-
env :
29-
COOKIE_SECRET : ${{secrets.COOKIE_SECRET}}
28+
env :
29+
COOKIE_SECRET : ${{secrets.COOKIE_SECRET}}
3030
- name: pushing the changes!!
3131
uses: stefanzweifel/git-auto-commit-action@v4
3232
with:

.github/src/SolutionDetails.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
const fs = require("fs")
22

33
const util = require("util")
4-
4+
const core = require("@actions/core")
55
const readFileDir = util.promisify(fs.readdir)
66
const codeWrite = util.promisify(fs.writeFile)
77

8+
const SOLUTION_LOCATION = core.getInput('solution_location') // relative to root directory default is root directory
89

910
function SolutionDetails({id, lang , runtime, memory, code, title_slug})
1011
{
@@ -31,7 +32,7 @@ SolutionDetails.prototype.fmtHdl = async function(){
3132

3233
SolutionDetails.prototype._fileWriteHdl = async function() {
3334
try {
34-
await codeWrite(`../../${this.id}_${this.title_slug}.${this.ext}`,this.fmtData)
35+
await codeWrite(`${SOLUTION_LOCATION}/${this.id}_${this.title_slug}.${this.ext}`,this.fmtData)
3536
console.log("file written")
3637
}
3738
catch(er)

.github/src/app.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,22 @@ const path = require("path")
33
require("dotenv").config()
44

55
const axios = require("axios").default
6-
76
const fs = require("fs")
8-
97
const util = require("util")
8+
const {Worker , workerData } = require("worker_threads")
9+
const core = require("@actions/core")
10+
1011

1112
const INTERVAL = 3000;
12-
const {Worker , workerData } = require("worker_threads")
1313

1414
const URL = "https://leetcode.com/api/submissions/"
1515
const PROBLEM_URL = "https://leetcode.com/api/problems/all"
1616

1717
const all_problems = require("./problemstat.json");
1818

19-
const cookieVal = process.env.COOKIE_SECRET ;
19+
const cookieVal = core.getInput('cookieVal')
20+
const SOLUTION_LOCATION = core.getInput('solution_location')
21+
2022

2123
if(cookieVal === null || cookieVal === undefined || cookieVal.length === 0)
2224
{
@@ -32,7 +34,7 @@ let aldyPresentSol = {}
3234

3335
function mapFileWithId(){
3436
return new Promise( async (resolve , reject ) => {
35-
const subPresent = await readFileDir("../../") ;
37+
const subPresent = await readFileDir(`${SOLUTION_LOCATION}`) ;
3638
subPresent.map(val => {
3739
if(val.indexOf("_") >= 0)
3840
{
@@ -57,7 +59,6 @@ SolutionDetails.prototype.IsPresent = function(){
5759

5860
const worker = new Worker('./worker.js' )
5961

60-
6162
worker.on('message', ()=>{
6263
console.log("done writing")
6364
})
@@ -83,13 +84,12 @@ let solutionPromise = (question) => new Promise((resolve, reject) => {
8384
}
8485
})
8586
.then(async (res)=>{
86-
//console.log(res.data)
87-
console.log(res, "reaching herre")
8887
worker.postMessage({workerData : res.data} )
8988
resolve()
9089
})
9190
.catch(err => {
9291
console.log("err",err.message)
92+
core.error('there is something wrong in here!')
9393
})
9494
.then(()=>{
9595
clearTimeout(sleep)
@@ -111,12 +111,12 @@ async function OneTimeFetch(){
111111
}
112112
catch(err)
113113
{
114+
core.error("there was something that goes wrong!")
114115
process.exit(err) ;
115116
}
116117
}
117118

118119
async function DailyFetch (){
119-
console.log("is it running")
120120
try {
121121
const r_recentSubmittedSols = await axios({
122122
method : 'GET',
@@ -128,11 +128,11 @@ async function DailyFetch (){
128128

129129
const bVal = r_recentSubmittedSols.data.submissions_dump;
130130
await FileWriteHdl(bVal)
131-
console.log("reachign here")
132131
process.exit()
133132
} catch (err)
134133
{
135134
console.log(err.message )
135+
core.error("there was something that goes wrong!")
136136
process.exit(err);
137137
}
138138
}

.github/src/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
"author": "",
1111
"license": "ISC",
1212
"dependencies": {
13+
"@actions/core": "^1.5.0",
1314
"axios": "^0.21.1",
1415
"dotenv": "^10.0.0"
1516
}

action.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
name: "LeetCode-collectinator"
2+
author: "Tarun Sharma (Me-On1)"
3+
4+
description: "Sync your leetcode solutions with your github repo"
5+
6+
inputs:
7+
cookieVal
8+
description : "leetcode cookie value to get your data value"
9+
required : true
10+
repo_location :
11+
description : "location of repo where solutions would be stored"
12+
required : false
13+
solution_location
14+
description : "location of folder in repo where solution will be stored"
15+
required : false
16+
default : '.'
17+
18+
runs:
19+
using: 'node14'
20+
main: './.github/src/app.js'
21+
22+
branding
23+
icon: 'git-commit'
24+
color : 'purple'

0 commit comments

Comments
 (0)