Create update dockerfiles PR #378
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 update dockerfiles PR | |
| on: | |
| workflow_run: | |
| workflows: [Update external base images, Update internal base images] | |
| types: completed | |
| workflow_dispatch: | |
| jobs: | |
| # ------------------------ | |
| get_branches: | |
| if: ${{ github.event.workflow_run.conclusion == 'success' }} | |
| runs-on: ubuntu-latest | |
| outputs: | |
| branches: ${{ steps.generate-matrix.outputs.branches }} | |
| steps: | |
| - name: Check out repository code | |
| uses: actions/checkout@v2 | |
| - name: Generate Matrix | |
| id: generate-matrix | |
| env: | |
| GITHUB_TOKEN: ${{secrets.CONTENT_BOT_TOKEN}} | |
| run: | | |
| echo "=== Starting autoupdate branch discovery ===" | |
| git fetch | |
| echo "Fetched latest changes from remote" | |
| branches=$(git branch -r | grep autoupdate/) | |
| echo "Found autoupdate branches:" | |
| echo "$branches" | |
| if [ -z "$branches" ]; then | |
| echo "No autoupdate branches found" | |
| SERVICES="[ ]" | |
| else | |
| echo "Processing branches for PR creation..." | |
| matrix="[ " | |
| for branch in $(echo $branches); do | |
| branch_name="${branch#origin/}" | |
| echo "Checking branch: $branch_name" | |
| exists=`gh pr list --state open -H $branch_name` | |
| if [ -z "$exists" ]; then | |
| echo " No existing PR for $branch_name - will create" | |
| matrix="${matrix} \"$branch_name\"," | |
| else | |
| echo " PR already exists for $branch_name - skipping" | |
| fi | |
| done | |
| matrix="${matrix%?}" | |
| SERVICES="${matrix} ]" | |
| fi | |
| echo "=== Branch discovery complete ===" | |
| echo "Final branches matrix: $SERVICES" | |
| echo "branches=${SERVICES}" >> $GITHUB_OUTPUT | |
| pull-request: | |
| if: ${{ needs.get_branches.outputs.branches != '[ ]' }} | |
| runs-on: ubuntu-latest | |
| needs: | |
| - get_branches | |
| strategy: | |
| max-parallel: 2 | |
| fail-fast: false | |
| matrix: | |
| branches: ${{ fromJSON(needs.get_branches.outputs.branches) }} | |
| steps: | |
| - uses: actions/checkout@v2 | |
| - name: pull-request | |
| id: open-pr | |
| uses: repo-sync/pull-request@v2 | |
| with: | |
| GITHUB_TOKEN: ${{secrets.CONTENT_BOT_TOKEN}} | |
| source_branch: "${{ matrix.branches }}" | |
| destination_branch: "" # If blank, default: master | |
| pr_title: "build(dockerfiles) update Dockerfile - ${{ matrix.branches }}" # Title of pull request | |
| pr_body: "This is automated PR to update dockerfiles base images\n${{ matrix.branches }}" | |
| - name: approve and merge | |
| env: | |
| GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | |
| PR_URL: ${{ steps.open-pr.outputs.pr_url }} | |
| if: ${{ steps.open-pr.outputs.pr_url }} | |
| run: | | |
| echo "Approving and merging" | |
| gh pr review --approve "$PR_URL" | |
| gh pr merge --auto --squash "$PR_URL" |