diff --git a/.github/workflows/create-cms-pr.yml b/.github/workflows/create-cms-pr.yml new file mode 100644 index 000000000..44024e0bf --- /dev/null +++ b/.github/workflows/create-cms-pr.yml @@ -0,0 +1,60 @@ +# This workflow is triggered when the "Create release on branch changes" workflow is completed. +# It downloads the release information from the previous workflow and invokes the external PR workflow. +# The external PR workflow is invoked only if the release branch is not develop or main. +# Needed secrets: +# CMS_PR_CREATION_PAT - for invoking the external PR workflow. A Token with the "repo" scope is needed. +# Needed env variables: +# REMOTE_REPO_GITHUB_HANDLE - is the GitHub handle ([ORG]/[REPO]) of the repository where the external PR workflow is located. +name: Create CMS PR +on: + workflow_dispatch: + inputs: + releaseBranch: + description: 'Release Branch' + required: true + dependencyPackage: + description: 'Dependency Package' + required: true + +jobs: + invoke-external-pr-workflow: + runs-on: ubuntu-latest + steps: + - name: Invoke external PR workflow + id: invoke_external_pr_workflow + uses: fjogeleit/http-request-action@v1 + with: + url: ${{ env.REQUEST_URL}} + method: 'POST' + customHeaders: | + { + "Accept": "application/vnd.github+json", + "Authorization": "Bearer ${{ secrets.CMS_PR_CREATION_PAT }}" + } + data: | + { + "event_type": "create_pr", + "client_payload": { + "branch": "${{ inputs.releaseBranch }}", + "dependency_package": "${{ inputs.dependencyPackage }}" + } + } + env: + REQUEST_URL: ${{ format('https://api.github.com/repos/{0}/dispatches', vars.REMOTE_REPO_GITHUB_HANDLE) }} + # Only invoke external PR workflow if the release branch is not develop or main + if: ${{ !contains(fromJSON('["develop", "main"]'), inputs.releaseBranch) }} + + - name: Adding summary + run: | + echo "Requested external PR at: ${REMOTE_REPO_GITHUB_HANDLE}" >> $GITHUB_STEP_SUMMARY + echo "Based on the [${{ inputs.releaseBranch }}](${{ env.BRANCH_URL }}) branch" >> $GITHUB_STEP_SUMMARY + if: ${{ steps.invoke_external_pr_workflow.outcome == 'success' }} + env: + BRANCH_URL: "${{ github.event.repository.html_url }}/tree/${{ inputs.releaseBranch }}" + REMOTE_REPO_GITHUB_HANDLE: "${{ vars.REMOTE_REPO_GITHUB_HANDLE }}" + + - name: Adding summary about skip if branch is develop or main + run: | + echo "Skipped PR creation because the branch was: $RELEASE_BRANCH " >> $GITHUB_STEP_SUMMARY + echo "...which is not considered being a release branch. " >> $GITHUB_STEP_SUMMARY + if: ${{ contains(fromJSON('["develop", "main"]'), inputs.releaseBranch) }} diff --git a/.github/workflows/create-release-on-branch-changes.yml b/.github/workflows/create-release-on-branch-changes.yml index 8574a7d27..1a9f2b23e 100644 --- a/.github/workflows/create-release-on-branch-changes.yml +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -85,6 +85,14 @@ jobs: body: ${{ env.RELEASE_DESCRIPTION }} files: ${{ env.DIST_FILENAME }} + - name: Dispatch CMS PR creation workflow + run: | + gh workflow run create-cms-pr.yml \ + -f releaseBranch=${{ env.RELEASE_BRANCH }} \ + -f dependencyPackage=danskernesdigitalebibliotek/dpl-design-system + env: + GH_TOKEN: ${{ github.token }} + - name: Adding summary run: | echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY