Skip to content

Commit

Permalink
WIP post preview comment (+ remove configurable output format)
Browse files Browse the repository at this point in the history
Signed-off-by: Antoine THEBAUD <[email protected]>
  • Loading branch information
Antoine THEBAUD committed Dec 10, 2024
1 parent 2b6dc4c commit 7ff59d2
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 11 deletions.
7 changes: 1 addition & 6 deletions .github/workflows/dac.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,7 @@ on:
type: boolean
required: false
# preview-specific:
output:
description: "Format of the output: json or yaml (default is yaml)."
type: string
required: false
prefix:
prefix: # TODO should be replaced by automatic passing of PR number
description: If provided, it is used to prefix the dashboard preview name.
type: string
required: false
Expand Down Expand Up @@ -133,7 +129,6 @@ jobs:
with:
directory: ./built
project: ${{ inputs.project }}
output: ${{ inputs.output }}
prefix: ${{ inputs.prefix }}
ttl: ${{ inputs.ttl }}

Expand Down
24 changes: 19 additions & 5 deletions actions/preview_dashboards/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ inputs:
file:
description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`).
required: false
output:
description: "Format of the output: json or yaml (default is yaml)."
required: false
prefix:
description: If provided, it is used to prefix the dashboard preview name.
required: false
Expand All @@ -29,8 +26,25 @@ runs:
percli dac preview \
$([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \
$([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \
$([[ -n "${{ inputs.output }}" ]] && echo "-o ${{ inputs.output }}") \
$([[ -n "${{ inputs.prefix }}" ]] && echo "--prefix ${{ inputs.prefix }}") \
$([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") \
$([[ -n "${{ inputs.ttl }}" ]] && echo "--ttl ${{ inputs.ttl }}")
$([[ -n "${{ inputs.ttl }}" ]] && echo "--ttl ${{ inputs.ttl }}") \
-o json \
> preview_output.json
shell: bash

- name: Post preview links to PR
if: ${{ github.event_name == 'pull_request' }}
uses: actions/github-script@v6
with:
script: |
const fs = require('fs');
const data = JSON.parse(fs.readFileSync('preview_output.json', 'utf8'));
const previewLinks = data.map(item => `- [${item.project}/${item.dashboard}](${item.preview})`).join('\n');
const commentBody = `### Dashboard Previews\nThe following dashboards have been deployed as previews:\n\n${previewLinks}`;
github.rest.issues.createComment({
owner: context.repo.owner,
repo: context.repo.repo,
issue_number: context.issue.number,
body: commentBody
});

0 comments on commit 7ff59d2

Please sign in to comment.