-
Notifications
You must be signed in to change notification settings - Fork 6
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
Add workflow that creates a pr externally in the dpl-cms repo #632
Conversation
.github/workflows/create-cms-pr.yml
Outdated
- 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) }} |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
So it easier to handle/understand.
Since the dpl-cms workflow does not need it anymore. The dpl-cms wf can resolve which package to download by the package name.
I have made changes according to some of your requests. |
- 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 }} |
There was a problem hiding this comment.
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.
.github/workflows/create-cms-pr.yml
Outdated
- 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) }} |
There was a problem hiding this comment.
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.
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 thecreate-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