Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add workflow that creates a pr externally in the dpl-cms repo #632

Conversation

spaceo
Copy link
Contributor

@spaceo spaceo commented May 18, 2024

Link to issue

https://reload.atlassian.net/browse/DDFLSBP-643

Description

This PR adds a Github Workflow create-cms-pr that requests dpl-cms to create a PR.
For separation of concerns the workflow is triggered by the create-release-on-branch-changes workflow. In that way we try to avoid leaving all steps in the create-release-on-branch-changes and isolate the remote pr action steps in a separate yml file.

The changes here are similar to the changes in the dpl-react repo.

Additional comments or questions

We need to set secrret and variables similiar to what has been set in:
https://github.com/reload/poc-dpl-design-system-pr-trigger

Comment on lines 27 to 50
- 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) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please consider using the gh CLI to invoke workflows instead of a HTTP bridge for the same.

As I see it using the CLI should be less fragile because 1) we do not depend on third parties (like fjogeleit/http-request-action), 2) we do not have no manually recreate HTTP requests for API calls.

It should ve available automatically.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Its a good call. I experimented a bit with "gh api -X POST". What also complicates things a bit is that I am experimenting in the poc-* repo which I have to keep aligned with this repo.
Anyways, I could not make it work right away, so I choose to write a todo and will revisit this part.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Have you tried using gh workflow run?

It seems appropriate for this use case compared to the "raw" gh api -X - it has parameters for the repo, fields etc.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you have used gh workflow run later on. I wonder why you could not get it to work here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As an alternative have you considered using an action that is targeted dispatches like https://github.com/marketplace/actions/repository-dispatch?

.github/workflows/create-cms-pr.yml Outdated Show resolved Hide resolved
.github/workflows/create-cms-pr.yml Show resolved Hide resolved
.github/workflows/create-release-on-branch-changes.yml Outdated Show resolved Hide resolved
.github/workflows/create-cms-pr.yml Show resolved Hide resolved
@kasperg kasperg removed their assignment May 28, 2024
spaceo added 3 commits May 31, 2024 12:19
Since the dpl-cms workflow does not need it anymore. The dpl-cms wf can
resolve which package to download by the package name.
@spaceo
Copy link
Contributor Author

spaceo commented Jun 3, 2024

I have made changes according to some of your requests.
Please note that the: "Create release on branch changes / Create release on branch changes (push)" is failing because the workflow is not merged into develop.

@spaceo spaceo requested a review from kasperg June 3, 2024 14:19
Comment on lines +88 to +94
- 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 }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍 This looks nice to me.

Comment on lines 27 to 50
- 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) }}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see you have used gh workflow run later on. I wonder why you could not get it to work here.

@spaceo spaceo merged commit fc1055c into develop Jun 4, 2024
4 of 6 checks passed
@spaceo spaceo deleted the DDFLSBP-643-automatiser-pull-request-oprettelse-i-dpl-cms-ved-arbejde-i-dpl-react-designsystem branch June 4, 2024 08:56
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants