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

Dashboard-as-Code actions & workflow #10

Merged
merged 33 commits into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from 30 commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
de1a91e
Add new action to build dashboards as code
Dec 4, 2024
8dafcad
Rename workflow file
Dec 4, 2024
eef95a5
add new action validate resources (1rst simple version)
Dec 4, 2024
4805acf
Avoid doing checks already done by the CLI
Dec 5, 2024
abbd6c2
remove useless quotes
Dec 5, 2024
dbe9801
build dac + validate: add missing flags
Dec 5, 2024
6db5e62
add new action to preview dashboards
Dec 6, 2024
24a514f
Fix wrong names
Dec 6, 2024
b8822c9
add new action to diff dashboards
Dec 6, 2024
6f60ab3
update some descriptions
Dec 6, 2024
63f4715
add new actions to apply resources
Dec 6, 2024
37f2120
update file & dir inputs descs
Dec 6, 2024
089b4d8
1rst working version for the merge main / deploy case
Dec 9, 2024
b303ca3
fix skip-tls flag usage
Dec 9, 2024
ff5c136
Factorize login logic
Dec 9, 2024
58b87cc
Move login to a dedicated action
Dec 10, 2024
6e9c322
Add conditions to change behavior between PR vs main branch
Dec 10, 2024
2b6dc4c
Add login step in individual tests that require it
Dec 10, 2024
aad1ef3
Post preview comment (+ remove configurable output format)
Dec 10, 2024
146bd3d
preview: replace configurable prefix by PR number
Dec 10, 2024
b5a4888
Preview: bring back configurable prefix in action + pass github PR nu…
Dec 10, 2024
7a2015b
Fix diff
Dec 10, 2024
155cb25
diff: upload diff files as artifacts
Dec 10, 2024
20f9152
update gitignore
Dec 10, 2024
e47bee3
bump github-script version used
Dec 10, 2024
d039a3a
Update diff message
Dec 10, 2024
739bd9a
Fix online validation
Dec 10, 2024
22270bf
dont skip diff in DaC test
Dec 10, 2024
c5380db
fix diff stage
Dec 10, 2024
b0edc84
Deploy if default branch
Dec 11, 2024
c70b6ae
consistent naming convention for inputs
Dec 11, 2024
939f22c
Improve diff output
Dec 12, 2024
17c8685
change creds to secrets
Dec 13, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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:
Copy link
Member

Choose a reason for hiding this comment

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

some keys are using "_" others "-", should we align everything? (ie: skip_deploy)

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: test
password: test

- 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: test
password: test
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: test
password: test

- 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: test
password: test

- 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
Loading