Fix YAML parsing errors and duplicate bot comments in PR workflows #11
Workflow file for this run
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: PR Auto-Tag | |
| on: | |
| pull_request: | |
| types: [opened, edited, synchronize, reopened] | |
| permissions: | |
| pull-requests: write | |
| contents: read | |
| jobs: | |
| auto-tag: | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| fetch-tags: true | |
| - name: Determine target version | |
| id: version | |
| uses: actions/github-script@v7 | |
| with: | |
| github-token: ${{ secrets.GITHUB_TOKEN }} | |
| script: | | |
| const pr = context.payload.pull_request; | |
| const title = pr.title.toLowerCase(); | |
| const labels = pr.labels.map(l => l.name); | |
| // Get latest tag | |
| let latestTag = 'v0.0.0'; | |
| try { | |
| const { data: tags } = await github.rest.repos.listTags({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| per_page: 1 | |
| }); | |
| if (tags.length > 0) { | |
| latestTag = tags[0].name; | |
| } | |
| } catch (error) { | |
| console.log('No tags found, using v0.0.0'); | |
| } | |
| // Parse version | |
| const versionMatch = latestTag.match(/v?(\d+)\.(\d+)\.(\d+)/); | |
| let [, major, minor, patch] = versionMatch || [null, 0, 0, 0]; | |
| major = parseInt(major); | |
| minor = parseInt(minor); | |
| patch = parseInt(patch); | |
| // Determine version bump | |
| let bumpType = 'patch'; | |
| let nextVersion = ''; | |
| if (labels.includes('breaking-change') || title.includes('!:')) { | |
| // Major version bump | |
| major += 1; | |
| minor = 0; | |
| patch = 0; | |
| bumpType = 'major'; | |
| } else if ( | |
| labels.includes('enhancement') || | |
| labels.includes('feature') || | |
| title.startsWith('feat:') | |
| ) { | |
| // Minor version bump | |
| minor += 1; | |
| patch = 0; | |
| bumpType = 'minor'; | |
| } else { | |
| // Patch version bump | |
| patch += 1; | |
| bumpType = 'patch'; | |
| } | |
| nextVersion = `v${major}.${minor}.${patch}`; | |
| console.log(`Current version: ${latestTag}`); | |
| console.log(`Bump type: ${bumpType}`); | |
| console.log(`Next version: ${nextVersion}`); | |
| // Add version label to PR | |
| const versionLabel = `version:${bumpType}`; | |
| await github.rest.issues.addLabels({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| labels: [versionLabel] | |
| }); | |
| // Add comment with version info | |
| const versionEmoji = bumpType === 'major' ? 'π¨' : bumpType === 'minor' ? 'β¨' : 'π§'; | |
| const majorNote = bumpType === 'major' ? 'β οΈ This is a **breaking change** - major version will be incremented.' : ''; | |
| const minorNote = bumpType === 'minor' ? 'π This adds new features - minor version will be incremented.' : ''; | |
| const patchNote = bumpType === 'patch' ? 'π This is a fix or minor improvement - patch version will be incremented.' : ''; | |
| await github.rest.issues.createComment({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: pr.number, | |
| body: `${versionEmoji} **Version Impact**\n\nThis PR will result in a **${bumpType}** version bump:\n- Current version: \`${latestTag}\`\n- Next version (if merged): \`${nextVersion}\`\n\n${majorNote}${minorNote}${patchNote}` | |
| }); | |
| return { | |
| current: latestTag, | |
| next: nextVersion, | |
| bumpType: bumpType | |
| }; |