Skip to content

Commit

Permalink
Adding package name concept
Browse files Browse the repository at this point in the history
  • Loading branch information
spaceo committed Jun 3, 2024
1 parent 784dd43 commit 270074f
Showing 1 changed file with 53 additions and 37 deletions.
90 changes: 53 additions & 37 deletions .github/workflows/create-pr.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,29 +17,32 @@ jobs:
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: |
PACKAGE_NAME=$(echo "${{ github.event.client_payload.dependency_package }}" | sed 's/[^\/]*\///')
echo "PR_BRANCH=$PR_BRANCH" >> $GITHUB_ENV
echo "BUILD_URL=$BUILD_URL" >> $GITHUB_ENV
echo "PACKAGE=$PACKAGE" >> $GITHUB_ENV
echo "PACKAGE_NAME=$PACKAGE_NAME" >> $GITHUB_ENV
BUILD_URL_IS_ACCEPTED=$(echo '${{ vars.ACCEPTED_BUILD_URL_PREFIXES }}' | jq --arg url "${{ env.BUILD_URL }}" 'any(.[]; . as $prefix | $url | contains($prefix))')
echo "BUILD_URL_IS_ACCEPTED=$BUILD_URL_IS_ACCEPTED" >> $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 }}
PACKAGE_NAME_IS_VALID=$(echo '${{ vars.ACCEPTED_PACKAGES }}' | jq --arg project "${{ env.PACKAGE }}" 'any(.[]; . as $name | $project | match($name))')
echo "PACKAGE_NAME_IS_VALID=$PACKAGE_NAME_IS_VALID" >> $GITHUB_ENV
echo $PACKAGE_NAME
echo $PACKAGE_NAME_IS_VALID
if: ${{ github.event.action == 'create_pr' && github.event.client_payload.branch && github.event.client_payload.dependency_package }}

- name: Stop workflow if any variables are missing
run: |
echo "::error::Some variable is missing. Have to stop..."
exit 1
if: ${{ !env.PR_BRANCH || !env.BUILD_URL && !env.PACKAGE || !vars.ACCEPTED_BUILD_URL_PREFIXES }}
if: ${{ !env.PR_BRANCH || !env.PACKAGE || !env.PACKAGE_NAME}}

- name: Stop workflow if build url is not valid
- name: Stop workflow if package name is not valid
run: |
echo "::error::The build URL is not valid. Should match one of the accepted prefixes."
echo "::error::The package name is not valid. Should match one of the accepted package names."
exit 1
if: ${{ env.BUILD_URL_IS_ACCEPTED != 'true' }}
if: ${{ env.PACKAGE_NAME_IS_VALID != 'true' }}

- uses: actions/checkout@v4
with:
Expand All @@ -56,42 +59,55 @@ jobs:
exit 1
if: ${{ steps.check_branch_exists.outputs.exists == 'true' }}

- name: Install go-task
uses: arduino/setup-task@v2
with:
repo-token: ${{ secrets.GITHUB_TOKEN }}

- name: Insert dependency
id: manipulate_composer
run: |
set -e
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 }}
declare -a CMDS=(
[poc-dpl-react-pr-trigger]='dev:composer:update-design-system'
[poc-dpl-design-system-pr-trigger]='dev:composer:update-react'
)
- name: Create branch
id: create_branch
uses: stefanzweifel/git-auto-commit-action@v5
with:
branch: ${{ env.PR_BRANCH }}
commit_message: "Insert new reference to dependency ${{ env.PACKAGE }}: ${{ env.BUILD_URL }}"
create_branch: true
if: ${{ steps.manipulate_composer.outcome == 'success' }}
- name: Create PR
id: create_pr
run: |
set -e
gh pr create \
--base develop \
--head ${{ env.PR_BRANCH }} \
--title "${{ format('PR for {0}:{1}', env.PACKAGE, env.PR_BRANCH) }}" \
--body "${{ format('This is an automated PR for {0}:{1}', env.PACKAGE, env.PR_BRANCH) }}"
if: ${{ steps.create_branch.outcome == 'success' }}
COMMAND=${CMDS[$PACKAGE_NAME]}
echo $COMMAND
task $COMMAND
env:
BRANCH: ${{ env.PR_BRANCH }}
GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Adding summary
run: |
URL=$(gh pr view --json=url ${{ env.PR_BRANCH }} | jq .url)
echo "Created automated PR at: ${URL}" >> $GITHUB_STEP_SUMMARY
if: ${{ steps.create_pr.outcome == 'success' }}
env:
GH_TOKEN: ${{ github.token }}
# - name: Create branch
# id: create_branch
# uses: stefanzweifel/git-auto-commit-action@v5
# with:
# branch: ${{ env.PR_BRANCH }}
# commit_message: "Insert new reference to dependency ${{ env.PACKAGE }}: ${{ env.BUILD_URL }}"
# create_branch: true
# if: ${{ steps.manipulate_composer.outcome == 'success' }}

# - name: Create PR
# id: create_pr
# run: |
# set -e
# gh pr create \
# --base develop \
# --head ${{ env.PR_BRANCH }} \
# --title "${{ format('PR for {0}:{1}', env.PACKAGE, env.PR_BRANCH) }}" \
# --body "${{ format('This is an automated PR for {0}:{1}', env.PACKAGE, env.PR_BRANCH) }}"
# if: ${{ steps.create_branch.outcome == 'success' }}
# env:
# GH_TOKEN: ${{ secrets.GITHUB_TOKEN }}

# - name: Adding summary
# run: |
# URL=$(gh pr view --json=url ${{ env.PR_BRANCH }} | jq .url)
# echo "Created automated PR at: ${URL}" >> $GITHUB_STEP_SUMMARY
# if: ${{ steps.create_pr.outcome == 'success' }}
# env:
# GH_TOKEN: ${{ github.token }}

0 comments on commit 270074f

Please sign in to comment.