create_pr #34
This file contains 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 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 | |
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 | |
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 | |
# TODO: Remember to change hardcoded url check. | |
if: ${{ env.BUILD_URL && env.PACKAGE && startsWith(env.BUILD_URL, 'https://github.com/reload/poc-dpl-react-pr-trigger/releases/download') }} | |
- name: Create branch and PR | |
run: | | |
set -e | |
git config --global user.name [email protected] | |
git config --global user.email [email protected] | |
git checkout -b ${{ env.PR_BRANCH }} | |
git push --set-upstream origin ${{ env.PR_BRANCH }} | |
git add composer.json composer.lock | |
git commit -m "Use new dependency url on dpl-react: ${{ 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.PR_BRANCH && env.BUILD_URL && steps.manipulate_composer.outcome == 'success' }} | |
env: | |
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }} |