Skip to content

Commit

Permalink
Merge pull request #10 from perses/antoinethebaud/action-dac
Browse files Browse the repository at this point in the history
Dashboard-as-Code actions & workflow
  • Loading branch information
AntoineThebaud authored Dec 18, 2024
2 parents a58b1a9 + 17c8685 commit 3abe302
Show file tree
Hide file tree
Showing 20 changed files with 694 additions and 10 deletions.
144 changes: 144 additions & 0 deletions .github/workflows/dac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,144 @@
name: Reusable Workflow for Dashboard-as-Code CI/CD
on:
workflow_call:
inputs:
# general:
url:
description: The URL of the Perses API server where to deploy the dashboard preview.
type: string
required: true
directory:
description: Path to the directory containing the dashboards as code (mutually exclusive with `file`).
type: string
required: false
file:
description: Path to the file that contains the dashboards as code (mutually exclusive with `directory`).
type: string
required: false
project:
description: If present, the project scope for this CLI request.
type: string
required: false
# skip:
skip-preview:
description: Skip the dashboard preview stage if provided.
type: boolean
required: false
skip-diff:
description: Skip the dashboard diff generation stage if provided.
type: boolean
required: false
skip-deploy:
description: Skip the dashboard deployment stage if provided.
type: boolean
required: false
# auth:
username:
description: Username for basic authentication to the API server.
type: string
required: false
password:
description: Password for basic authentication to the API server.
type: string
required: false
token:
description: Bearer token for authentication to the API server.
type: string
required: false
provider:
description: External authentication provider identifier. (slug_id)
type: string
required: false
client-id:
description: Client ID used for robotic access when using external authentication provider.
type: string
required: false
client-secret:
description: Client Secret used for robotic access when using external authentication provider.
type: string
required: false
insecure-skip-tls-verify:
description: If true the server's certificate will not be checked for validity. This will make your HTTPS connections insecure.
type: string
required: false
# validate-specific:
server-validation:
description: When enabled, requests the API to make additional validation.
type: boolean
required: false
# preview-specific:
ttl:
description: Time To Live of the dashboard preview (default "1d").
type: string
required: false
# deploy-specific:
force:
description: If present, dashboards will be deployed even if the projects are not consistent between the --project flag and the dashboards metadata (the latter has priority).
type: boolean
required: false

jobs:
dac:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install necessary tools
uses: ./actions/setup_environment
with:
enable_go: true
enable_cue: true

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: "latest"

- name: Build the dashboards
uses: ./actions/build_dac
with:
directory: ${{ inputs.directory }}
file: ${{ inputs.file }}

- name: Login to the API server
uses: ./actions/login
with:
url: ${{ inputs.url }}
username: ${{ inputs.username }}
password: ${{ inputs.password }}
token: ${{ inputs.token }}
provider: ${{ inputs.provider }}
client-id: ${{ inputs.client-id }}
client-secret: ${{ inputs.client-secret }}
insecure-skip-tls-verify: ${{ inputs.insecure-skip-tls-verify }}

- name: Validate the dashboards
uses: ./actions/validate_resources
with:
directory: ./built
online: ${{ inputs.server-validation }}

- name: Preview the dashboards
if: ${{ github.event_name == 'pull_request' && !inputs.skip-preview }}
uses: ./actions/preview_dashboards
with:
directory: ./built
project: ${{ inputs.project }}
prefix: ${{ github.event.pull_request.number }}
ttl: ${{ inputs.ttl }}

- name: Generate dashboards diffs
if: ${{ github.event_name == 'pull_request' && !inputs.skip-diff }}
uses: ./actions/diff_dashboards
with:
directory: ./built
project: ${{ inputs.project }}

- name: Deploy the dashboards
if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !inputs.skip-deploy }}
uses: ./actions/apply_resources
with:
directory: ./built
project: ${{ inputs.project }}
force: ${{ inputs.force }}
36 changes: 36 additions & 0 deletions .github/workflows/test_apply_resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test Apply Resources
on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-apply-resources:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: "latest"

- name: Login to the API server
uses: ./actions/login
with:
url: https://demo.perses.dev
username: ${{ secrets.TEST_USERNAME }}
password: ${{ secrets.TEST_PASSWORD }}

- name: Test apply resources
uses: ./actions/apply_resources
with:
file: ./testdata/resources_folder/dashboard.json

56 changes: 56 additions & 0 deletions .github/workflows/test_build_dac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
name: Test Build Dashboards-as-Code
on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-build-dac:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: latest

- name: Install cue binary
uses: ./actions/setup_environment
with:
enable_go: true
enable_cue: true

- name: Test build DaC with directory
uses: ./actions/build_dac
with:
directory: ./testdata/dac_folder

- name: Test build DaC with file
uses: ./actions/build_dac
with:
file: ./testdata/dac_file.cue

- name: Test build DaC with both inputs (should fail)
id: test_fail
uses: ./actions/build_dac
with:
directory: ./testdata/dac_folder
file: ./testdata/dac_file.cue
continue-on-error: true

- name: Validate failure for both inputs
run: |
if [ "${{ steps.test_fail.outcome }}" != "failure" ]; then
echo "Error: Action did not fail as expected when both inputs were provided."
exit 1
else
echo "Success: Action failed as expected."
fi
22 changes: 22 additions & 0 deletions .github/workflows/test_dac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
name: Test the Dashboard-as-Code workflow

on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-dac:
uses: ./.github/workflows/dac.yaml
with:
url: https://demo.perses.dev
directory: ./testdata/dac_folder
server-validation: true
username: ${{ secrets.TEST_USERNAME }}
password: ${{ secrets.TEST_PASSWORD }}
35 changes: 35 additions & 0 deletions .github/workflows/test_diff_dashboards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: Test Diff Dashboards
on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-diff-dashboards:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: "latest"

- name: Login to the API server
uses: ./actions/login
with:
url: https://demo.perses.dev
username: ${{ secrets.TEST_USERNAME }}
password: ${{ secrets.TEST_PASSWORD }}

- name: Test dashboard diff
uses: ./actions/diff_dashboards
with:
directory: ./testdata/resources_folder
36 changes: 36 additions & 0 deletions .github/workflows/test_preview_dashboards.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Test Preview Dashboards
on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-preview-dashboards:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: "latest"

- name: Login to the API server
uses: ./actions/login
with:
url: https://demo.perses.dev
username: ${{ secrets.TEST_USERNAME }}
password: ${{ secrets.TEST_PASSWORD }}

- name: Test dashboard preview
uses: ./actions/preview_dashboards
with:
file: ./testdata/resources_folder/dashboard.json
prefix: test-preview
39 changes: 39 additions & 0 deletions .github/workflows/test_validate_resources.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
name: Test resources validation
on:
workflow_dispatch: # Allow manual triggering
push:
branches:
- main
- release/*
- snapshot/*
tags:
- v*
pull_request:
merge_group:
jobs:
test-validate-resources:
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4

- name: Install percli
uses: ./actions/install_percli
with:
cli_version: latest

- name: Install cue binary
uses: ./actions/setup_environment
with:
enable_go: true
enable_cue: true

- name: Test resources validation
uses: ./actions/validate_resources
with:
directory: ./testdata/resources_folder

- name: Test resources validation with file
uses: ./actions/validate_resources
with:
file: ./testdata/resource.json
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,7 @@

# System Files
.DS_Store
Thumbs.db
Thumbs.db

# DaC-generated
built
Loading

0 comments on commit 3abe302

Please sign in to comment.