Add branch conditions to create a PR #2
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: CreatePR | ||
|
Check failure on line 1 in .github/workflows/createpr.yml
|
||
| on: | ||
| workflow_call: | ||
| env: | ||
| CONDITION: ${{ (github.ref != 'refs/heads/master') && \ | ||
| (github.ref != 'refs/heads/develop') && \ | ||
| (github.ref != 'refs/heads/developv2') && \ | ||
| (github.ref != 'refs/heads/pdfxfa-master') && \ | ||
| (github.ref != 'refs/heads/pdfxfa-develop') && \ | ||
| (! startsWith(github.ref, 'refs/heads/rebased/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/no-rebased/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/archive/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/android/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/7.1/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/7.2/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/7.3/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/8.0/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/autoport-')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/autoport/')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/release_branch')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/after_release')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/master-rc')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/test-release')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/test-after-release')) && \ | ||
| (! startsWith(github.ref, 'refs/heads/internal-master-rc')) }} | ||
| jobs: | ||
| create_pr: | ||
| runs-on: ubuntu-latest | ||
| continue-on-error: true | ||
| outputs: | ||
| email: ${{ steps.get-email.outputs.email }} | ||
| prid: ${{ steps.open-pull-request.outputs.prid }} | ||
| failure: ${{ steps.failure_handling.outputs.failure }} | ||
| steps: | ||
| - name: Logging | ||
| run: | | ||
| echo "github.ref: ${{ github.ref }}" | ||
| - name: Get email | ||
| id: get-email | ||
| if: $CONDITION | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
| run: | | ||
| EMAIL=$(curl --request GET --url "https://api.github.com/users/${{ github.event.sender.login }}" --header "Accept: application/vnd.github+json" --header "X-GitHub-Api-Version: 2022-11-28" --header "Authorization: Bearer $GITHUB_TOKEN" --silent | jq '.email') | ||
| echo "email=$EMAIL" >> $GITHUB_OUTPUT | ||
| - name: Open pull request | ||
| id: open-pull-request | ||
| if: $CONDITION | ||
| env: | ||
| GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} | ||
| run: | | ||
| PRID=$(curl --request POST --url "https://api.github.com/repos/${{ github.repository }}/pulls" \ | ||
| --header "Accept: application/vnd.github+json" \ | ||
| --header "X-GitHub-Api-Version: 2022-11-28" \ | ||
| --header "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| --data "{\"title\": \"Pull Request to create/update rebased branch for '${{ github.ref }}'\", \"body\": \"Programmatically created Pull Request to automatically keep merge branch to develop up-to-date\", \"head\": \"${{ github.ref }}\", \"base\": \"develop\"}" \ | ||
| --silent | jq '.number') | ||
| curl --request POST --url "https://api.github.com/repos/${{ github.repository }}/issues/${PRID}/assignees" \ | ||
| --header "Accept: application/vnd.github+json" \ | ||
| --header "X-GitHub-Api-Version: 2022-11-28" \ | ||
| --header "Authorization: Bearer $GITHUB_TOKEN" \ | ||
| --data "{\"assignees\":[\"${{ github.event.sender.login }}\"]}" \ | ||
| --silent | ||
| echo "prid=$PRID" >> $GITHUB_OUTPUT | ||
| - name: Failure handling | ||
| if: failure() | ||
| id: failure_handling | ||
| run: | | ||
| FAILURE=${{ true }} | ||
| echo "failure=$FAILURE" >> $GITHUB_OUTPUT | ||
| notification_success: | ||
| needs: [create_pr] | ||
| if: ($CONDITION) && (! needs.create_pr.outputs.failure) | ||
| uses: ./.github/workflows/sendslackmsgtopusher.yml | ||
| secrets: inherit | ||
| with: | ||
| emailslackuser: ${{ needs.create_pr.outputs.email }} | ||
| shortmsg: "Pull request created for '${{ github.ref }}'!" | ||
| blocks: "[{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"Pull request created for '${{ github.ref }}': https://github.com/${{ github.repository }}/pull/${{ needs.create_pr.outputs.prid }}\"}}]" | ||
| notification_failure: | ||
| needs: [create_pr] | ||
| if: ($CONDITION) && (needs.create_pr.outputs.failure) | ||
| uses: ./.github/workflows/sendslackmsgtopusher.yml | ||
| secrets: inherit | ||
| with: | ||
| emailslackuser: ${{ needs.create_pr.outputs.email }} | ||
| shortmsg: "No pull request created for '${{ github.ref }}'!" | ||
| blocks: "[{\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \":alert-beam: No pull request created in '${{ github.server_url }}/${{ github.repository }}':\"}}, {\"type\": \"section\", \"text\": {\"type\": \"mrkdwn\", \"text\": \"Check if '${{ github.ref }}' has changes compared to 'develop' & push again\"}}]" | ||