|
16 | 16 | secrets: |
17 | 17 | APP_ID: ${{ secrets.APP_ID }} |
18 | 18 | AUTOMATION_KEY: ${{ secrets.AUTOMATION_KEY }} |
| 19 | + |
| 20 | + create-backport-label: |
| 21 | + needs: create-release-branch |
| 22 | + permissions: |
| 23 | + issues: write |
| 24 | + runs-on: ubuntu-latest |
| 25 | + steps: |
| 26 | + - name: Create Backport PR label if it doesn't exist |
| 27 | + uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1 |
| 28 | + with: |
| 29 | + github-token: ${{ secrets.GITHUB_TOKEN }} |
| 30 | + script: | |
| 31 | + const tagName = context.payload.release?.tag_name; |
| 32 | + if (!tagName) { |
| 33 | + console.error("❌ No tag name found in the release payload"); |
| 34 | + throw new Error("No tag name found"); |
| 35 | + } |
| 36 | + // check if it matches vX.Y.Z format or something/vX.Y.Z |
| 37 | + const tagPattern = /^([\w/-_]+\/)?v\d+\.\d+\.\d+$/; |
| 38 | + if (!tagPattern.test(tagName)) { |
| 39 | + console.error(`❌ Tag name "${tagName}" does not match expected format`); |
| 40 | + throw new Error("Invalid tag name format"); |
| 41 | + } |
| 42 | + const labelPrefix = "backport release/"; |
| 43 | + // Extract the label name by removing patch version |
| 44 | + let labelName; |
| 45 | + if (tagName && tagName.includes('.')) { |
| 46 | + const lastDotIndex = tagName.lastIndexOf('.'); |
| 47 | + labelName = `${labelPrefix}${tagName.substring(0, lastDotIndex)}`; |
| 48 | + } else { |
| 49 | + labelName = `${labelPrefix}${tagName}`; |
| 50 | + } |
| 51 | +
|
| 52 | + const labelColor = "731ddb"; // purple |
| 53 | + const labelDescription = "Backport PR to release " + tagName; |
| 54 | +
|
| 55 | + try { |
| 56 | + // Check if label already exists |
| 57 | + await github.rest.issues.getLabel({ |
| 58 | + owner: context.repo.owner, |
| 59 | + repo: context.repo.repo, |
| 60 | + name: labelName, |
| 61 | + }); |
| 62 | + console.log(`✅ Label "${labelName}" already exists`); |
| 63 | + } catch (error) { |
| 64 | + if (error.status === 404) { |
| 65 | + console.log(`🏷️ Creating label "${labelName}"`); |
| 66 | + try { |
| 67 | + await github.rest.issues.createLabel({ |
| 68 | + owner: context.repo.owner, |
| 69 | + repo: context.repo.repo, |
| 70 | + name: labelName, |
| 71 | + color: labelColor, |
| 72 | + description: labelDescription, |
| 73 | + }); |
| 74 | + console.log(`✅ Label "${labelName}" created`); |
| 75 | + } catch (createError) { |
| 76 | + console.error(`❌ Error creating label "${labelName}":`, createError); |
| 77 | + throw createError; |
| 78 | + } |
| 79 | + } else { |
| 80 | + console.error(`❌ Error getting label "${labelName}":`, error); |
| 81 | + throw error; |
| 82 | + } |
| 83 | + } |
| 84 | +
|
0 commit comments