diff --git a/.github/actions/acc_test/action.yaml b/.github/actions/acc_test/action.yaml
index 13674a9a..46565e96 100644
--- a/.github/actions/acc_test/action.yaml
+++ b/.github/actions/acc_test/action.yaml
@@ -67,9 +67,13 @@ inputs:
outputs:
result:
- value: ${{ steps.testrun.result }}
+ value: "${{ steps.testrun.result }}"
description: "the output of the tests"
+ status:
+ value: "${{ steps.status.status }}"
+ description: "the status of the tests"
+
runs:
using: "composite"
steps:
@@ -213,6 +217,8 @@ runs:
fi
testfile="${{ inputs.test_file }}"
+
+ echo "result=no result before run" >> "$GITHUB_OUTPUT"
echo "Running acceptance tests for the terraform provider"
set +e
@@ -230,11 +236,14 @@ runs:
echo "::endgroup::"
set -e
echo "::group::go test result"
- if [ $? -ne 0 ]; then
+
+ if [[ $(cat acc_test_run.log | grep "FAIL") ]]; then
echo "Test failed, see acc_test_run.log for details"
res=$(cat acc_test_run.log | grep -v "=== RUN" | grep -v "\-\-\- PASS" | grep -v "=== CONT" | grep -v "=== PAUSE")
- echo "result=${res}" >> "$GITHUB_OUTPUT"
+ echo "result=FAIL: ${res}" >> "$GITHUB_OUTPUT"
exit 1
+ else
+ echo "result=no FAIL detected" >> "$GITHUB_OUTPUT"
fi
echo "::endgroup::"
env:
@@ -246,10 +255,12 @@ runs:
TF_ACC_KEK_KEY_VERSION: ${{ inputs.tf_acc_kek_key_version }}
TF_ACC_KEK_SERVICE_ACCOUNT: ${{ inputs.tf_acc_kek_service_account }}
- - name: Artifact upload start
+ - name: Set status output variable
+ if: always()
+ id: status
shell: bash
run: |
- echo "::group::artifact upload"
+ echo "status=${{ steps.testrun.outcome == 'success' && 'SUCCESS' || 'FAILURE' }}" >> "$GITHUB_OUTPUT"
- name: Upload test log artifact
if: always()
@@ -257,8 +268,3 @@ runs:
with:
name: acc_test.log
path: "stackit/acc_test_run.log"
-
- - name: Artifact upload finish
- shell: bash
- run: |
- echo "::endgroup::"
diff --git a/.github/actions/clean_up/action.yaml b/.github/actions/clean_up/action.yaml
index 1cea3615..72ee1dad 100644
--- a/.github/actions/clean_up/action.yaml
+++ b/.github/actions/clean_up/action.yaml
@@ -41,6 +41,14 @@ outputs:
description: "stackit cli version"
value: ${{ steps.stackit_version.outputs.version }}
+ pre_count:
+ description: "number of resources found"
+ value: ${{ steps.retrieve_pre.outputs.count }}
+
+ post_count:
+ description: "number of resources found"
+ value: ${{ steps.retrieve_post.outputs.count }}
+
runs:
using: "composite"
steps:
@@ -115,7 +123,8 @@ runs:
exit 1
fi
- - name: Retrieve resources
+ - name: Retrieve resources before
+ id: retrieve_pre
run: |
echo "::group::retrieve resources"
set -e
@@ -125,11 +134,15 @@ runs:
stackit auth activate-service-account --service-account-key-path .svc_acc.json
echo "SQL Server Flex resources:"
- stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" beta sqlserverflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))'
+ sql_res=$(stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" beta sqlserverflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))')
+ sql_count=$(echo "$sql_res" | jq -r '.id' | wc -l)
echo "PostgreSQL Flex resources:"
- stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))'
+ pg_res=$(stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))')
+ pg_count=$(echo "$pg_res" | jq -r '.id' | wc -l)
+ echo "Number of resources found: ${sql_count} SQL Server Flex, ${pg_count} PostgreSQL Flex"
+ echo "count=$(( ${pg_count} + ${sql_count} ))" >> $GITHUB_OUTPUT
echo "::endgroup::"
shell: bash
@@ -156,7 +169,7 @@ runs:
echo "::group::delete PostgreSQL Flex resources"
set -e
stackit auth activate-service-account --service-account-key-path .svc_acc.json
- for s in $(stackit --verbosity ${{ inputs.log_level }} --project-id ${{ inputs.project_id }} postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}")) | .id'); do stackit --verbosity ${{ inputs.log_level }} -y --project-id ${{ inputs.project_id }} postgresflex instance delete $s; done
+ for s in $(stackit --verbosity ${{ inputs.log_level }} --project-id ${{ inputs.project_id }} postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}")) | .id'); do stackit --verbosity ${{ inputs.log_level }} -y --project-id ${{ inputs.project_id }} postgresflex instance delete "$s" --force; done
echo "::endgroup::"
shell: bash
@@ -166,3 +179,26 @@ runs:
set -e
echo "Skip deleting: list only mode"
shell: bash
+
+ - name: Retrieve resources after
+ id: retrieve_post
+ run: |
+ echo "::group::retrieve resources"
+ set -e
+ echo "authenticating api"
+ STACKIT_SERVICE_ACCOUNT_KEY_PATH="${PWD}/.svc_acc.json"
+ export STACKIT_SERVICE_ACCOUNT_KEY_PATH
+ stackit auth activate-service-account --service-account-key-path .svc_acc.json
+
+ echo "SQL Server Flex resources:"
+ sql_res=$(stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" beta sqlserverflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))')
+ sql_count=$(echo "$sql_res" | jq -r '.id' | wc -l)
+
+ echo "PostgreSQL Flex resources:"
+ pg_res=$(stackit --verbosity ${{ inputs.log_level }} --project-id "${{ inputs.project_id }}" postgresflex instance list --output-format json | jq -r '.[] | select(.name | startswith("${{ inputs.tf_resource_prefix }}"))')
+ pg_count=$(echo "$pg_res" | jq -r '.id' | wc -l)
+
+ echo "Number of resources found: ${sql_count} SQL Server Flex, ${pg_count} PostgreSQL Flex"
+ echo "count=$(( ${pg_count} + ${sql_count} ))" >> $GITHUB_OUTPUT
+ echo "::endgroup::"
+ shell: bash
diff --git a/.github/actions/notify/action.yaml b/.github/actions/notify/action.yaml
index f260d087..2e72732e 100644
--- a/.github/actions/notify/action.yaml
+++ b/.github/actions/notify/action.yaml
@@ -9,11 +9,17 @@ inputs:
title:
description: "The title of the notification."
required: true
- default: 'no title provided'
+
+ subtitle:
+ description: "The subtitle of the notification."
+ default: 'no subtitle provided'
+
+ image_slug:
+ description: "The slug of the image to be included in the notification."
+ default: 'git'
event_author:
description: "The author of the event."
- required: true
default: 'unknown'
event_title:
@@ -22,35 +28,23 @@ inputs:
event_body:
description: "The body of the event."
- required: true
default: 'no body provided'
event_number:
description: "The number of the event."
- required: true
default: 'no number provided'
event_url:
description: "The url of the event."
- required: true
default: 'none'
+ status:
+ description: "The status of the event."
+ default: 'UNKNOWN'
+
runs:
using: "composite"
steps:
-# - name: event list
-# shell: bash
-# run: |
-# cat <<'EOF'
-# ${{ toJSON(github) }}
-# EOF
-#
-# - name: print env
-# shell: bash
-# run: |
-# env
-# exit 1
-
- name: Install prerequisites
shell: bash
run: |
@@ -60,6 +54,27 @@ runs:
apt install -y curl jq
echo "::endgroup::"
+ - name: Determine status color
+ id: status
+ shell: bash
+ run: |
+ case "${{ inputs.status }}" in
+ SUCCESS)
+ STATUS_COLOR="006400/228b22"
+ ADD='{"decoratedText": {"startIcon": {"materialIcon": {"name": "check_circle"}},"text": "SUCCESS"}},'
+ ;;
+ FAILURE)
+ STATUS_COLOR="8b0000/dc143c"
+ ADD='{"decoratedText": {"startIcon": {"materialIcon": {"name": "stop_circle"}},"text": "FAILURE"}},'
+ ;;
+ *)
+ STATUS_COLOR="483d8b/6495ed"
+ ADD=''
+ ;;
+ esac
+ echo "color=${STATUS_COLOR}" >> "$GITHUB_OUTPUT"
+ echo "status_add=${ADD}" >> "$GITHUB_OUTPUT"
+
- name: Notify via Google Chat Webhook
shell: bash
env:
@@ -69,7 +84,8 @@ runs:
PAYLOAD=$(jq -n -r \
--arg header "${{ inputs.title }}" \
- --arg repo "${{ github.repository || '' }}" \
+ --arg subtitle "${{ inputs.subtitle }}" \
+ --arg imgurl "https://cdn.simpleicons.org/${{ inputs.image_slug }}/${{ steps.status.outputs.color }}" \
--arg title "${{ inputs.event_title || 'no event title given' }}" \
--arg body "${{ inputs.event_body || 'no event body given' }}" \
--arg author "${{ inputs.event_author || 'no event author given' }}" \
@@ -77,8 +93,8 @@ runs:
'{ "cardsV2": [ { "cardId": "notify-${{ github.run_id }}", "card": {
"header": {
"title": "\($header)",
- "subtitle": "Repo: \($repo)",
- "imageUrl": "https://cdn.jsdelivr.net/gh/homarr-labs/dashboard-icons/png/git.png",
+ "subtitle": "\($subtitle)",
+ "imageUrl": "\($imgurl)",
"imageType": "SQUARE"
},
"sections": [
@@ -86,12 +102,13 @@ runs:
"header": "\($title)",
"collapsible": false,
"widgets": [
+ ${{ steps.status.outputs.status_add }}
{
"decoratedText": {
- "icon": {
+ "startIcon": {
"knownIcon": "PERSON"
},
- "text": "Opened by: \($author)"
+ "text": "\($author)"
}
},
{
diff --git a/.github/workflows/clean_up.yaml b/.github/workflows/clean_up.yaml
index b366488f..d9e61d2c 100644
--- a/.github/workflows/clean_up.yaml
+++ b/.github/workflows/clean_up.yaml
@@ -38,14 +38,16 @@ jobs:
uses: ./.github/actions/notify
with:
webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }}
- title: CLEAN UP pipeline started
+ title: "[START] CLEAN UP pipeline"
+ subtitle: "${{ forgejo.repository }}"
event_title: ${{ forgejo.event_name }}
event_author: ${{ forgejo.actor }}
- event_body: "Filter: ${{ inputs.res_prefix }}"
+ event_body: "try to remove all resources with prefix ${{ inputs.res_prefix }}"
event_number: ${{ forgejo.run_number }}
event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ forgejo.run_number }}"
- name: Clean
+ id: clean
uses: ./.github/actions/clean_up
with:
project_id: ${{ vars.TF_ACC_PROJECT_ID }}
@@ -54,3 +56,17 @@ jobs:
service_account_json_content_b64: "${{ secrets.TF_ACC_SERVICE_ACCOUNT_JSON_B64 }}"
list_only: ${{ inputs.list_only }}
log_level: ${{ inputs.log_level }}
+
+ - name: Notify
+ if: always()
+ uses: ./.github/actions/notify
+ with:
+ webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }}
+ title: "[END] CLEAN UP pipeline"
+ subtitle: "${{ forgejo.repository }}"
+ event_title: ${{ forgejo.event_name }}
+ event_author: ${{ forgejo.actor }}
+ event_body: "count before cleaning: ${{ steps.clean.outputs.pre_count }}
count after cleaning: ${{ steps.clean.outputs.post_count }}"
+ event_number: ${{ forgejo.run_number }}
+ event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ forgejo.run_number }}"
+ status: ${{ steps.clean.outcome == 'success' && 'SUCCESS' || 'FAILURE' }}
diff --git a/.github/workflows/tf-acc-test.yaml b/.github/workflows/tf-acc-test.yaml
index 642fe63b..504324ba 100644
--- a/.github/workflows/tf-acc-test.yaml
+++ b/.github/workflows/tf-acc-test.yaml
@@ -40,19 +40,26 @@ jobs:
- name: Checkout
uses: actions/checkout@v6
+ - name: set start time
+ id: start_time
+ run: |
+ echo "time=$(date --rfc-3339=ns)" >> ${GITHUB_ENV}
+ echo "start=$(date +%s%N)" >> ${GITHUB_ENV}
+
- name: Notify
uses: ./.github/actions/notify
with:
webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }}
- title: Terraform Acceptance Tests started
- event_title: ${{ github.event_name }}
- event_author: ${{ github.actor }}
+ title: "[START] Terraform Acceptance Tests"
+ subtitle: "${{ forgejo.event_name }} on branch ${{ forgejo.ref }}"
+ event_title: "started: ${{ steps.start_time.outputs.time }}"
+ event_author: ${{ forgejo.actor }}
event_body: ${{ inputs.test_file }}
- event_number: ${{ github.run_id }}
+ event_number: ${{ forgejo.run_number }}
event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ forgejo.run_number }}"
- name: Run Test (workflow dispatch)
- if: ${{ github.event_name == 'workflow_dispatch' }}
+ if: ${{ forgejo.event_name == 'workflow_dispatch' }}
id: manual_run
uses: ./.github/actions/acc_test
with:
@@ -70,7 +77,7 @@ jobs:
test_file: ${{ inputs.test_file }}
- name: Run Test (automatic)
- if: ${{ github.event_name != 'workflow_dispatch' }}
+ if: ${{ forgejo.event_name != 'workflow_dispatch' }}
id: automatic_run
uses: ./.github/actions/acc_test
with:
@@ -84,13 +91,26 @@ jobs:
tf_acc_kek_key_version: ${{ vars.TF_ACC_KEK_KEY_VERSION }}
tf_acc_kek_service_account: ${{ vars.TF_ACC_KEK_SERVICE_ACCOUNT }}
+ - name: set end time
+ id: end_time
+ run: |
+ echo "time=$(date --rfc-3339=ns)" >> ${GITHUB_ENV}
+ end=$(date +%s%N)
+ echo "end=${end}" >> ${GITHUB_ENV}
+ start=${{ steps.start_time.outputs.start }}
+ diff=$((end-start))
+ duration=$(printf "%s.%s" "${diff:0: -9}" "${diff: -9:3}")
+ echo "duration=${duration}" >> ${GITHUB_ENV}
+
- name: Notify
uses: ./.github/actions/notify
with:
webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }}
- title: Terraform Acceptance Tests finished
- event_title: ${{ github.event_name }}
- event_author: ${{ github.actor }}
- event_body: "${{ steps.automatic_run.outputs.result || steps.manual_run.outputs.result }}"
- event_number: ${{ github.event.id }}
+ title: "[END] Terraform Acceptance Tests"
+ subtitle: "${{ forgejo.event_name }} on branch ${{ forgejo.ref }} with status: ${{ forgejo.event_name == 'workflow_dispatch' && steps.manual_run.outputs.status || steps.automatic_run.outputs.status }}"
+ event_title: "run ended: ${{ steps.end_time.outputs.time }}, duration: ${{ steps.end_time.outputs.duration }} seconds"
+ event_author: ${{ forgejo.actor }}
+ event_body: "${{ forgejo.event_name == 'workflow_dispatch' && steps.manual_run.outputs.result || steps.automatic_run.outputs.result }}"
+ event_number: ${{ forgejo.event.id }}
event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ forgejo.run_number }}"
+ status: "${{ forgejo.event_name == 'workflow_dispatch' && steps.manual_run.outputs.status || steps.automatic_run.outputs.status }}"