[BOOK-410/qa] test #145
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| name: Jira Integration | |
| on: | |
| issues: | |
| types: | |
| - opened | |
| jobs: | |
| # Job 1: 기존 Jira 이슈와 연결 (qa 라벨이 있는 경우) | |
| link-existing-jira: | |
| if: contains(github.event.issue.labels.*.name, '🛠️ qa') | |
| name: Link Existing Jira Issue | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Extract Jira Key | |
| id: extract | |
| run: | | |
| title=$(cat <<'EOF' | |
| ${{ github.event.issue.title }} | |
| EOF | |
| ) | |
| body=$(cat <<'EOF' | |
| ${{ github.event.issue.body }} | |
| EOF | |
| ) | |
| # 제목에서 먼저 Jira 키 찾기 | |
| jira_key=$(echo "$title" | grep -oP '\b[A-Z]+-\d+\b' | head -1) | |
| # 없으면 본문에서 찾기 | |
| if [ -z "$jira_key" ]; then | |
| jira_key=$(echo "$body" | grep -oP '\b[A-Z]+-\d+\b' | head -1) | |
| fi | |
| if [ -z "$jira_key" ]; then | |
| echo "❌ Jira key not found in issue title or body." | |
| echo "jira_key=" >> $GITHUB_OUTPUT | |
| else | |
| echo "✅ Found Jira key: $jira_key" | |
| echo "jira_key=$jira_key" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Stop if no Jira key | |
| if: steps.extract.outputs.jira_key == '' | |
| run: | | |
| echo "⚠️ No Jira key found. Exiting workflow." | |
| exit 0 | |
| - name: Jira Login | |
| uses: atlassian/gajira-login@v3 | |
| env: | |
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | |
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to develop | |
| run: | | |
| git fetch origin develop | |
| git checkout develop | |
| - name: Generate Branch Name | |
| id: branch | |
| run: | | |
| issue_number=${{ github.event.issue.number }} | |
| jira_key="${{ steps.extract.outputs.jira_key }}" | |
| branch_name="${jira_key}-fix/#${issue_number}" | |
| echo "branch=${branch_name}" >> $GITHUB_OUTPUT | |
| - name: Check and create branch | |
| id: create_branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # 브랜치가 이미 존재하는지 확인 | |
| if git ls-remote --heads origin "${{ steps.branch.outputs.branch }}" | grep -q "${{ steps.branch.outputs.branch }}"; then | |
| echo "⚠️ Branch already exists. Skipping creation." | |
| echo "created=false" >> $GITHUB_OUTPUT | |
| else | |
| git checkout -b "${{ steps.branch.outputs.branch }}" | |
| git push origin "${{ steps.branch.outputs.branch }}" | |
| echo "✅ Branch created successfully." | |
| echo "created=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Check if title needs update | |
| id: check_title | |
| run: | | |
| title="${{ github.event.issue.title }}" | |
| jira_key="${{ steps.extract.outputs.jira_key }}" | |
| if [[ "$title" == *"$jira_key"* ]]; then | |
| echo "skip=true" >> $GITHUB_OUTPUT | |
| echo "⚠️ Jira key already in title. Skipping update." | |
| else | |
| echo "skip=false" >> $GITHUB_OUTPUT | |
| echo "new_title=[$jira_key/$title" >> $GITHUB_OUTPUT | |
| echo "✅ Will update title." | |
| fi | |
| - name: Update issue title | |
| if: steps.check_title.outputs.skip == 'false' | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'update-issue' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| title: '${{ steps.check_title.outputs.new_title }}' | |
| - name: Add Jira link comment | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| 🧩 **Linked to Jira Issue:** [${{ steps.extract.outputs.jira_key }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.extract.outputs.jira_key }}) | |
| - name: Add branch comment | |
| if: steps.create_branch.outputs.created == 'true' | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| 🔀 **Branch Created:** `${{ steps.branch.outputs.branch }}` | |
| - name: Assign issue author | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'add-assignees' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| assignees: ${{ github.event.issue.user.login }} | |
| # Job 2: 새 Jira 이슈 생성 (qa 라벨이 없는 경우) | |
| create-new-jira: | |
| if: "!contains(github.event.issue.labels.*.name, '🛠️ qa')" | |
| name: Create New Jira Issue | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Determine Issue Type | |
| id: type | |
| run: | | |
| LABELS_JSON=$(cat <<'JSON' | |
| ${{ toJson(github.event.issue.labels) }} | |
| JSON | |
| ) | |
| label_names=$(echo "$LABELS_JSON" | jq -r '.[].name') | |
| echo "=== 라벨 목록 확인 ===" | |
| echo "$label_names" | |
| if echo "$label_names" | grep -Fxq '✨ feat'; then | |
| echo "type=feature" >> "$GITHUB_OUTPUT" | |
| echo "template=feature-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '🐞 fix'; then | |
| echo "type=fix" >> "$GITHUB_OUTPUT" | |
| echo "template=fix-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '🔨 refactor'; then | |
| echo "type=refactor" >> "$GITHUB_OUTPUT" | |
| echo "template=refactor-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '📃 docs'; then | |
| echo "type=docs" >> "$GITHUB_OUTPUT" | |
| echo "template=docs-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '⚙️ chore'; then | |
| echo "type=chore" >> "$GITHUB_OUTPUT" | |
| echo "template=setting-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '✅ test'; then | |
| echo "type=test" >> "$GITHUB_OUTPUT" | |
| echo "template=test-task.yml" >> "$GITHUB_OUTPUT" | |
| elif echo "$label_names" | grep -Fxq '🎨 style'; then | |
| echo "type=style" >> "$GITHUB_OUTPUT" | |
| echo "template=style-task.yml" >> "$GITHUB_OUTPUT" | |
| else | |
| echo "type=other" >> "$GITHUB_OUTPUT" | |
| echo "template=default.yml" >> "$GITHUB_OUTPUT" | |
| fi | |
| - name: Jira Login | |
| uses: atlassian/gajira-login@v3 | |
| env: | |
| JIRA_BASE_URL: ${{ secrets.JIRA_BASE_URL }} | |
| JIRA_API_TOKEN: ${{ secrets.JIRA_API_TOKEN }} | |
| JIRA_USER_EMAIL: ${{ secrets.JIRA_USER_EMAIL }} | |
| - name: Checkout repository | |
| uses: actions/checkout@v4 | |
| with: | |
| ref: develop | |
| - name: Parse Issue | |
| uses: stefanbuck/github-issue-parser@v3 | |
| id: issue-parser | |
| with: | |
| template-path: .github/ISSUE_TEMPLATE/${{ steps.type.outputs.template }} | |
| - name: Log Issue Parser Output | |
| run: | | |
| echo "Parent Key: ${{ steps.issue-parser.outputs.issueparser_parentKey }}" | |
| echo "Description: ${{ steps.issue-parser.outputs.issueparser_description }}" | |
| - name: Convert markdown to Jira Syntax | |
| uses: peter-evans/jira2md@v1 | |
| id: md2jira | |
| with: | |
| input-text: | | |
| ### Github Issue Link | |
| - ${{ github.event.issue.html_url }} | |
| ### 기능 설명 | |
| ${{ steps.issue-parser.outputs.issueparser_description }} | |
| ### 작업 목록 | |
| ${{ steps.issue-parser.outputs.issueparser_tasks }} | |
| ### 참고 링크 | |
| ${{ steps.issue-parser.outputs.issueparser_links }} | |
| mode: md2jira | |
| - name: Create Jira Issue | |
| id: create | |
| uses: atlassian/gajira-create@v3 | |
| with: | |
| project: BOOK | |
| issuetype: 하위 작업 | |
| summary: '${{ github.event.issue.title }}' | |
| description: '${{ steps.md2jira.outputs.output-text }}' | |
| fields: | | |
| { | |
| "parent": { | |
| "key": "${{ steps.issue-parser.outputs.issueparser_parentKey }}" | |
| } | |
| } | |
| - name: Log created issue | |
| run: | | |
| echo "✅ Jira Issue Created: ${{ steps.create.outputs.issue }}" | |
| echo "Parent: ${{ steps.issue-parser.outputs.issueparser_parentKey }}" | |
| - name: Checkout for branch creation | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Switch to develop | |
| run: | | |
| git fetch origin develop | |
| git checkout develop | |
| - name: Generate Branch Name | |
| id: branch | |
| run: | | |
| issue_number=${{ github.event.issue.number }} | |
| ticket_key="${{ steps.create.outputs.issue }}" | |
| type="${{ steps.type.outputs.type }}" | |
| branch_name="${ticket_key}-${type}/#${issue_number}" | |
| echo "branch=${branch_name}" >> $GITHUB_OUTPUT | |
| - name: Check and create branch | |
| id: create_branch | |
| run: | | |
| git config user.name "github-actions[bot]" | |
| git config user.email "github-actions[bot]@users.noreply.github.com" | |
| # 브랜치가 이미 존재하는지 확인 | |
| if git ls-remote --heads origin "${{ steps.branch.outputs.branch }}" | grep -q "${{ steps.branch.outputs.branch }}"; then | |
| echo "⚠️ Branch already exists. Skipping creation." | |
| echo "created=false" >> $GITHUB_OUTPUT | |
| else | |
| git checkout -b "${{ steps.branch.outputs.branch }}" | |
| git push origin "${{ steps.branch.outputs.branch }}" | |
| echo "✅ Branch created successfully." | |
| echo "created=true" >> $GITHUB_OUTPUT | |
| fi | |
| - name: Update issue title | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'update-issue' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| title: '[${{ steps.create.outputs.issue }}/${{ github.event.issue.title }}' | |
| - name: Add Jira issue link comment | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| 🎫 **Jira Issue Created:** [${{ steps.create.outputs.issue }}](${{ secrets.JIRA_BASE_URL }}/browse/${{ steps.create.outputs.issue }}) | |
| - name: Add branch comment | |
| if: steps.create_branch.outputs.created == 'true' | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'create-comment' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| body: | | |
| 🔀 **Branch Created:** `${{ steps.branch.outputs.branch }}` | |
| - name: Assign issue author | |
| uses: actions-cool/issues-helper@v3 | |
| with: | |
| actions: 'add-assignees' | |
| token: ${{ secrets.PAT_TOKEN }} | |
| issue-number: ${{ github.event.issue.number }} | |
| assignees: ${{ github.event.issue.user.login }} |