Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create update-poetry.yml #23

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
69 changes: 69 additions & 0 deletions .github/workflows/update-poetry.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
name: Update Poetry Dependencies on Command

on:
issue_comment:
types: [created]

jobs:
update-poetry:
runs-on: ubuntu-latest
permissions:
contents: write
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Set up Python and Poetry
uses: actions/setup-python@v4
with:
python-version: '3.9'

- name: Install Poetry
run: |
curl -sSL https://install.python-poetry.org | python3 -
echo "$HOME/.local/bin" >> $GITHUB_PATH

- name: Extract Package Name if Comment is from BAEM1N
id: extract_package
uses: actions/github-script@v7
with:
script: |
const commentBody = context.payload.comment.body;
const commenter = context.payload.comment.user.login;
const issueBody = context.payload.issue.body;

// 관리자 확인
if (commenter !== "BAEM1N") {
console.log(`Unauthorized user: ${commenter}. Skipping package update.`);
return null;
}

// 코멘트를 포함하는지 확인
if (!commentBody.includes("@bot update package")) {
console.log("Command not detected. Skipping...");
return null;
}

// "Package Name"에서 패키지 이름 추출
const packageNameMatch = issueBody.match(/Package Name\s*\n\s*(\S+)/);
if (packageNameMatch) {
return packageNameMatch[1].trim();
} else {
console.log("Package Name not found.");
return null;
}

- name: Add package to pyproject.toml
if: steps.extract_package.outputs.result != ''
run: |
PACKAGE_NAME="${{ steps.extract_package.outputs.result }}"
poetry add "$PACKAGE_NAME"

- name: Commit and push changes
if: steps.extract_package.outputs.result != ''
run: |
git config --global user.name "github-actions[bot]"
git config --global user.email "github-actions[bot]@users.noreply.github.com"
git add pyproject.toml poetry.lock
git commit -m "Added ${{ steps.extract_package.outputs.result }}"
git push origin main