From de1a91e4d550f2f997c391e111e6dc0c1188aad0 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Wed, 4 Dec 2024 11:42:04 +0100 Subject: [PATCH 01/33] Add new action to build dashboards as code Signed-off-by: Antoine THEBAUD --- .github/workflows/test_percli_dac_build.yaml | 56 ++++++++++++++++++++ actions/build_dac/action.yaml | 32 +++++++++++ testdata/dac_file.cue | 3 ++ testdata/dac_folder/file.cue | 3 ++ 4 files changed, 94 insertions(+) create mode 100644 .github/workflows/test_percli_dac_build.yaml create mode 100644 actions/build_dac/action.yaml create mode 100644 testdata/dac_file.cue create mode 100644 testdata/dac_folder/file.cue diff --git a/.github/workflows/test_percli_dac_build.yaml b/.github/workflows/test_percli_dac_build.yaml new file mode 100644 index 0000000..f98af03 --- /dev/null +++ b/.github/workflows/test_percli_dac_build.yaml @@ -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 diff --git a/actions/build_dac/action.yaml b/actions/build_dac/action.yaml new file mode 100644 index 0000000..97f1743 --- /dev/null +++ b/actions/build_dac/action.yaml @@ -0,0 +1,32 @@ +name: "Build the dashboards as code" +description: "Run the `dac build` command of percli to build the dashboards as code" +inputs: + directory: + description: Path to the directory containing the resources consumed by the command. + required: false + file: + description: Path to the file that contains the resources consumed by the command. + required: false +runs: + using: composite + steps: + - name: Validate inputs + run: | + if [[ -z "${{ inputs.directory }}" && -z "${{ inputs.file }}" ]]; then + echo "Error: Either 'directory' or 'file' must be provided." >&2 + exit 1 + fi + if [[ -n "${{ inputs.directory }}" && -n "${{ inputs.file }}" ]]; then + echo "Error: Only one of 'directory' or 'file' can be provided, not both." >&2 + exit 1 + fi + shell: bash + + - name: Run the `dac build` command + run: | + if [[ -n "${{ inputs.directory }}" ]]; then + percli dac build -d "${{ inputs.directory }}" + elif [[ -n "${{ inputs.file }}" ]]; then + percli dac build -f "${{ inputs.file }}" + fi + shell: bash diff --git a/testdata/dac_file.cue b/testdata/dac_file.cue new file mode 100644 index 0000000..f31332b --- /dev/null +++ b/testdata/dac_file.cue @@ -0,0 +1,3 @@ +package test + +success: true \ No newline at end of file diff --git a/testdata/dac_folder/file.cue b/testdata/dac_folder/file.cue new file mode 100644 index 0000000..f31332b --- /dev/null +++ b/testdata/dac_folder/file.cue @@ -0,0 +1,3 @@ +package test + +success: true \ No newline at end of file From 8dafcad5c9c301106dcfe1ce7e83578fb777d441 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Wed, 4 Dec 2024 16:05:45 +0100 Subject: [PATCH 02/33] Rename workflow file Signed-off-by: Antoine THEBAUD --- .../workflows/{test_percli_dac_build.yaml => test_build_dac.yaml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{test_percli_dac_build.yaml => test_build_dac.yaml} (100%) diff --git a/.github/workflows/test_percli_dac_build.yaml b/.github/workflows/test_build_dac.yaml similarity index 100% rename from .github/workflows/test_percli_dac_build.yaml rename to .github/workflows/test_build_dac.yaml From eef95a54b319bda0186cf25f7480f55bc86e630c Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Wed, 4 Dec 2024 16:24:28 +0100 Subject: [PATCH 03/33] add new action validate resources (1rst simple version) Signed-off-by: Antoine THEBAUD --- .github/workflows/test_validate_resource.yaml | 56 +++++++++++++++++++ actions/validate_resources/action.yaml | 32 +++++++++++ testdata/resource.json | 20 +++++++ testdata/resources_folder/dashboard.json | 20 +++++++ 4 files changed, 128 insertions(+) create mode 100644 .github/workflows/test_validate_resource.yaml create mode 100644 actions/validate_resources/action.yaml create mode 100644 testdata/resource.json create mode 100644 testdata/resources_folder/dashboard.json diff --git a/.github/workflows/test_validate_resource.yaml b/.github/workflows/test_validate_resource.yaml new file mode 100644 index 0000000..2984e64 --- /dev/null +++ b/.github/workflows/test_validate_resource.yaml @@ -0,0 +1,56 @@ +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 with directory + uses: ./actions/validate_resources + with: + directory: "./testdata/resources_folder" + + - name: Test resources validation with file + uses: ./actions/validate_resources + with: + file: "./testdata/resource.json" + + - name: Test resources validation with both inputs (should fail) + id: test_fail + uses: ./actions/validate_resources + with: + directory: "./testdata/resources_folder" + file: "./testdata/resource.json" + 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 diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml new file mode 100644 index 0000000..a48b2af --- /dev/null +++ b/actions/validate_resources/action.yaml @@ -0,0 +1,32 @@ +name: "Build the dashboards as code" +description: "Run the `lint` command of percli to validate the dashboards" +inputs: + directory: + description: Path to the directory containing the resources consumed by the command. + required: false + file: + description: Path to the file that contains the resources consumed by the command. + required: false +runs: + using: composite + steps: + - name: Validate inputs + run: | + if [[ -z "${{ inputs.directory }}" && -z "${{ inputs.file }}" ]]; then + echo "Error: Either 'directory' or 'file' must be provided." >&2 + exit 1 + fi + if [[ -n "${{ inputs.directory }}" && -n "${{ inputs.file }}" ]]; then + echo "Error: Only one of 'directory' or 'file' can be provided, not both." >&2 + exit 1 + fi + shell: bash + + - name: Run the `lint` command + run: | + if [[ -n "${{ inputs.directory }}" ]]; then + percli lint -d "${{ inputs.directory }}" + elif [[ -n "${{ inputs.file }}" ]]; then + percli lint -f "${{ inputs.file }}" + fi + shell: bash diff --git a/testdata/resource.json b/testdata/resource.json new file mode 100644 index 0000000..d087b6c --- /dev/null +++ b/testdata/resource.json @@ -0,0 +1,20 @@ +{ + "kind": "Dashboard", + "metadata": { + "name": "empty_dashboard", + "createdAt": "2024-12-04T15:08:03.737189012Z", + "updatedAt": "2024-12-04T15:08:03.737189012Z", + "version": 0, + "project": "perses" + }, + "spec": { + "display": { + "name": "Empty Dashboard" + }, + "panels": {}, + "layouts": [], + "variables": [], + "duration": "1h", + "refreshInterval": "0s" + } +} \ No newline at end of file diff --git a/testdata/resources_folder/dashboard.json b/testdata/resources_folder/dashboard.json new file mode 100644 index 0000000..d087b6c --- /dev/null +++ b/testdata/resources_folder/dashboard.json @@ -0,0 +1,20 @@ +{ + "kind": "Dashboard", + "metadata": { + "name": "empty_dashboard", + "createdAt": "2024-12-04T15:08:03.737189012Z", + "updatedAt": "2024-12-04T15:08:03.737189012Z", + "version": 0, + "project": "perses" + }, + "spec": { + "display": { + "name": "Empty Dashboard" + }, + "panels": {}, + "layouts": [], + "variables": [], + "duration": "1h", + "refreshInterval": "0s" + } +} \ No newline at end of file From 4805acf63d08a776d6db5c5847c609fd5563ab31 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Thu, 5 Dec 2024 13:09:16 +0100 Subject: [PATCH 04/33] Avoid doing checks already done by the CLI Signed-off-by: Antoine THEBAUD --- .github/workflows/test_build_dac.yaml | 8 ++++---- ...urce.yaml => test_validate_resources.yaml} | 0 actions/build_dac/action.yaml | 20 +++---------------- actions/validate_resources/action.yaml | 20 +++---------------- 4 files changed, 10 insertions(+), 38 deletions(-) rename .github/workflows/{test_validate_resource.yaml => test_validate_resources.yaml} (100%) diff --git a/.github/workflows/test_build_dac.yaml b/.github/workflows/test_build_dac.yaml index f98af03..5cef55d 100644 --- a/.github/workflows/test_build_dac.yaml +++ b/.github/workflows/test_build_dac.yaml @@ -31,19 +31,19 @@ jobs: - name: Test build DaC with directory uses: ./actions/build_dac with: - directory: "./testdata/dac_folder" + directory: ./testdata/dac_folder - name: Test build DaC with file uses: ./actions/build_dac with: - file: "./testdata/dac_file.cue" + 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" + directory: ./testdata/dac_folder + file: ./testdata/dac_file.cue continue-on-error: true - name: Validate failure for both inputs diff --git a/.github/workflows/test_validate_resource.yaml b/.github/workflows/test_validate_resources.yaml similarity index 100% rename from .github/workflows/test_validate_resource.yaml rename to .github/workflows/test_validate_resources.yaml diff --git a/actions/build_dac/action.yaml b/actions/build_dac/action.yaml index 97f1743..182515e 100644 --- a/actions/build_dac/action.yaml +++ b/actions/build_dac/action.yaml @@ -10,23 +10,9 @@ inputs: runs: using: composite steps: - - name: Validate inputs - run: | - if [[ -z "${{ inputs.directory }}" && -z "${{ inputs.file }}" ]]; then - echo "Error: Either 'directory' or 'file' must be provided." >&2 - exit 1 - fi - if [[ -n "${{ inputs.directory }}" && -n "${{ inputs.file }}" ]]; then - echo "Error: Only one of 'directory' or 'file' can be provided, not both." >&2 - exit 1 - fi - shell: bash - - name: Run the `dac build` command run: | - if [[ -n "${{ inputs.directory }}" ]]; then - percli dac build -d "${{ inputs.directory }}" - elif [[ -n "${{ inputs.file }}" ]]; then - percli dac build -f "${{ inputs.file }}" - fi + percli dac build \ + $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") shell: bash diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index a48b2af..a38df08 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -10,23 +10,9 @@ inputs: runs: using: composite steps: - - name: Validate inputs - run: | - if [[ -z "${{ inputs.directory }}" && -z "${{ inputs.file }}" ]]; then - echo "Error: Either 'directory' or 'file' must be provided." >&2 - exit 1 - fi - if [[ -n "${{ inputs.directory }}" && -n "${{ inputs.file }}" ]]; then - echo "Error: Only one of 'directory' or 'file' can be provided, not both." >&2 - exit 1 - fi - shell: bash - - name: Run the `lint` command run: | - if [[ -n "${{ inputs.directory }}" ]]; then - percli lint -d "${{ inputs.directory }}" - elif [[ -n "${{ inputs.file }}" ]]; then - percli lint -f "${{ inputs.file }}" - fi + percli lint \ + $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") shell: bash From abbd6c25f373448a52cee0d1b4cb2cea43ebd013 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Thu, 5 Dec 2024 14:20:01 +0100 Subject: [PATCH 05/33] remove useless quotes Signed-off-by: Antoine THEBAUD --- .github/workflows/test_build_dac.yaml | 2 +- .github/workflows/test_validate_resources.yaml | 10 +++++----- actions/build_dac/action.yaml | 4 ++-- actions/install_percli/action.yaml | 8 ++++---- actions/setup_environment/action.yaml | 10 +++++----- actions/validate_resources/action.yaml | 4 ++-- 6 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.github/workflows/test_build_dac.yaml b/.github/workflows/test_build_dac.yaml index 5cef55d..6980775 100644 --- a/.github/workflows/test_build_dac.yaml +++ b/.github/workflows/test_build_dac.yaml @@ -20,7 +20,7 @@ jobs: - name: Install percli uses: ./actions/install_percli with: - cli_version: "latest" + cli_version: latest - name: Install cue binary uses: ./actions/setup_environment diff --git a/.github/workflows/test_validate_resources.yaml b/.github/workflows/test_validate_resources.yaml index 2984e64..33b5926 100644 --- a/.github/workflows/test_validate_resources.yaml +++ b/.github/workflows/test_validate_resources.yaml @@ -20,7 +20,7 @@ jobs: - name: Install percli uses: ./actions/install_percli with: - cli_version: "latest" + cli_version: latest - name: Install cue binary uses: ./actions/setup_environment @@ -31,19 +31,19 @@ jobs: - name: Test resources validation with directory uses: ./actions/validate_resources with: - directory: "./testdata/resources_folder" + directory: ./testdata/resources_folder - name: Test resources validation with file uses: ./actions/validate_resources with: - file: "./testdata/resource.json" + file: ./testdata/resource.json - name: Test resources validation with both inputs (should fail) id: test_fail uses: ./actions/validate_resources with: - directory: "./testdata/resources_folder" - file: "./testdata/resource.json" + directory: ./testdata/resources_folder + file: ./testdata/resource.json continue-on-error: true - name: Validate failure for both inputs diff --git a/actions/build_dac/action.yaml b/actions/build_dac/action.yaml index 182515e..8f8d9eb 100644 --- a/actions/build_dac/action.yaml +++ b/actions/build_dac/action.yaml @@ -1,5 +1,5 @@ -name: "Build the dashboards as code" -description: "Run the `dac build` command of percli to build the dashboards as code" +name: Build the dashboards as code +description: Run the `dac build` command of percli to build the dashboards as code inputs: directory: description: Path to the directory containing the resources consumed by the command. diff --git a/actions/install_percli/action.yaml b/actions/install_percli/action.yaml index cb0546f..c1103ac 100644 --- a/actions/install_percli/action.yaml +++ b/actions/install_percli/action.yaml @@ -1,9 +1,9 @@ -name: "Install percli" -description: "Install the Perses CLI" +name: Install percli +description: Install the Perses CLI inputs: cli_version: - description: "Version of percli to install" - default: "latest" + description: Version of percli to install + default: latest runs: using: composite steps: diff --git a/actions/setup_environment/action.yaml b/actions/setup_environment/action.yaml index ee91962..e12bdf7 100644 --- a/actions/setup_environment/action.yaml +++ b/actions/setup_environment/action.yaml @@ -1,12 +1,12 @@ -name: "Setup environment" -description: "Setup GO or NPM environment" +name: Setup environment +description: Setup GO or NPM environment" inputs: enable_go: description: Whether to enable go specific features, such as caching. default: "false" go_version: description: The Go version to be used if Go is enable - default: "1.23.x" + default: 1.23.x enable_go_cache: description: Whether you want to cache the go dependencies default: "true" @@ -15,13 +15,13 @@ inputs: default: "false" cue_version: description: The Cue version to be used if Cue is enable - default: "v0.8.0" + default: v0.8.0 enable_npm: description: Whether to enable npm specific features, such as caching. default: "false" nvmrc_path: description: Path to the nvmrc file that contain the node version - default: ".nvmrc" + default: .nvmrc runs: using: composite steps: diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index a38df08..db70ab3 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -1,5 +1,5 @@ -name: "Build the dashboards as code" -description: "Run the `lint` command of percli to validate the dashboards" +name: Build the dashboards as code +description: Run the `lint` command of percli to validate the dashboards inputs: directory: description: Path to the directory containing the resources consumed by the command. From dbe98015edcbd36c660b6a063d77a25d08c5829a Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Thu, 5 Dec 2024 16:54:59 +0100 Subject: [PATCH 06/33] build dac + validate: add missing flags Signed-off-by: Antoine THEBAUD --- actions/build_dac/action.yaml | 10 +++++++++- actions/validate_resources/action.yaml | 6 +++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/actions/build_dac/action.yaml b/actions/build_dac/action.yaml index 8f8d9eb..ee3444e 100644 --- a/actions/build_dac/action.yaml +++ b/actions/build_dac/action.yaml @@ -7,6 +7,12 @@ inputs: file: description: Path to the file that contains the resources consumed by the command. required: false + mode: + description: Mode for the output. Must be either file to automatically save the content to file(s), or `stdout` to print on the standard output. (default "file") + required: false + output: + description: "Format of the output: json or yaml (default is yaml)." + required: false runs: using: composite steps: @@ -14,5 +20,7 @@ runs: run: | percli dac build \ $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ - $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ + $([[ -n "${{ inputs.mode }}" ]] && echo "-m ${{ inputs.mode }}") \ + $([[ -n "${{ inputs.output }}" ]] && echo "-o ${{ inputs.output }}") shell: bash diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index db70ab3..193c906 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -7,6 +7,9 @@ inputs: file: description: Path to the file that contains the resources consumed by the command. required: false + online: + description: When enabled, it can request the API to make additional validation. + required: false runs: using: composite steps: @@ -14,5 +17,6 @@ runs: run: | percli lint \ $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ - $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ + $([[ -n "${{ inputs.online }}" ]] && echo "--online ${{ inputs.online }}") shell: bash From 6db5e628949a97d5b64f5b05b0694b74f6fbf3e5 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 09:19:10 +0100 Subject: [PATCH 07/33] add new action to preview dashboards Signed-off-by: Antoine THEBAUD --- .github/workflows/test_preview_dac.yaml | 32 +++++++++++ actions/preview_dashboards/action.yaml | 70 +++++++++++++++++++++++++ 2 files changed, 102 insertions(+) create mode 100644 .github/workflows/test_preview_dac.yaml create mode 100644 actions/preview_dashboards/action.yaml diff --git a/.github/workflows/test_preview_dac.yaml b/.github/workflows/test_preview_dac.yaml new file mode 100644 index 0000000..94ead69 --- /dev/null +++ b/.github/workflows/test_preview_dac.yaml @@ -0,0 +1,32 @@ +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: Test dashboard preview + uses: ./actions/preview_dashboards + with: + url: https://demo.perses.dev + file: ./testdata/resources_folder/dashboard.json + username: test + password: test + diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml new file mode 100644 index 0000000..2569b86 --- /dev/null +++ b/actions/preview_dashboards/action.yaml @@ -0,0 +1,70 @@ +name: "Build the dashboards as code" +description: "Run the `dac preview` command of percli to preview the dashboards" +inputs: + url: + description: The URL of the Perses API server where to deploy the dashboard preview. + required: true + directory: + description: Path to the directory containing the resources consumed by the command. + required: false + file: + description: Path to the file that contains the resources consumed by the command. + required: false + username: + description: Username for basic authentication to the API server. + required: false + password: + description: Password for basic authentication to the API server. + required: false + token: + description: Bearer token for authentication to the API server. + required: false + provider: + description: External authentication provider identifier. (slug_id) + required: false + client-id: + description: Client ID used for robotic access when using external authentication provider. + required: false + client-secret: + description: Client Secret used for robotic access when using external authentication provider. + 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. + 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 + project: + description: If present, the project scope for this CLI request. + required: false + ttl: + description: Time To Live of the dashboard preview (default "1d"). + required: false +runs: + using: composite + steps: + - name: Login to the Perses API + run: | + percli login ${{ inputs.url }} \ + $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ + $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ + $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ + $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ + $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ + $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ + $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + shell: bash + + - name: Run the `dac preview` command + run: | + 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 }}") + shell: bash From 24a514ff48672aa72daac847fa265e40c18d1c42 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 09:26:03 +0100 Subject: [PATCH 08/33] Fix wrong names Signed-off-by: Antoine THEBAUD --- .../{test_preview_dac.yaml => test_preview_dashboards.yaml} | 0 actions/preview_dashboards/action.yaml | 4 ++-- actions/setup_environment/action.yaml | 2 +- actions/validate_resources/action.yaml | 4 ++-- 4 files changed, 5 insertions(+), 5 deletions(-) rename .github/workflows/{test_preview_dac.yaml => test_preview_dashboards.yaml} (100%) diff --git a/.github/workflows/test_preview_dac.yaml b/.github/workflows/test_preview_dashboards.yaml similarity index 100% rename from .github/workflows/test_preview_dac.yaml rename to .github/workflows/test_preview_dashboards.yaml diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 2569b86..4b333b8 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -1,5 +1,5 @@ -name: "Build the dashboards as code" -description: "Run the `dac preview` command of percli to preview the dashboards" +name: Preview dashboards +description: Run the `dac preview` command of percli to preview the dashboards inputs: url: description: The URL of the Perses API server where to deploy the dashboard preview. diff --git a/actions/setup_environment/action.yaml b/actions/setup_environment/action.yaml index e12bdf7..9ea7c38 100644 --- a/actions/setup_environment/action.yaml +++ b/actions/setup_environment/action.yaml @@ -1,5 +1,5 @@ name: Setup environment -description: Setup GO or NPM environment" +description: Setup GO or NPM environment inputs: enable_go: description: Whether to enable go specific features, such as caching. diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index 193c906..cc835e3 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -1,5 +1,5 @@ -name: Build the dashboards as code -description: Run the `lint` command of percli to validate the dashboards +name: Validate resources +description: Run the `lint` command of percli to validate Perses resources inputs: directory: description: Path to the directory containing the resources consumed by the command. From b8822c9fe25c7a145d4c472cad787839fcf61af3 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 09:39:40 +0100 Subject: [PATCH 09/33] add new action to diff dashboards Signed-off-by: Antoine THEBAUD --- .github/workflows/test_diff_dashboards.yaml | 32 ++++++++++++ actions/diff_dashboards/action.yaml | 58 +++++++++++++++++++++ 2 files changed, 90 insertions(+) create mode 100644 .github/workflows/test_diff_dashboards.yaml create mode 100644 actions/diff_dashboards/action.yaml diff --git a/.github/workflows/test_diff_dashboards.yaml b/.github/workflows/test_diff_dashboards.yaml new file mode 100644 index 0000000..63b0a11 --- /dev/null +++ b/.github/workflows/test_diff_dashboards.yaml @@ -0,0 +1,32 @@ +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: Test dashboard diff + uses: ./actions/diff_dashboards + with: + url: https://demo.perses.dev + directory: ./testdata/resources_folder + username: test + password: test + diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml new file mode 100644 index 0000000..7eb9056 --- /dev/null +++ b/actions/diff_dashboards/action.yaml @@ -0,0 +1,58 @@ +name: Build the dashboards as code +description: Run the `dac preview` command of percli to preview the dashboards +inputs: + url: + description: The URL of the Perses API server where to deploy the dashboard preview. + required: true + directory: + description: Path to the directory containing the resources consumed by the command. + required: false + file: + description: Path to the file that contains the resources consumed by the command. + required: false + username: + description: Username for basic authentication to the API server. + required: false + password: + description: Password for basic authentication to the API server. + required: false + token: + description: Bearer token for authentication to the API server. + required: false + provider: + description: External authentication provider identifier. (slug_id) + required: false + client-id: + description: Client ID used for robotic access when using external authentication provider. + required: false + client-secret: + description: Client Secret used for robotic access when using external authentication provider. + 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. + required: false + project: + description: If present, the project scope for this CLI request. + required: false +runs: + using: composite + steps: + - name: Login to the Perses API + run: | + percli login ${{ inputs.url }} \ + $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ + $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ + $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ + $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ + $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ + $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ + $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + shell: bash + + - name: Run the `dac diff` command + run: | + percli dac diff \ + $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ + $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") + shell: bash From 6f60ab37cb49b937b379402ae2e9c909108c1ac3 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 09:44:06 +0100 Subject: [PATCH 10/33] update some descriptions Signed-off-by: Antoine THEBAUD --- actions/diff_dashboards/action.yaml | 2 +- actions/preview_dashboards/action.yaml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 7eb9056..2da245f 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -1,5 +1,5 @@ name: Build the dashboards as code -description: Run the `dac preview` command of percli to preview the dashboards +description: Run the `dac diff` command of percli to generate diffs between the local dashboards and their remote counterparts on the API server inputs: url: description: The URL of the Perses API server where to deploy the dashboard preview. diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 4b333b8..b3fb046 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -1,5 +1,5 @@ name: Preview dashboards -description: Run the `dac preview` command of percli to preview the dashboards +description: Run the `dac preview` command of percli to deploy ephemeral dashboards to the API server inputs: url: description: The URL of the Perses API server where to deploy the dashboard preview. From 63f471571aa4f41b606d3d518e9ad7d2c0b64ce5 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 10:15:30 +0100 Subject: [PATCH 11/33] add new actions to apply resources Signed-off-by: Antoine THEBAUD --- .github/workflows/test_apply_resources.yaml | 32 +++++++++++ actions/apply_resources/action.yaml | 62 +++++++++++++++++++++ testdata/resource.json | 2 +- testdata/resources_folder/dashboard.json | 2 +- 4 files changed, 96 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test_apply_resources.yaml create mode 100644 actions/apply_resources/action.yaml diff --git a/.github/workflows/test_apply_resources.yaml b/.github/workflows/test_apply_resources.yaml new file mode 100644 index 0000000..c3dadee --- /dev/null +++ b/.github/workflows/test_apply_resources.yaml @@ -0,0 +1,32 @@ +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: Test apply resources + uses: ./actions/apply_resources + with: + url: https://demo.perses.dev + file: ./testdata/resources_folder/dashboard.json + username: test + password: test + diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml new file mode 100644 index 0000000..85f5a1f --- /dev/null +++ b/actions/apply_resources/action.yaml @@ -0,0 +1,62 @@ +name: Apply the resources +description: Run the `apply` command of percli to deploy Perses resources to the API server +inputs: + url: + description: The URL of the Perses API server where to deploy the dashboard preview. + required: true + directory: + description: Path to the directory containing the resources consumed by the command. + required: false + file: + description: Path to the file that contains the resources consumed by the command. + required: false + username: + description: Username for basic authentication to the API server. + required: false + password: + description: Password for basic authentication to the API server. + required: false + token: + description: Bearer token for authentication to the API server. + required: false + provider: + description: External authentication provider identifier. (slug_id) + required: false + client-id: + description: Client ID used for robotic access when using external authentication provider. + required: false + client-secret: + description: Client Secret used for robotic access when using external authentication provider. + 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. + required: false + project: + description: If present, the project scope for this CLI request. + required: false + force: + description: If present, the command will create the resource even if the projects are not consistent between the --project flag and the dashboard metadata (the latter has priority). + required: false +runs: + using: composite + steps: + - name: Login to the Perses API + run: | + percli login ${{ inputs.url }} \ + $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ + $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ + $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ + $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ + $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ + $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ + $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + shell: bash + + - name: Run the `apply` command + run: | + percli apply \ + $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ + $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ + $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") \ + $([[ -n "${{ inputs.force }}" ]] && echo "--project ${{ inputs.force }}") + shell: bash diff --git a/testdata/resource.json b/testdata/resource.json index d087b6c..fa26045 100644 --- a/testdata/resource.json +++ b/testdata/resource.json @@ -5,7 +5,7 @@ "createdAt": "2024-12-04T15:08:03.737189012Z", "updatedAt": "2024-12-04T15:08:03.737189012Z", "version": 0, - "project": "perses" + "project": "perses-github-actions" }, "spec": { "display": { diff --git a/testdata/resources_folder/dashboard.json b/testdata/resources_folder/dashboard.json index d087b6c..fa26045 100644 --- a/testdata/resources_folder/dashboard.json +++ b/testdata/resources_folder/dashboard.json @@ -5,7 +5,7 @@ "createdAt": "2024-12-04T15:08:03.737189012Z", "updatedAt": "2024-12-04T15:08:03.737189012Z", "version": 0, - "project": "perses" + "project": "perses-github-actions" }, "spec": { "display": { From 37f2120bebd58c9058c8e2dc93c13beedbda010d Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 6 Dec 2024 15:10:32 +0100 Subject: [PATCH 12/33] update file & dir inputs descs Signed-off-by: Antoine THEBAUD --- actions/apply_resources/action.yaml | 4 ++-- actions/build_dac/action.yaml | 4 ++-- actions/diff_dashboards/action.yaml | 4 ++-- actions/preview_dashboards/action.yaml | 4 ++-- actions/validate_resources/action.yaml | 4 ++-- 5 files changed, 10 insertions(+), 10 deletions(-) diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml index 85f5a1f..903d842 100644 --- a/actions/apply_resources/action.yaml +++ b/actions/apply_resources/action.yaml @@ -5,10 +5,10 @@ inputs: description: The URL of the Perses API server where to deploy the dashboard preview. required: true directory: - description: Path to the directory containing the resources consumed by the command. + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: - description: Path to the file that contains the resources consumed by the command. + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false username: description: Username for basic authentication to the API server. diff --git a/actions/build_dac/action.yaml b/actions/build_dac/action.yaml index ee3444e..075471f 100644 --- a/actions/build_dac/action.yaml +++ b/actions/build_dac/action.yaml @@ -2,10 +2,10 @@ name: Build the dashboards as code description: Run the `dac build` command of percli to build the dashboards as code inputs: directory: - description: Path to the directory containing the resources consumed by the command. + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: - description: Path to the file that contains the resources consumed by the command. + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false mode: description: Mode for the output. Must be either file to automatically save the content to file(s), or `stdout` to print on the standard output. (default "file") diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 2da245f..68796b0 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -5,10 +5,10 @@ inputs: description: The URL of the Perses API server where to deploy the dashboard preview. required: true directory: - description: Path to the directory containing the resources consumed by the command. + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: - description: Path to the file that contains the resources consumed by the command. + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false username: description: Username for basic authentication to the API server. diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index b3fb046..44e5b36 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -5,10 +5,10 @@ inputs: description: The URL of the Perses API server where to deploy the dashboard preview. required: true directory: - description: Path to the directory containing the resources consumed by the command. + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: - description: Path to the file that contains the resources consumed by the command. + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false username: description: Username for basic authentication to the API server. diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index cc835e3..3273fb9 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -2,10 +2,10 @@ name: Validate resources description: Run the `lint` command of percli to validate Perses resources inputs: directory: - description: Path to the directory containing the resources consumed by the command. + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: - description: Path to the file that contains the resources consumed by the command. + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false online: description: When enabled, it can request the API to make additional validation. From 089b4d841bdc4b27c8177aa4f068b21d3ea08fea Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Mon, 9 Dec 2024 18:34:31 +0100 Subject: [PATCH 13/33] 1rst working version for the merge main / deploy case Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 175 ++++++++++++++++++++++++++++ .github/workflows/test_dac.yaml | 23 ++++ actions/apply_resources/action.yaml | 2 +- testdata/dac_file.cue | 13 ++- testdata/dac_folder/file.cue | 13 ++- 5 files changed, 221 insertions(+), 5 deletions(-) create mode 100644 .github/workflows/dac.yaml create mode 100644 .github/workflows/test_dac.yaml diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml new file mode 100644 index 0000000..d732940 --- /dev/null +++ b/.github/workflows/dac.yaml @@ -0,0 +1,175 @@ +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: + online: + description: When enabled, it can request the API to make additional validation. + type: boolean + required: false + # preview-specific: + output: + description: "Format of the output: json or yaml (default is yaml)." + type: string + required: false + prefix: + description: If provided, it is used to prefix the dashboard preview name. + type: string + required: false + 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: Validate the dashboards + uses: ./actions/validate_resources + with: + directory: ./built + + # TODO append preview links to PR + - name: Preview the dashboards + if: ${{ !inputs.skip_preview }} + uses: ./actions/preview_dashboards + with: + # general: + url: ${{ inputs.url }} + directory: ./built + project: ${{ inputs.project }} + # auth: + 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 }} + # preview-specific + output: ${{ inputs.output }} + prefix: ${{ inputs.prefix }} + ttl: ${{ inputs.ttl }} + + # TODO append diff to PR + - name: Generate dashboards diffs + if: ${{ !inputs.skip_diff }} + uses: ./actions/diff_dashboards + with: + # general inputs: + url: ${{ inputs.url }} + directory: ./built + project: ${{ inputs.project }} + # auth inputs: + 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 }} + + # TODO skip deploy if pull request + - name: Deploy the dashboards + if: ${{ !inputs.skip_deploy }} + uses: ./actions/apply_resources + with: + # general: + url: ${{ inputs.url }} + directory: ./built + project: ${{ inputs.project }} + # auth: + 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 }} + # deploy-specific: + force: ${{ inputs.force }} diff --git a/.github/workflows/test_dac.yaml b/.github/workflows/test_dac.yaml new file mode 100644 index 0000000..c5735e2 --- /dev/null +++ b/.github/workflows/test_dac.yaml @@ -0,0 +1,23 @@ +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 + username: test + password: test + skip_preview: true + skip_diff: true \ No newline at end of file diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml index 903d842..f6f92f0 100644 --- a/actions/apply_resources/action.yaml +++ b/actions/apply_resources/action.yaml @@ -58,5 +58,5 @@ runs: $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") \ - $([[ -n "${{ inputs.force }}" ]] && echo "--project ${{ inputs.force }}") + $([[ "${{ inputs.force }}" == "true" ]] && echo "--force") shell: bash diff --git a/testdata/dac_file.cue b/testdata/dac_file.cue index f31332b..f271f12 100644 --- a/testdata/dac_file.cue +++ b/testdata/dac_file.cue @@ -1,3 +1,12 @@ -package test +package dac -success: true \ No newline at end of file +kind: "Dashboard" +metadata: { + name: "empty_dashboard", + project: "perses-github-actions" +}, +spec: { + display: name: "Empty Dashboard" + duration: "1h", + refreshInterval: "0s" +} \ No newline at end of file diff --git a/testdata/dac_folder/file.cue b/testdata/dac_folder/file.cue index f31332b..f271f12 100644 --- a/testdata/dac_folder/file.cue +++ b/testdata/dac_folder/file.cue @@ -1,3 +1,12 @@ -package test +package dac -success: true \ No newline at end of file +kind: "Dashboard" +metadata: { + name: "empty_dashboard", + project: "perses-github-actions" +}, +spec: { + display: name: "Empty Dashboard" + duration: "1h", + refreshInterval: "0s" +} \ No newline at end of file From b303ca395703f638744532d17b8952ad5b3bc12e Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Mon, 9 Dec 2024 18:34:50 +0100 Subject: [PATCH 14/33] fix skip-tls flag usage Signed-off-by: Antoine THEBAUD --- actions/apply_resources/action.yaml | 2 +- actions/diff_dashboards/action.yaml | 2 +- actions/preview_dashboards/action.yaml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml index f6f92f0..d89505d 100644 --- a/actions/apply_resources/action.yaml +++ b/actions/apply_resources/action.yaml @@ -49,7 +49,7 @@ runs: $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") shell: bash - name: Run the `apply` command diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 68796b0..c6bd907 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -46,7 +46,7 @@ runs: $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") shell: bash - name: Run the `dac diff` command diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 44e5b36..fee7bf6 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -55,7 +55,7 @@ runs: $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ -n "${{ inputs.insecure-skip-tls-verify }}" ]] && echo "--insecure-skip-tls-verify ${{ inputs.insecure-skip-tls-verify }}") + $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") shell: bash - name: Run the `dac preview` command From ff5c136d086494eab164552c8e368234d797b308 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Mon, 9 Dec 2024 18:40:45 +0100 Subject: [PATCH 15/33] Factorize login logic Signed-off-by: Antoine THEBAUD --- actions/apply_resources/action.yaml | 20 +++++------ actions/diff_dashboards/action.yaml | 20 +++++------ actions/login/action.yaml | 47 ++++++++++++++++++++++++++ actions/preview_dashboards/action.yaml | 20 +++++------ 4 files changed, 77 insertions(+), 30 deletions(-) create mode 100644 actions/login/action.yaml diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml index d89505d..b8c4772 100644 --- a/actions/apply_resources/action.yaml +++ b/actions/apply_resources/action.yaml @@ -41,16 +41,16 @@ runs: using: composite steps: - name: Login to the Perses API - run: | - percli login ${{ inputs.url }} \ - $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ - $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ - $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ - $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ - $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ - $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") - shell: bash + 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: Run the `apply` command run: | diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index c6bd907..b69356b 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -38,16 +38,16 @@ runs: using: composite steps: - name: Login to the Perses API - run: | - percli login ${{ inputs.url }} \ - $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ - $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ - $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ - $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ - $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ - $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") - shell: bash + 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: Run the `dac diff` command run: | diff --git a/actions/login/action.yaml b/actions/login/action.yaml new file mode 100644 index 0000000..ff5801f --- /dev/null +++ b/actions/login/action.yaml @@ -0,0 +1,47 @@ +name: Login to Perses +description: Run the `login` command of percli to authenticate to the API server +inputs: + url: + description: The URL of the Perses API server where to deploy the dashboard preview. + required: true + directory: + description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). + required: false + file: + description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). + required: false + username: + description: Username for basic authentication to the API server. + required: false + password: + description: Password for basic authentication to the API server. + required: false + token: + description: Bearer token for authentication to the API server. + required: false + provider: + description: External authentication provider identifier. (slug_id) + required: false + client-id: + description: Client ID used for robotic access when using external authentication provider. + required: false + client-secret: + description: Client Secret used for robotic access when using external authentication provider. + 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. + required: false +runs: + using: composite + steps: + - name: Login to the Perses API + run: | + percli login ${{ inputs.url }} \ + $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ + $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ + $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ + $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ + $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ + $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ + $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") + shell: bash \ No newline at end of file diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index fee7bf6..02755e9 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -47,16 +47,16 @@ runs: using: composite steps: - name: Login to the Perses API - run: | - percli login ${{ inputs.url }} \ - $([[ -n "${{ inputs.username }}" ]] && echo "-u ${{ inputs.username }}") \ - $([[ -n "${{ inputs.password }}" ]] && echo "-p ${{ inputs.password }}") \ - $([[ -n "${{ inputs.token }}" ]] && echo "--token ${{ inputs.token }}") \ - $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ - $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ - $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") - shell: bash + 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: Run the `dac preview` command run: | From 58b87cc97768f5daa00facb7cdbb121ae2401dcd Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 11:42:01 +0100 Subject: [PATCH 16/33] Move login to a dedicated action Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 40 +++++++------------------- actions/apply_resources/action.yaml | 40 ++------------------------ actions/diff_dashboards/action.yaml | 40 ++------------------------ actions/login/action.yaml | 8 +----- actions/preview_dashboards/action.yaml | 40 ++------------------------ actions/validate_resources/action.yaml | 4 ++- 6 files changed, 23 insertions(+), 149 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index d732940..c7ce1b4 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -114,16 +114,10 @@ jobs: with: directory: ./built - # TODO append preview links to PR - - name: Preview the dashboards - if: ${{ !inputs.skip_preview }} - uses: ./actions/preview_dashboards + - name: Login to the API server + uses: ./actions/login with: - # general: url: ${{ inputs.url }} - directory: ./built - project: ${{ inputs.project }} - # auth: username: ${{ inputs.username }} password: ${{ inputs.password }} token: ${{ inputs.token }} @@ -131,7 +125,14 @@ jobs: client-id: ${{ inputs.client-id }} client-secret: ${{ inputs.client-secret }} insecure-skip-tls-verify: ${{ inputs.insecure-skip-tls-verify }} - # preview-specific + + # TODO append preview links to PR + - name: Preview the dashboards + if: ${{ !inputs.skip_preview }} + uses: ./actions/preview_dashboards + with: + directory: ./built + project: ${{ inputs.project }} output: ${{ inputs.output }} prefix: ${{ inputs.prefix }} ttl: ${{ inputs.ttl }} @@ -141,35 +142,14 @@ jobs: if: ${{ !inputs.skip_diff }} uses: ./actions/diff_dashboards with: - # general inputs: - url: ${{ inputs.url }} directory: ./built project: ${{ inputs.project }} - # auth inputs: - 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 }} # TODO skip deploy if pull request - name: Deploy the dashboards if: ${{ !inputs.skip_deploy }} uses: ./actions/apply_resources with: - # general: - url: ${{ inputs.url }} directory: ./built project: ${{ inputs.project }} - # auth: - 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 }} - # deploy-specific: force: ${{ inputs.force }} diff --git a/actions/apply_resources/action.yaml b/actions/apply_resources/action.yaml index b8c4772..2a3dd12 100644 --- a/actions/apply_resources/action.yaml +++ b/actions/apply_resources/action.yaml @@ -1,36 +1,14 @@ name: Apply the resources -description: Run the `apply` command of percli to deploy Perses resources to the API server +description: | + Run the `apply` command of percli to deploy Perses resources to the API server + **Note:** Login to an API server is required before running this action. You can use the provided `login` action for this purpose. inputs: - url: - description: The URL of the Perses API server where to deploy the dashboard preview. - required: true directory: description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false - username: - description: Username for basic authentication to the API server. - required: false - password: - description: Password for basic authentication to the API server. - required: false - token: - description: Bearer token for authentication to the API server. - required: false - provider: - description: External authentication provider identifier. (slug_id) - required: false - client-id: - description: Client ID used for robotic access when using external authentication provider. - required: false - client-secret: - description: Client Secret used for robotic access when using external authentication provider. - 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. - required: false project: description: If present, the project scope for this CLI request. required: false @@ -40,18 +18,6 @@ inputs: runs: using: composite steps: - - name: Login to the Perses API - 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: Run the `apply` command run: | percli apply \ diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index b69356b..0a77c25 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -1,54 +1,20 @@ name: Build the dashboards as code -description: Run the `dac diff` command of percli to generate diffs between the local dashboards and their remote counterparts on the API server +description: | + Run the `dac diff` command of percli to generate diffs between the local dashboards and their remote counterparts on the API server. + **Note:** Login to an API server is required before running this action. You can use the provided `login` action for this purpose. inputs: - url: - description: The URL of the Perses API server where to deploy the dashboard preview. - required: true directory: description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false - username: - description: Username for basic authentication to the API server. - required: false - password: - description: Password for basic authentication to the API server. - required: false - token: - description: Bearer token for authentication to the API server. - required: false - provider: - description: External authentication provider identifier. (slug_id) - required: false - client-id: - description: Client ID used for robotic access when using external authentication provider. - required: false - client-secret: - description: Client Secret used for robotic access when using external authentication provider. - 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. - required: false project: description: If present, the project scope for this CLI request. required: false runs: using: composite steps: - - name: Login to the Perses API - 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: Run the `dac diff` command run: | percli dac diff \ diff --git a/actions/login/action.yaml b/actions/login/action.yaml index ff5801f..6e2b0b0 100644 --- a/actions/login/action.yaml +++ b/actions/login/action.yaml @@ -2,14 +2,8 @@ name: Login to Perses description: Run the `login` command of percli to authenticate to the API server inputs: url: - description: The URL of the Perses API server where to deploy the dashboard preview. + description: The URL of the Perses API server. required: true - directory: - description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). - required: false - file: - description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). - required: false username: description: Username for basic authentication to the API server. required: false diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 02755e9..24fda7f 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -1,36 +1,14 @@ name: Preview dashboards -description: Run the `dac preview` command of percli to deploy ephemeral dashboards to the API server +description: | + Run the `dac preview` command of percli to deploy ephemeral dashboards to the API server + **Note:** Login to an API server is required before running this action. You can use the provided `login` action for this purpose. inputs: - url: - description: The URL of the Perses API server where to deploy the dashboard preview. - required: true directory: description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). required: false file: description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false - username: - description: Username for basic authentication to the API server. - required: false - password: - description: Password for basic authentication to the API server. - required: false - token: - description: Bearer token for authentication to the API server. - required: false - provider: - description: External authentication provider identifier. (slug_id) - required: false - client-id: - description: Client ID used for robotic access when using external authentication provider. - required: false - client-secret: - description: Client Secret used for robotic access when using external authentication provider. - 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. - required: false output: description: "Format of the output: json or yaml (default is yaml)." required: false @@ -46,18 +24,6 @@ inputs: runs: using: composite steps: - - name: Login to the Perses API - 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: Run the `dac preview` command run: | percli dac preview \ diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index 3273fb9..28fc277 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -1,5 +1,7 @@ name: Validate resources -description: Run the `lint` command of percli to validate Perses resources +description: | + Run the `lint` command of percli to validate Perses resources + **Note:** In online mode, login to an API server is required before running this action. You can use the provided `login` action for this purpose. inputs: directory: description: Path to the directory containing the resources consumed by the command (mutually exclusive with `file`). From 6e9c322a4825dd4cefc73832fc05e1887354017a Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 12:06:27 +0100 Subject: [PATCH 17/33] Add conditions to change behavior between PR vs main branch Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index c7ce1b4..c819996 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -128,7 +128,7 @@ jobs: # TODO append preview links to PR - name: Preview the dashboards - if: ${{ !inputs.skip_preview }} + if: ${{ github.event_name == 'pull_request' && !inputs.skip_preview }} uses: ./actions/preview_dashboards with: directory: ./built @@ -139,15 +139,14 @@ jobs: # TODO append diff to PR - name: Generate dashboards diffs - if: ${{ !inputs.skip_diff }} + if: ${{ github.event_name == 'pull_request' && !inputs.skip_diff }} uses: ./actions/diff_dashboards with: directory: ./built project: ${{ inputs.project }} - # TODO skip deploy if pull request - name: Deploy the dashboards - if: ${{ !inputs.skip_deploy }} + if: ${{ github.event_name != 'pull_request' && !inputs.skip_deploy }} uses: ./actions/apply_resources with: directory: ./built From 2b6dc4c5b68fd7c26277844c2510162449d18c22 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 12:20:46 +0100 Subject: [PATCH 18/33] Add login step in individual tests that require it Signed-off-by: Antoine THEBAUD --- .github/workflows/test_apply_resources.yaml | 10 ++++++--- .github/workflows/test_diff_dashboards.yaml | 9 +++++--- .../workflows/test_preview_dashboards.yaml | 9 +++++--- .../workflows/test_validate_resources.yaml | 21 ++----------------- 4 files changed, 21 insertions(+), 28 deletions(-) diff --git a/.github/workflows/test_apply_resources.yaml b/.github/workflows/test_apply_resources.yaml index c3dadee..28702f1 100644 --- a/.github/workflows/test_apply_resources.yaml +++ b/.github/workflows/test_apply_resources.yaml @@ -22,11 +22,15 @@ jobs: with: cli_version: "latest" - - name: Test apply resources - uses: ./actions/apply_resources + - name: Login to the API server + uses: ./actions/login with: url: https://demo.perses.dev - file: ./testdata/resources_folder/dashboard.json username: test password: test + - name: Test apply resources + uses: ./actions/apply_resources + with: + file: ./testdata/resources_folder/dashboard.json + diff --git a/.github/workflows/test_diff_dashboards.yaml b/.github/workflows/test_diff_dashboards.yaml index 63b0a11..5f129e7 100644 --- a/.github/workflows/test_diff_dashboards.yaml +++ b/.github/workflows/test_diff_dashboards.yaml @@ -22,11 +22,14 @@ jobs: with: cli_version: "latest" - - name: Test dashboard diff - uses: ./actions/diff_dashboards + - name: Login to the API server + uses: ./actions/login with: url: https://demo.perses.dev - directory: ./testdata/resources_folder username: test password: test + - name: Test dashboard diff + uses: ./actions/diff_dashboards + with: + directory: ./testdata/resources_folder \ No newline at end of file diff --git a/.github/workflows/test_preview_dashboards.yaml b/.github/workflows/test_preview_dashboards.yaml index 94ead69..99bd1b2 100644 --- a/.github/workflows/test_preview_dashboards.yaml +++ b/.github/workflows/test_preview_dashboards.yaml @@ -22,11 +22,14 @@ jobs: with: cli_version: "latest" - - name: Test dashboard preview - uses: ./actions/preview_dashboards + - name: Login to the API server + uses: ./actions/login with: url: https://demo.perses.dev - file: ./testdata/resources_folder/dashboard.json username: test password: test + - name: Test dashboard preview + uses: ./actions/preview_dashboards + with: + file: ./testdata/resources_folder/dashboard.json \ No newline at end of file diff --git a/.github/workflows/test_validate_resources.yaml b/.github/workflows/test_validate_resources.yaml index 33b5926..30d513f 100644 --- a/.github/workflows/test_validate_resources.yaml +++ b/.github/workflows/test_validate_resources.yaml @@ -28,7 +28,7 @@ jobs: enable_go: true enable_cue: true - - name: Test resources validation with directory + - name: Test resources validation uses: ./actions/validate_resources with: directory: ./testdata/resources_folder @@ -36,21 +36,4 @@ jobs: - name: Test resources validation with file uses: ./actions/validate_resources with: - file: ./testdata/resource.json - - - name: Test resources validation with both inputs (should fail) - id: test_fail - uses: ./actions/validate_resources - with: - directory: ./testdata/resources_folder - file: ./testdata/resource.json - 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 + file: ./testdata/resource.json \ No newline at end of file From aad1ef3168300c821a9b2b39e4ec623528e01a3d Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 13:38:14 +0100 Subject: [PATCH 19/33] Post preview comment (+ remove configurable output format) Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 7 +------ actions/preview_dashboards/action.yaml | 24 +++++++++++++++++++----- 2 files changed, 20 insertions(+), 11 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index c819996..3b4b47c 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -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 @@ -133,7 +129,6 @@ jobs: with: directory: ./built project: ${{ inputs.project }} - output: ${{ inputs.output }} prefix: ${{ inputs.prefix }} ttl: ${{ inputs.ttl }} diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 24fda7f..995bf53 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -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 @@ -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 ephemeral dashboards have been deployed:\n\n${previewLinks}`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody + }); \ No newline at end of file From 146bd3dd8a53079305fdcdcd8e8b1928280f2987 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 13:43:14 +0100 Subject: [PATCH 20/33] preview: replace configurable prefix by PR number Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 5 ----- actions/preview_dashboards/action.yaml | 7 ++----- 2 files changed, 2 insertions(+), 10 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index 3b4b47c..f667152 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -67,10 +67,6 @@ on: type: boolean required: false # preview-specific: - 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 ttl: description: Time To Live of the dashboard preview (default "1d"). type: string @@ -129,7 +125,6 @@ jobs: with: directory: ./built project: ${{ inputs.project }} - prefix: ${{ inputs.prefix }} ttl: ${{ inputs.ttl }} # TODO append diff to PR diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 995bf53..69890ba 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -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 - prefix: - description: If provided, it is used to prefix the dashboard preview name. - required: false project: description: If present, the project scope for this CLI request. required: false @@ -26,9 +23,9 @@ runs: percli dac preview \ $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ - $([[ -n "${{ inputs.prefix }}" ]] && echo "--prefix ${{ inputs.prefix }}") \ $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") \ $([[ -n "${{ inputs.ttl }}" ]] && echo "--ttl ${{ inputs.ttl }}") \ + --prefix "PR-${{ github.event.pull_request.number }}" \ -o json \ > preview_output.json shell: bash @@ -47,4 +44,4 @@ runs: repo: context.repo.repo, issue_number: context.issue.number, body: commentBody - }); \ No newline at end of file + }); From b5a4888d25c9e8c975c2a9b1b77388e5bb191329 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 14:38:33 +0100 Subject: [PATCH 21/33] Preview: bring back configurable prefix in action + pass github PR number to it in workflow Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 2 +- .github/workflows/test_dac.yaml | 1 - .github/workflows/test_preview_dashboards.yaml | 3 ++- actions/preview_dashboards/action.yaml | 7 +++++-- 4 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index f667152..a354065 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -118,13 +118,13 @@ jobs: client-secret: ${{ inputs.client-secret }} insecure-skip-tls-verify: ${{ inputs.insecure-skip-tls-verify }} - # TODO append preview links to PR - 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 }} # TODO append diff to PR diff --git a/.github/workflows/test_dac.yaml b/.github/workflows/test_dac.yaml index c5735e2..3093fab 100644 --- a/.github/workflows/test_dac.yaml +++ b/.github/workflows/test_dac.yaml @@ -19,5 +19,4 @@ jobs: directory: ./testdata/dac_folder username: test password: test - skip_preview: true skip_diff: true \ No newline at end of file diff --git a/.github/workflows/test_preview_dashboards.yaml b/.github/workflows/test_preview_dashboards.yaml index 99bd1b2..d3d29ba 100644 --- a/.github/workflows/test_preview_dashboards.yaml +++ b/.github/workflows/test_preview_dashboards.yaml @@ -32,4 +32,5 @@ jobs: - name: Test dashboard preview uses: ./actions/preview_dashboards with: - file: ./testdata/resources_folder/dashboard.json \ No newline at end of file + file: ./testdata/resources_folder/dashboard.json + prefix: test-preview \ No newline at end of file diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 69890ba..995bf53 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -9,6 +9,9 @@ inputs: file: description: Path to the file that contains the resources consumed by the command (mutually exclusive with `directory`). required: false + prefix: + description: If provided, it is used to prefix the dashboard preview name. + required: false project: description: If present, the project scope for this CLI request. required: false @@ -23,9 +26,9 @@ runs: percli dac preview \ $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ + $([[ -n "${{ inputs.prefix }}" ]] && echo "--prefix ${{ inputs.prefix }}") \ $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") \ $([[ -n "${{ inputs.ttl }}" ]] && echo "--ttl ${{ inputs.ttl }}") \ - --prefix "PR-${{ github.event.pull_request.number }}" \ -o json \ > preview_output.json shell: bash @@ -44,4 +47,4 @@ runs: repo: context.repo.repo, issue_number: context.issue.number, body: commentBody - }); + }); \ No newline at end of file From 7a2015bc8fbc2c94d8ea0e0f23437f7a3ef081f2 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 16:03:12 +0100 Subject: [PATCH 22/33] Fix diff Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 1 - actions/diff_dashboards/action.yaml | 8 +++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index a354065..afab0c8 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -127,7 +127,6 @@ jobs: prefix: ${{ github.event.pull_request.number }} ttl: ${{ inputs.ttl }} - # TODO append diff to PR - name: Generate dashboards diffs if: ${{ github.event_name == 'pull_request' && !inputs.skip_diff }} uses: ./actions/diff_dashboards diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 0a77c25..92783a1 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -1,4 +1,4 @@ -name: Build the dashboards as code +name: Diff dashboards description: | Run the `dac diff` command of percli to generate diffs between the local dashboards and their remote counterparts on the API server. **Note:** Login to an API server is required before running this action. You can use the provided `login` action for this purpose. @@ -15,6 +15,12 @@ inputs: runs: using: composite steps: + - name: Create the output folder + run: | + # Remove this step when a release embedding https://github.com/perses/perses/pull/2484 is available. + mkdir built + shell: bash + - name: Run the `dac diff` command run: | percli dac diff \ From 155cb252b7d967f42ad7eff7c6187b5d4798c9fa Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 16:21:55 +0100 Subject: [PATCH 23/33] diff: upload diff files as artifacts Signed-off-by: Antoine THEBAUD --- actions/diff_dashboards/action.yaml | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 92783a1..ee38b1a 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -28,3 +28,25 @@ runs: $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") shell: bash + + - name: Upload diffs as artifacts + uses: actions/upload-artifact@v4 + with: + name: dashboard-diffs + path: built/ + + - name: Post artifacts link to PR + if: ${{ github.event_name == 'pull_request' }} + uses: actions/github-script@v7 + with: + script: | + const runId = process.env.GITHUB_RUN_ID; + const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; + const artifactUrl = `${repoUrl}/actions/runs/${runId}`; + const commentBody = `### Dashboard Diffs\nThe dashboard diffs have been uploaded as an artifact.\n\n[Download Artifact](artifactUrl)`; + github.rest.issues.createComment({ + owner: context.repo.owner, + repo: context.repo.repo, + issue_number: context.issue.number, + body: commentBody.replace('artifactUrl', artifactUrl) + }); \ No newline at end of file From 20f915235186d163698737ad0dc0c4c8010768aa Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 16:22:04 +0100 Subject: [PATCH 24/33] update gitignore Signed-off-by: Antoine THEBAUD --- .gitignore | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.gitignore b/.gitignore index 303463c..8512a60 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,7 @@ # System Files .DS_Store -Thumbs.db \ No newline at end of file +Thumbs.db + +# DaC-generated +built \ No newline at end of file From e47bee3587eab42baff553e382c4198c31810551 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 16:22:19 +0100 Subject: [PATCH 25/33] bump github-script version used Signed-off-by: Antoine THEBAUD --- actions/preview_dashboards/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/preview_dashboards/action.yaml b/actions/preview_dashboards/action.yaml index 995bf53..38ae215 100644 --- a/actions/preview_dashboards/action.yaml +++ b/actions/preview_dashboards/action.yaml @@ -35,7 +35,7 @@ runs: - name: Post preview links to PR if: ${{ github.event_name == 'pull_request' }} - uses: actions/github-script@v6 + uses: actions/github-script@v7 with: script: | const fs = require('fs'); From d039a3ae735ade2ee85cfa809bef0e1d4f379d9f Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 16:40:34 +0100 Subject: [PATCH 26/33] Update diff message Signed-off-by: Antoine THEBAUD --- actions/diff_dashboards/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index ee38b1a..cfc518e 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -43,7 +43,7 @@ runs: const runId = process.env.GITHUB_RUN_ID; const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; const artifactUrl = `${repoUrl}/actions/runs/${runId}`; - const commentBody = `### Dashboard Diffs\nThe dashboard diffs have been uploaded as an artifact.\n\n[Download Artifact](artifactUrl)`; + const commentBody = `### Dashboard diffs\nThe dashboard diffs can be downloaded from the [workflow artifacts](artifactUrl).`; github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, From 739bd9a92908c9231dd9ca796d1947046083b125 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 18:15:51 +0100 Subject: [PATCH 27/33] Fix online validation Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 15 ++++++++------- .github/workflows/test_dac.yaml | 1 + actions/login/action.yaml | 2 +- actions/validate_resources/action.yaml | 2 +- 4 files changed, 11 insertions(+), 9 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index afab0c8..3dffc12 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -62,8 +62,8 @@ on: type: string required: false # validate-specific: - online: - description: When enabled, it can request the API to make additional validation. + server-validation: + description: When enabled, requests the API to make additional validation. type: boolean required: false # preview-specific: @@ -101,11 +101,6 @@ jobs: directory: ${{ inputs.directory }} file: ${{ inputs.file }} - - name: Validate the dashboards - uses: ./actions/validate_resources - with: - directory: ./built - - name: Login to the API server uses: ./actions/login with: @@ -118,6 +113,12 @@ jobs: 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 diff --git a/.github/workflows/test_dac.yaml b/.github/workflows/test_dac.yaml index 3093fab..66299d7 100644 --- a/.github/workflows/test_dac.yaml +++ b/.github/workflows/test_dac.yaml @@ -17,6 +17,7 @@ jobs: with: url: https://demo.perses.dev directory: ./testdata/dac_folder + server-validation: true username: test password: test skip_diff: true \ No newline at end of file diff --git a/actions/login/action.yaml b/actions/login/action.yaml index 6e2b0b0..170c7a2 100644 --- a/actions/login/action.yaml +++ b/actions/login/action.yaml @@ -37,5 +37,5 @@ runs: $([[ -n "${{ inputs.provider }}" ]] && echo "--provider ${{ inputs.provider }}") \ $([[ -n "${{ inputs.client-id }}" ]] && echo "--client-id ${{ inputs.client-id }}") \ $([[ -n "${{ inputs.client-secret }}" ]] && echo "--client-secret ${{ inputs.client-secret }}") \ - $([[ "${{ inputs.insecure-skip-tls-verify}}" == "true" ]] && echo "--insecure-skip-tls-verify") + $([[ "${{ inputs.insecure-skip-tls-verify }}" == "true" ]] && echo "--insecure-skip-tls-verify") shell: bash \ No newline at end of file diff --git a/actions/validate_resources/action.yaml b/actions/validate_resources/action.yaml index 28fc277..32c357a 100644 --- a/actions/validate_resources/action.yaml +++ b/actions/validate_resources/action.yaml @@ -20,5 +20,5 @@ runs: percli lint \ $([[ -n "${{ inputs.directory }}" ]] && echo "-d ${{ inputs.directory }}") \ $([[ -n "${{ inputs.file }}" ]] && echo "-f ${{ inputs.file }}") \ - $([[ -n "${{ inputs.online }}" ]] && echo "--online ${{ inputs.online }}") + $([[ "${{ inputs.online }}" == "true" ]] && echo "--online") shell: bash From 22270bfb9175e4dfeca5e030c7f03c8a1d5d934e Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 18:42:36 +0100 Subject: [PATCH 28/33] dont skip diff in DaC test Signed-off-by: Antoine THEBAUD --- .github/workflows/test_dac.yaml | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/.github/workflows/test_dac.yaml b/.github/workflows/test_dac.yaml index 66299d7..340e731 100644 --- a/.github/workflows/test_dac.yaml +++ b/.github/workflows/test_dac.yaml @@ -19,5 +19,4 @@ jobs: directory: ./testdata/dac_folder server-validation: true username: test - password: test - skip_diff: true \ No newline at end of file + password: test \ No newline at end of file From c5380dbf6b9f0afcf16af5261271790e1a8ac47e Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Tue, 10 Dec 2024 18:48:14 +0100 Subject: [PATCH 29/33] fix diff stage Signed-off-by: Antoine THEBAUD --- actions/diff_dashboards/action.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index cfc518e..489f379 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -18,7 +18,7 @@ runs: - name: Create the output folder run: | # Remove this step when a release embedding https://github.com/perses/perses/pull/2484 is available. - mkdir built + mkdir -p built shell: bash - name: Run the `dac diff` command From b0edc842493656315a097d5a781b72a17128dff5 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Wed, 11 Dec 2024 09:29:59 +0100 Subject: [PATCH 30/33] Deploy if default branch Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index 3dffc12..632ed81 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -136,7 +136,7 @@ jobs: project: ${{ inputs.project }} - name: Deploy the dashboards - if: ${{ github.event_name != 'pull_request' && !inputs.skip_deploy }} + if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !inputs.skip_deploy }} uses: ./actions/apply_resources with: directory: ./built From c70b6ae375ee15c2633ab6c7c214eb1fe2d636c8 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Wed, 11 Dec 2024 14:43:42 +0100 Subject: [PATCH 31/33] consistent naming convention for inputs Signed-off-by: Antoine THEBAUD --- .github/workflows/dac.yaml | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/.github/workflows/dac.yaml b/.github/workflows/dac.yaml index 632ed81..4967217 100644 --- a/.github/workflows/dac.yaml +++ b/.github/workflows/dac.yaml @@ -20,15 +20,15 @@ on: type: string required: false # skip: - skip_preview: + skip-preview: description: Skip the dashboard preview stage if provided. type: boolean required: false - skip_diff: + skip-diff: description: Skip the dashboard diff generation stage if provided. type: boolean required: false - skip_deploy: + skip-deploy: description: Skip the dashboard deployment stage if provided. type: boolean required: false @@ -120,7 +120,7 @@ jobs: online: ${{ inputs.server-validation }} - name: Preview the dashboards - if: ${{ github.event_name == 'pull_request' && !inputs.skip_preview }} + if: ${{ github.event_name == 'pull_request' && !inputs.skip-preview }} uses: ./actions/preview_dashboards with: directory: ./built @@ -129,14 +129,14 @@ jobs: ttl: ${{ inputs.ttl }} - name: Generate dashboards diffs - if: ${{ github.event_name == 'pull_request' && !inputs.skip_diff }} + 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 }} + if: ${{ github.ref == format('refs/heads/{0}', github.event.repository.default_branch) && !inputs.skip-deploy }} uses: ./actions/apply_resources with: directory: ./built From 939f22c23d60764db65c7379d87e33201d74a9de Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Thu, 12 Dec 2024 15:33:21 +0100 Subject: [PATCH 32/33] Improve diff output Signed-off-by: Antoine THEBAUD --- actions/diff_dashboards/action.yaml | 52 ++++++++++++++++++++++------- 1 file changed, 40 insertions(+), 12 deletions(-) diff --git a/actions/diff_dashboards/action.yaml b/actions/diff_dashboards/action.yaml index 489f379..de35744 100644 --- a/actions/diff_dashboards/action.yaml +++ b/actions/diff_dashboards/action.yaml @@ -29,24 +29,52 @@ runs: $([[ -n "${{ inputs.project }}" ]] && echo "--project ${{ inputs.project }}") shell: bash - - name: Upload diffs as artifacts - uses: actions/upload-artifact@v4 - with: - name: dashboard-diffs - path: built/ - - - name: Post artifacts link to PR + - name: Post diffs as PR comments if: ${{ github.event_name == 'pull_request' }} uses: actions/github-script@v7 with: script: | - const runId = process.env.GITHUB_RUN_ID; - const repoUrl = `https://github.com/${context.repo.owner}/${context.repo.repo}`; - const artifactUrl = `${repoUrl}/actions/runs/${runId}`; - const commentBody = `### Dashboard diffs\nThe dashboard diffs can be downloaded from the [workflow artifacts](artifactUrl).`; + const fs = require('fs'); + const path = require('path'); + + // Directory containing the diff files + const diffDir = './built'; + + // Filter files to include only those with a `.diff` extension + const diffFiles = fs.readdirSync(diffDir).filter(file => file.endsWith('.diff')); + + if (diffFiles.length === 0) { + console.log('No diff files found to comment.'); + return; + } + + // Generate the PR comment with collapsible sections + let commentBody = `### Dashboard diffs\n\n`; + for (const file of diffFiles) { + const filePath = path.join(diffDir, file); + const diffContent = fs.readFileSync(filePath, 'utf-8').trim(); + + if (diffContent) { + // Include a collapsible section for non-empty diffs + commentBody += ` +
+ ${path.basename(file, '.diff')}: + + \`\`\`diff + ${diffContent} + \`\`\` +
\n\n + `; + } else { + // Add a plain "No change" message for empty diffs + commentBody += `⯈ ${path.basename(file, '.diff')}:\n*No change*\n\n`; + } + } + + // Post the comment github.rest.issues.createComment({ owner: context.repo.owner, repo: context.repo.repo, issue_number: context.issue.number, - body: commentBody.replace('artifactUrl', artifactUrl) + body: commentBody.trim() // Ensure no trailing newlines }); \ No newline at end of file From 17c86853639bb7ffa17e1086ad1f2f9342fd89a8 Mon Sep 17 00:00:00 2001 From: Antoine THEBAUD Date: Fri, 13 Dec 2024 09:53:43 +0100 Subject: [PATCH 33/33] change creds to secrets Signed-off-by: Antoine THEBAUD --- .github/workflows/test_apply_resources.yaml | 4 ++-- .github/workflows/test_dac.yaml | 4 ++-- .github/workflows/test_diff_dashboards.yaml | 4 ++-- .github/workflows/test_preview_dashboards.yaml | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.github/workflows/test_apply_resources.yaml b/.github/workflows/test_apply_resources.yaml index 28702f1..1e82bc4 100644 --- a/.github/workflows/test_apply_resources.yaml +++ b/.github/workflows/test_apply_resources.yaml @@ -26,8 +26,8 @@ jobs: uses: ./actions/login with: url: https://demo.perses.dev - username: test - password: test + username: ${{ secrets.TEST_USERNAME }} + password: ${{ secrets.TEST_PASSWORD }} - name: Test apply resources uses: ./actions/apply_resources diff --git a/.github/workflows/test_dac.yaml b/.github/workflows/test_dac.yaml index 340e731..079523f 100644 --- a/.github/workflows/test_dac.yaml +++ b/.github/workflows/test_dac.yaml @@ -18,5 +18,5 @@ jobs: url: https://demo.perses.dev directory: ./testdata/dac_folder server-validation: true - username: test - password: test \ No newline at end of file + username: ${{ secrets.TEST_USERNAME }} + password: ${{ secrets.TEST_PASSWORD }} \ No newline at end of file diff --git a/.github/workflows/test_diff_dashboards.yaml b/.github/workflows/test_diff_dashboards.yaml index 5f129e7..314e3d8 100644 --- a/.github/workflows/test_diff_dashboards.yaml +++ b/.github/workflows/test_diff_dashboards.yaml @@ -26,8 +26,8 @@ jobs: uses: ./actions/login with: url: https://demo.perses.dev - username: test - password: test + username: ${{ secrets.TEST_USERNAME }} + password: ${{ secrets.TEST_PASSWORD }} - name: Test dashboard diff uses: ./actions/diff_dashboards diff --git a/.github/workflows/test_preview_dashboards.yaml b/.github/workflows/test_preview_dashboards.yaml index d3d29ba..16ba50c 100644 --- a/.github/workflows/test_preview_dashboards.yaml +++ b/.github/workflows/test_preview_dashboards.yaml @@ -26,8 +26,8 @@ jobs: uses: ./actions/login with: url: https://demo.perses.dev - username: test - password: test + username: ${{ secrets.TEST_USERNAME }} + password: ${{ secrets.TEST_PASSWORD }} - name: Test dashboard preview uses: ./actions/preview_dashboards