Create Prod Region Issues From Stage #9
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: Create Prod Region Issues From Stage | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| stage_issue_number: | |
| description: "Stage issue number to copy from" | |
| required: true | |
| region: | |
| description: "Optional: specific region (e.g. us-east). Leave empty for all regions." | |
| required: false | |
| jobs: | |
| create-prod-issues: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| issues: write | |
| steps: | |
| - name: Create prod issues | |
| uses: actions/github-script@v7 | |
| with: | |
| script: | | |
| const regions = [ | |
| "CA-MON", | |
| "AU-SYD", | |
| "BR-SAO", | |
| "CA-TOR", | |
| "JP-OSA", | |
| "JP-TOK", | |
| "US-EAST", | |
| "US-SOUTH", | |
| "IN-CHE", | |
| "EU-GB", | |
| "EU-ES", | |
| "EU-DE", | |
| "EU-FR2" | |
| ]; | |
| const stageIssueNumber = context.payload.inputs.stage_issue_number; | |
| const inputRegion = context.payload.inputs.region; | |
| const { data: stageIssue } = await github.rest.issues.get({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| issue_number: stageIssueNumber | |
| }); | |
| const baseBody = stageIssue.body || ""; | |
| const baseTitle = stageIssue.title.replace(/STAGE/i, ""); | |
| // Get current date in YYYY-MM-DD format | |
| const currentDate = new Date().toISOString().split('T')[0]; | |
| const regionsToCreate = | |
| inputRegion && inputRegion.trim() !== "" | |
| ? [inputRegion.trim()] | |
| : regions; | |
| for (const region of regionsToCreate) { | |
| // Replace the value after "Region (required):" with the actual region | |
| // Replace the value after "Deployment Date (YYYY-MM-DD):" with current date | |
| // Uncheck all checked items in the body | |
| let updatedBody = baseBody | |
| .replace(/(Region \(required\):?\s*)([^\n]*)/gi, `$1${region}`) | |
| .replace(/(Deployment Date \(YYYY-MM-DD\):?\s*)([^\n]*)/gi, `$1${currentDate}`) | |
| .replace(/\[x\]/gi, '[ ]'); | |
| await github.rest.issues.create({ | |
| owner: context.repo.owner, | |
| repo: context.repo.repo, | |
| title: `${baseTitle} ${region}`, | |
| body: updatedBody, | |
| labels: ["deployment"] | |
| }); | |
| } | |
| console.log(`Created ${regionsToCreate.length} issue(s).`); |