Skip to content

Commit

Permalink
ci: Add Logic
Browse files Browse the repository at this point in the history
  • Loading branch information
8954sood committed Nov 19, 2024
1 parent cc96721 commit 7aaf08d
Show file tree
Hide file tree
Showing 5 changed files with 257 additions and 4 deletions.
29 changes: 26 additions & 3 deletions .github/workflows/string-parser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
- 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: "<Student>
릴리즈 노트 작성
<Teacher>
릴리즈 노트 작성"
split: "<Teacher>"
splitIndex: 0
envName: TEST

- name: Output result
run: echo "Parsed result: ${{ env.TEST }}"
94 changes: 94 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -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/
42 changes: 41 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
@@ -1 +1,41 @@
console.log("test");
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}`);
}
81 changes: 81 additions & 0 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

15 changes: 15 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -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"
}
}

0 comments on commit 7aaf08d

Please sign in to comment.