|
| 1 | +name: 🔃 Create PRs |
| 2 | +on: |
| 3 | + workflow_dispatch: |
| 4 | + inputs: |
| 5 | + dry-run: |
| 6 | + description: 'Run the workflow without creating PRs' |
| 7 | + required: false |
| 8 | + default: false |
| 9 | + type: boolean |
| 10 | + schedule: |
| 11 | + - cron: '0 0 * * *' |
| 12 | +jobs: |
| 13 | + get-branches: |
| 14 | + outputs: |
| 15 | + branches: ${{ steps.get-branches.outputs.branches }} |
| 16 | + runs-on: ubuntu-latest |
| 17 | + steps: |
| 18 | + - name: Checkout code |
| 19 | + uses: actions/checkout@v4 |
| 20 | + with: |
| 21 | + fetch-depth: 0 |
| 22 | + - name: Get branches |
| 23 | + id: get-branches |
| 24 | + shell: pwsh |
| 25 | + run: | |
| 26 | + $branches = git branch -r --format="%(refname:short)" | ForEach-Object { $_.Trim() -replace "^origin/", "" } |
| 27 | + # filter only branches that start with dev/ |
| 28 | + $branches = $branches | Where-Object { $_ -match "^dev/" } |
| 29 | + $branchJson = ConvertTo-Json @($branches) -Compress |
| 30 | + Write-Host "branches=$branchJson" |
| 31 | + echo "branches=$branchJson" >> $env:GITHUB_OUTPUT |
| 32 | + create-pr: |
| 33 | + needs: get-branches |
| 34 | + strategy: |
| 35 | + max-parallel: 1 |
| 36 | + matrix: |
| 37 | + branch: ${{fromJson(needs.get-branches.outputs.branches)}} |
| 38 | + runs-on: ubuntu-latest |
| 39 | + steps: |
| 40 | + - name: Checkout code |
| 41 | + uses: actions/checkout@v4 |
| 42 | + with: |
| 43 | + fetch-depth: 0 |
| 44 | + - name: Set Env |
| 45 | + run: | |
| 46 | + TARGET=$(echo ${{ matrix.branch }} | sed 's/dev\///') |
| 47 | + SOURCE=${{ matrix.branch }} |
| 48 | +
|
| 49 | + if [ -z "$TARGET" ]; then |
| 50 | + echo "TARGET is empty" |
| 51 | + exit 1 |
| 52 | + fi |
| 53 | + |
| 54 | + if [ -z "$SOURCE" ]; then |
| 55 | + echo "SOURCE is empty" |
| 56 | + exit 1 |
| 57 | + fi |
| 58 | +
|
| 59 | + if [ "$SOURCE" == "$TARGET" ]; then |
| 60 | + echo "SOURCE is the same as TARGET" |
| 61 | + exit 1 |
| 62 | + fi |
| 63 | +
|
| 64 | + echo "SOURCE=$SOURCE" |
| 65 | + echo "TARGET=$TARGET" |
| 66 | + echo "SOURCE=$SOURCE" >> $GITHUB_ENV |
| 67 | + echo "TARGET=$TARGET" >> $GITHUB_ENV |
| 68 | + - name: Run the Action |
| 69 | + if: ${{ github.event.inputs.dry-run == 'false' }} |
| 70 | + uses: devops-infra/[email protected] |
| 71 | + with: |
| 72 | + github_token: ${{ secrets.GITHUB_TOKEN }} |
| 73 | + source_branch: ${{ env.SOURCE }} |
| 74 | + target_branch: ${{ env.TARGET }} |
| 75 | + title: "Merge ${{ env.SOURCE }} into ${{ env.TARGET }}" |
| 76 | + reviewer: ${{ github.repository_owner }} |
| 77 | + assignee: ${{ github.repository_owner }} |
0 commit comments