diff --git a/.github/workflows/string-parser.yml b/.github/workflows/string-parser.yml index 68ae37a..5bc4f76 100644 --- a/.github/workflows/string-parser.yml +++ b/.github/workflows/string-parser.yml @@ -4,8 +4,31 @@ on: workflow_dispatch: jobs: - main: + parse-string: runs-on: ubuntu-latest + steps: - - name: Thank you - uses: Team-B1ND/string-parser@main \ No newline at end of file + - name: Checkout code + uses: actions/checkout@v3 + + - name: Set up Node.js + uses: actions/setup-node@v3 + with: + node-version: 16 + + - name: Install dependencies + run: npm install + + - name: Run string parser + run: node index.js + env: + body: " +릴리즈 노트 작성 + +릴리즈 노트 작성" + split: "" + splitIndex: 0 + envName: TEST + + - name: Output result + run: echo "Parsed result: ${{ env.TEST }}" \ No newline at end of file diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..f79d789 --- /dev/null +++ b/.gitignore @@ -0,0 +1,94 @@ +__tests__/runner/* + +node_modules/ + +.idea/ + +# Rest pulled from https://github.com/github/gitignore/blob/master/Node.gitignore +# Logs +logs +*.log +npm-debug.log* +yarn-debug.log* +yarn-error.log* +lerna-debug.log* + +# Diagnostic reports (https://nodejs.org/api/report.html) +report.[0-9]*.[0-9]*.[0-9]*.[0-9]*.json + +# Runtime data +pids +*.pid +*.seed +*.pid.lock + +# Directory for instrumented libs generated by jscoverage/JSCover +lib-cov + +# Coverage directory used by tools like istanbul +coverage +*.lcov + +# nyc test coverage +.nyc_output + +# Grunt intermediate storage (https://gruntjs.com/creating-plugins#storing-task-files) +.grunt + +# Bower dependency directory (https://bower.io/) +bower_components + +# node-waf configuration +.lock-wscript + +# Compiled binary addons (https://nodejs.org/api/addons.html) +build/Release + +# Dependency directories +jspm_packages/ + +# TypeScript v1 declaration files +typings/ + +# TypeScript cache +*.tsbuildinfo + +# Optional npm cache directory +.npm + +# Optional eslint cache +.eslintcache + +# Optional REPL history +.node_repl_history + +# Output of 'npm pack' +*.tgz + +# Yarn Integrity file +.yarn-integrity + +# dotenv environment variables file +.env +.env.test + +# parcel-bundler cache (https://parceljs.org/) +.cache + +# next.js build output +.next + +# nuxt.js build output +.nuxt + +# vuepress build output +.vuepress/dist + +# Serverless directories +.serverless/ + +# FuseBox cache +.fusebox/ + +# DynamoDB Local files +.dynamodb/ \ No newline at end of file diff --git a/index.js b/index.js index 02525d0..708d16c 100644 --- a/index.js +++ b/index.js @@ -1 +1,41 @@ -console.log("test"); \ No newline at end of file +const core = require('@actions/core'); + +try { + // `body`, `splitStr`, `splitIndex`, `replaceBefore`, `replaceAfter`, `envName` 입력값 가져오기 + const body = core.getInput('body', { required: true }); + const splitStr = core.getInput('split', { required: false }); + const splitIndex = splitStr ? parseInt(core.getInput('splitIndex', { required: true }), 10) : null; + const replaceBefore = core.getInput('replaceBefore', { required: false }); + const replaceAfter = core.getInput('replaceAfter', { required: false }); + const envName = core.getInput('envName', { required: true }); + + // splitStr이 있는 경우, splitIndex가 존재해야 함 + if (splitStr && splitIndex === null) { + throw new Error('splitStr이 주어졌을 경우, splitIndex도 필수입니다.'); + } + + // 문자열 처리 + let result = body; + + // split 처리 + if (splitStr) { + const splitResult = result.split(splitStr); + if (splitIndex >= splitResult.length || splitIndex < 0) { + throw new Error(`Invalid splitIndex: ${splitIndex}. It should be between 0 and ${splitResult.length - 1}.`); + } + result = splitResult[splitIndex]; + } + + // replaceBefore 및 replaceAfter 처리 + if (replaceBefore && replaceAfter) { + const regex = new RegExp(replaceBefore, 'g'); + result = result.replace(regex, replaceAfter); + } + + // 결과를 `GITHUB_ENV`에 저장 + core.exportVariable(envName, result); + + console.log(`Parsed Result: ${result}`); +} catch (error) { + core.setFailed(`Error: ${error.message}`); +} diff --git a/package-lock.json b/package-lock.json new file mode 100644 index 0000000..52c61ce --- /dev/null +++ b/package-lock.json @@ -0,0 +1,81 @@ +{ + "name": "string-parser", + "version": "1.0.0", + "lockfileVersion": 3, + "requires": true, + "packages": { + "": { + "name": "string-parser", + "version": "1.0.0", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.11.1" + } + }, + "node_modules/@actions/core": { + "version": "1.11.1", + "resolved": "https://registry.npmjs.org/@actions/core/-/core-1.11.1.tgz", + "integrity": "sha512-hXJCSrkwfA46Vd9Z3q4cpEpHB1rL5NG04+/rbqW9d3+CSvtB1tYe8UTpAlixa1vj0m/ULglfEK2UKxMGxCxv5A==", + "license": "MIT", + "dependencies": { + "@actions/exec": "^1.1.1", + "@actions/http-client": "^2.0.1" + } + }, + "node_modules/@actions/exec": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@actions/exec/-/exec-1.1.1.tgz", + "integrity": "sha512-+sCcHHbVdk93a0XT19ECtO/gIXoxvdsgQLzb2fE2/5sIZmWQuluYyjPQtrtTHdU1YzTZ7bAPN4sITq2xi1679w==", + "license": "MIT", + "dependencies": { + "@actions/io": "^1.0.1" + } + }, + "node_modules/@actions/http-client": { + "version": "2.2.3", + "resolved": "https://registry.npmjs.org/@actions/http-client/-/http-client-2.2.3.tgz", + "integrity": "sha512-mx8hyJi/hjFvbPokCg4uRd4ZX78t+YyRPtnKWwIl+RzNaVuFpQHfmlGVfsKEJN8LwTCvL+DfVgAM04XaHkm6bA==", + "license": "MIT", + "dependencies": { + "tunnel": "^0.0.6", + "undici": "^5.25.4" + } + }, + "node_modules/@actions/io": { + "version": "1.1.3", + "resolved": "https://registry.npmjs.org/@actions/io/-/io-1.1.3.tgz", + "integrity": "sha512-wi9JjgKLYS7U/z8PPbco+PvTb/nRWjeoFlJ1Qer83k/3C5PHQi28hiVdeE2kHXmIL99mQFawx8qt/JPjZilJ8Q==", + "license": "MIT" + }, + "node_modules/@fastify/busboy": { + "version": "2.1.1", + "resolved": "https://registry.npmjs.org/@fastify/busboy/-/busboy-2.1.1.tgz", + "integrity": "sha512-vBZP4NlzfOlerQTnba4aqZoMhE/a9HY7HRqoOPaETQcSQuWEIyZMHGfVu6w9wGtGK5fED5qRs2DteVCjOH60sA==", + "license": "MIT", + "engines": { + "node": ">=14" + } + }, + "node_modules/tunnel": { + "version": "0.0.6", + "resolved": "https://registry.npmjs.org/tunnel/-/tunnel-0.0.6.tgz", + "integrity": "sha512-1h/Lnq9yajKY2PEbBadPXj3VxsDDu844OnaAo52UVmIzIvwwtBPIuNvkjuzBlTWpfJyUbG3ez0KSBibQkj4ojg==", + "license": "MIT", + "engines": { + "node": ">=0.6.11 <=0.7.0 || >=0.7.3" + } + }, + "node_modules/undici": { + "version": "5.28.4", + "resolved": "https://registry.npmjs.org/undici/-/undici-5.28.4.tgz", + "integrity": "sha512-72RFADWFqKmUb2hmmvNODKL3p9hcB6Gt2DOQMis1SEBaV6a4MH8soBvzg+95CYhCKPFedut2JY9bMfrDl9D23g==", + "license": "MIT", + "dependencies": { + "@fastify/busboy": "^2.0.0" + }, + "engines": { + "node": ">=14.0" + } + } + } +} diff --git a/package.json b/package.json new file mode 100644 index 0000000..15a8705 --- /dev/null +++ b/package.json @@ -0,0 +1,15 @@ +{ + "name": "string-parser", + "version": "1.0.0", + "description": "", + "main": "index.js", + "scripts": { + "test": "echo \"Error: no test specified\" && exit 1" + }, + "keywords": [], + "author": "", + "license": "ISC", + "dependencies": { + "@actions/core": "^1.11.1" + } +}