From 0ed3e618ee79d39f1da317acf3b42051c921a0c6 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Sat, 18 May 2024 12:10:06 +0200 Subject: [PATCH 1/3] Add workflow that creates a pr externally in the dpl-cms repo --- .github/workflows/create-cms-pr.yml | 65 +++++++++++++++++++ .../create-release-on-branch-changes.yml | 15 +++++ 2 files changed, 80 insertions(+) create mode 100644 .github/workflows/create-cms-pr.yml diff --git a/.github/workflows/create-cms-pr.yml b/.github/workflows/create-cms-pr.yml new file mode 100644 index 0000000000..10dcab5356 --- /dev/null +++ b/.github/workflows/create-cms-pr.yml @@ -0,0 +1,65 @@ +name: Create CMS PR +on: + workflow_run: + workflows: ["Create release on branch changes"] + types: + - completed + +jobs: + invoke-external-pr-workflow: + runs-on: ubuntu-latest + steps: + - uses: actions/download-artifact@v4 + with: + name: release-info.json + github-token: ${{ secrets.GITHUB_TOKEN }} + run-id: ${{ github.event.workflow_run.id }} + + - name: Set env variables + run: | + RELEASE_BRANCH=$(jq -r '.release_branch' release-info.json) + RELEASE_DOWNLOAD_URL=$(jq -r '.release_download_url' release-info.json) + DEPENDENCY_PACKAGE=$(jq -r '.dependency_package' release-info.json) + echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV + echo "RELEASE_DOWNLOAD_URL=$RELEASE_DOWNLOAD_URL" >> $GITHUB_ENV + echo "DEPENDENCY_PACKAGE=$DEPENDENCY_PACKAGE" >> $GITHUB_ENV + + - 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": "${{ env.RELEASE_BRANCH }}", + "build_url": "${{ env.RELEASE_DOWNLOAD_URL }}", + "dependency_package": "${{ env.DEPENDENCY_PACKAGE }}" + } + } + 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"]'), env.RELEASE_BRANCH) }} + + - name: Adding summary + run: | + echo "Requested external PR at: ${REMOTE_REPO_GITHUB_HANDLE}" >> $GITHUB_STEP_SUMMARY + echo "Based on the [${{ env.RELEASE_BRANCH }}](${{ env.BRANCH_URL }}) branch" >> $GITHUB_STEP_SUMMARY + if: ${{ steps.invoke_external_pr_workflow.outcome == 'success' }} + env: + BRANCH_URL: "${{ github.event.repository.html_url }}/tree/${{ env.RELEASE_BRANCH }}" + 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"]'), env.RELEASE_BRANCH) }} diff --git a/.github/workflows/create-release-on-branch-changes.yml b/.github/workflows/create-release-on-branch-changes.yml index 5c08090b5b..1ad7ecaa3c 100644 --- a/.github/workflows/create-release-on-branch-changes.yml +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -82,6 +82,21 @@ jobs: body: ${{ env.RELEASE_DESCRIPTION }} files: ${{ env.DIST_FILENAME }} + - name: Write release information in artifact file + run: | + printf '{ + "release_branch": "${{ env.RELEASE_BRANCH }}", + "dependency_package": "danskernesdigitalebibliotek/dpl-react", + "release_download_url": "${{ env.DOWNLOAD_URL }}" + }' >> release-info.json + env: + DOWNLOAD_URL: "${{ github.event.repository.html_url }}/releases/download/${{ env.TAG_NAME }}/${{ env.DIST_FILENAME }}" + + - uses: actions/upload-artifact@v3 + with: + name: release-info.json + path: ./release-info.json + - name: Adding summary run: | echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY From ddde043ef563c5c96f356d3e65caf07b82df84f8 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Fri, 31 May 2024 18:14:57 +0200 Subject: [PATCH 2/3] Make create-cms-pr dispatcable with inputs and dispatch workflow from create-release-on-branch-changes with gh instead of uploading a json asset. --- .github/workflows/create-cms-pr.yml | 51 +++++++++---------- .../create-release-on-branch-changes.yml | 17 +++---- 2 files changed, 31 insertions(+), 37 deletions(-) diff --git a/.github/workflows/create-cms-pr.yml b/.github/workflows/create-cms-pr.yml index 10dcab5356..5db2285e9d 100644 --- a/.github/workflows/create-cms-pr.yml +++ b/.github/workflows/create-cms-pr.yml @@ -1,29 +1,28 @@ +# 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_run: - workflows: ["Create release on branch changes"] - types: - - completed + workflow_dispatch: + inputs: + releaseBranch: + description: 'Release Branch' + required: true + releaseDownloadUrl: + description: 'Release Download Url' + required: true + dependencyPackage: + description: 'Dependency Package' + required: true jobs: invoke-external-pr-workflow: runs-on: ubuntu-latest steps: - - uses: actions/download-artifact@v4 - with: - name: release-info.json - github-token: ${{ secrets.GITHUB_TOKEN }} - run-id: ${{ github.event.workflow_run.id }} - - - name: Set env variables - run: | - RELEASE_BRANCH=$(jq -r '.release_branch' release-info.json) - RELEASE_DOWNLOAD_URL=$(jq -r '.release_download_url' release-info.json) - DEPENDENCY_PACKAGE=$(jq -r '.dependency_package' release-info.json) - echo "RELEASE_BRANCH=$RELEASE_BRANCH" >> $GITHUB_ENV - echo "RELEASE_DOWNLOAD_URL=$RELEASE_DOWNLOAD_URL" >> $GITHUB_ENV - echo "DEPENDENCY_PACKAGE=$DEPENDENCY_PACKAGE" >> $GITHUB_ENV - - name: Invoke external PR workflow id: invoke_external_pr_workflow uses: fjogeleit/http-request-action@v1 @@ -39,27 +38,27 @@ jobs: { "event_type": "create_pr", "client_payload": { - "branch": "${{ env.RELEASE_BRANCH }}", - "build_url": "${{ env.RELEASE_DOWNLOAD_URL }}", - "dependency_package": "${{ env.DEPENDENCY_PACKAGE }}" + "branch": "${{ inputs.releaseBranch }}", + "build_url": "${{ inputs.releaseDownloadUrl }}", + "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"]'), env.RELEASE_BRANCH) }} + 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 [${{ env.RELEASE_BRANCH }}](${{ env.BRANCH_URL }}) branch" >> $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/${{ env.RELEASE_BRANCH }}" + 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"]'), env.RELEASE_BRANCH) }} + 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 1ad7ecaa3c..7bf76ff758 100644 --- a/.github/workflows/create-release-on-branch-changes.yml +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -82,21 +82,16 @@ jobs: body: ${{ env.RELEASE_DESCRIPTION }} files: ${{ env.DIST_FILENAME }} - - name: Write release information in artifact file + - name: Dispatch CMS PR creation workflow run: | - printf '{ - "release_branch": "${{ env.RELEASE_BRANCH }}", - "dependency_package": "danskernesdigitalebibliotek/dpl-react", - "release_download_url": "${{ env.DOWNLOAD_URL }}" - }' >> release-info.json + gh workflow run create-cms-pr.yml \ + -f releaseBranch=${{ env.RELEASE_BRANCH }} \ + -f releaseDownloadUrl=${{ env.DOWNLOAD_URL }} \ + -f dependencyPackage=danskernesdigitalebibliotek/dpl-react env: + GH_TOKEN: ${{ github.token }} DOWNLOAD_URL: "${{ github.event.repository.html_url }}/releases/download/${{ env.TAG_NAME }}/${{ env.DIST_FILENAME }}" - - uses: actions/upload-artifact@v3 - with: - name: release-info.json - path: ./release-info.json - - name: Adding summary run: | echo "Release created 🚀😎 at: ${{ steps.create-release.outputs.url }}" >> $GITHUB_STEP_SUMMARY From 87f806f9e04fcc0036395e33cb653bfabeedae59 Mon Sep 17 00:00:00 2001 From: Mikkel Jakobsen Date: Mon, 3 Jun 2024 15:56:27 +0200 Subject: [PATCH 3/3] Remove build download url Since the dpl-cms workflow does not need it anymore. The dpl-cms wf can resolve which package to download by the package name. --- .github/workflows/create-cms-pr.yml | 4 ---- .github/workflows/create-release-on-branch-changes.yml | 2 -- 2 files changed, 6 deletions(-) diff --git a/.github/workflows/create-cms-pr.yml b/.github/workflows/create-cms-pr.yml index 5db2285e9d..44024e0bf5 100644 --- a/.github/workflows/create-cms-pr.yml +++ b/.github/workflows/create-cms-pr.yml @@ -12,9 +12,6 @@ on: releaseBranch: description: 'Release Branch' required: true - releaseDownloadUrl: - description: 'Release Download Url' - required: true dependencyPackage: description: 'Dependency Package' required: true @@ -39,7 +36,6 @@ jobs: "event_type": "create_pr", "client_payload": { "branch": "${{ inputs.releaseBranch }}", - "build_url": "${{ inputs.releaseDownloadUrl }}", "dependency_package": "${{ inputs.dependencyPackage }}" } } diff --git a/.github/workflows/create-release-on-branch-changes.yml b/.github/workflows/create-release-on-branch-changes.yml index 7bf76ff758..a20fb916f8 100644 --- a/.github/workflows/create-release-on-branch-changes.yml +++ b/.github/workflows/create-release-on-branch-changes.yml @@ -86,11 +86,9 @@ jobs: run: | gh workflow run create-cms-pr.yml \ -f releaseBranch=${{ env.RELEASE_BRANCH }} \ - -f releaseDownloadUrl=${{ env.DOWNLOAD_URL }} \ -f dependencyPackage=danskernesdigitalebibliotek/dpl-react env: GH_TOKEN: ${{ github.token }} - DOWNLOAD_URL: "${{ github.event.repository.html_url }}/releases/download/${{ env.TAG_NAME }}/${{ env.DIST_FILENAME }}" - name: Adding summary run: |