Skip to content

create_pr

create_pr #41

Workflow file for this run

name: Create PR with external dependency
on:
repository_dispatch:
types: [create_pr]
jobs:
build:
name: Create PR with external dependency
runs-on: ubuntu-latest
steps:
- name: Verify Event and set env
env:
BUILD_URL: ${{ github.event.client_payload.build_url }}
PR_BRANCH: ${{ github.event.client_payload.branch }}
PACKAGE: ${{ github.event.client_payload.dependency_package }}
run: |
echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_ENV
echo "BUILD_URL=$BUILD_URL" >> $GITHUB_ENV
echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV
PULL_REQUEST_GIT_USER='${{ vars.PULL_REQUEST_GIT_USER }}'
echo "GIT_USER_NAME=$(echo "$PULL_REQUEST_GIT_USER" | jq -r .name)" >> $GITHUB_ENV
echo "GIT_USER_EMAIL=$(echo "$PULL_REQUEST_GIT_USER" | jq -r .email)" >> $GITHUB_ENV
if: ${{ github.event.action == 'create_pr' && github.event.client_payload.branch && github.event.client_payload.build_url && github.event.client_payload.dependency_package }}
- uses: actions/checkout@v4
with:
fetch-depth: 0
if: ${{ env.PR_BRANCH && env.BUILD_URL }}
- name: Insert dependency
uses: Wandalen/wretry.action@master
id: manipulate_composer
with:
command: |
composer config repositories.${{ env.PACKAGE }} '{"type":"package","package":{"name":"${{ env.PACKAGE }}","version":"dev-master","type":"drupal-library","dist":{"url":"${{ env.BUILD_URL }}","type":"zip"},"require":{"composer\/installers":"^1.2.0"}}}'
composer remove ${{ env.PACKAGE }} \
&& composer require ${{ env.PACKAGE }}
attempt_limit: 200
if: ${{ env.BUILD_URL && env.PACKAGE && startsWith(env.BUILD_URL, env.ACCEPTED_BUILD_URL_PREFIX) }}
env:
ACCEPTED_BUILD_URL_PREFIX: "${{ vars.ACCEPTED_BUILD_URL_PREFIX }}"
- name: Create branch and PR
run: |
set -e
git config --global user.name ${{ env.GIT_USER_NAME }}
git config --global user.email ${{ env.GIT_USER_MAIL }}
git checkout -b ${{ env.PR_BRANCH }}
git push --set-upstream origin ${{ env.PR_BRANCH }}
git add composer.json composer.lock
git commit -m "Insert new reference to dependency ${{ env.PACKAGE }}: ${{ env.BUILD_URL }}"
git push
gh pr create --base develop --head ${{ env.PR_BRANCH }} --title "PR for ${{ env.PR_BRANCH }}" --body "This is an automated PR for ${{ env.PR_BRANCH }}"
if: ${{ env.GIT_USER_NAME && env.GIT_USER_MAIL && env.PACKAGE && env.PR_BRANCH && env.BUILD_URL && steps.manipulate_composer.outcome == 'success' }}
env:
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}