Skip to content

Commit

Permalink
A0-4085: Add step that posts frontend-url when branchpreview is creat…
Browse files Browse the repository at this point in the history
…ed (#47)

* Add step that posts frontend-url when branchpreview is created

* Modify branchpreview workflow to match action changes

* Change action ref

* Add missing shell property

* Remove temporary ref
  • Loading branch information
mikolajgs authored Apr 19, 2024
1 parent dcfbc23 commit d9eeb8c
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 1 deletion.
14 changes: 13 additions & 1 deletion .github/workflows/_branchpreview-create.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ on:
description: "Choose from 'private' or 'public'"
required: true
type: string
post-frontend-url:
description: "Post frontend-url output to PR comments"
required: false
type: string
default: "false"
pull-request-number:
description: "Pull request number required when posting frontend-url"
required: false
type: string
default: ""
outputs:
base64:
description: Outputs encoded with base64
Expand All @@ -40,7 +50,7 @@ jobs:
steps:
- name: Create branchpreview
id: create-branchpreview
uses: Cardinal-Cryptography/github-actions/create-branchpreview@v3
uses: Cardinal-Cryptography/github-actions/create-branchpreview@v6
with:
repository-name: ${{ inputs.repository-name }}
branch-name: ${{ inputs.branch-name }}
Expand All @@ -54,3 +64,5 @@ jobs:
git-commit-author: ${{ secrets.AUTOCOMMIT_AUTHOR }}
git-commit-email: ${{ secrets.AUTOCOMMIT_EMAIL }}
hard-refresh: 'true'
post-frontend-url: '${{ inputs.post-frontend-url }}'
pull-request-number: '${{ inputs.pull-request-number }}'
27 changes: 27 additions & 0 deletions create-branchpreview/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ inputs:
description: 'Make hard-refresh of ArgoCD application'
required: false
default: "false"
post-frontend-url:
description: "Post frontend-url output value"
required: false
default: "false"
pull-request-number:
description: "Pull request number to post the frontend-url to"
required: false
default: ""
outputs:
app-name:
description: |
Expand Down Expand Up @@ -131,3 +139,22 @@ runs:
'${{ inputs.argo-sync-user-token }}' \
'${{ steps.start-branchpreview.outputs.app-name }}' \
'${{ inputs.hard-refresh == 'true' && 'true' || 'false' }}'
- name: Post frontend-url in comments
if: >
inputs.post-frontend-url == 'true' &&
inputs.repository-name != '' &&
inputs.pull-request-number != ''
shell: bash
env:
CI_GH_TOKEN: ${{ inputs.gh-ci-token }}
run: |
echo '${{ steps.start-branchpreview.outputs.all-base64 }}' | base64 -d > tmp-outputs.txt
frontend_url=$(cat tmp-outputs.txt | grep "^frontend-url" | sed 's|frontend-url:||g')
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer ${{ env.CI_GH_TOKEN }}" \
-H "X-GitHub-Api-Version: 2022-11-28" \
https://api.github.com/repos/Cardinal-Cryptography/${{ inputs.repository-name }}/issues/${{ inputs.pull-request-number }}/comments \
-d "{\"body\":\"The following site has been deployed: [${frontend_url}](${frontend_url})\"}"

0 comments on commit d9eeb8c

Please sign in to comment.