From aac1a2ba1723baa140dcf8276a9d980609bdb2b8 Mon Sep 17 00:00:00 2001 From: Marcel_Henselin Date: Fri, 27 Mar 2026 17:07:50 +0000 Subject: [PATCH] fix: pipeline_fix (#99) ## Description relates to #1234 ## Checklist - [ ] Issue was linked above - [ ] Code format was applied: `make fmt` - [ ] Examples were added / adjusted (see `examples/` directory) - [x] Docs are up-to-date: `make generate-docs` (will be checked by CI) - [ ] Unit tests got implemented or updated - [ ] Acceptance tests got implemented or updated (see e.g. [here](https://github.com/stackitcloud/terraform-provider-stackit/blob/f5f99d170996b208672ae684b6da53420e369563/stackit/internal/services/dns/dns_acc_test.go)) - [x] Unit tests are passing: `make test` (will be checked by CI) - [x] No linter issues: `make lint` (will be checked by CI) Co-authored-by: Marcel S. Henselin Reviewed-on: https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/pulls/99 --- .github/actions/acc_test/action.yaml | 15 +++++++------- .github/actions/clean_up/action.yaml | 31 ++++++++++++++++++++++++---- .github/workflows/ci_new.yaml | 14 +++++++------ .github/workflows/clean_up.yaml | 4 ++-- .github/workflows/publish.yaml | 28 +++++++++++++++++++------ .github/workflows/tf-acc-test.yaml | 28 +++++++++++++++++-------- 6 files changed, 86 insertions(+), 34 deletions(-) diff --git a/.github/actions/acc_test/action.yaml b/.github/actions/acc_test/action.yaml index 46565e96..79f82298 100644 --- a/.github/actions/acc_test/action.yaml +++ b/.github/actions/acc_test/action.yaml @@ -67,11 +67,11 @@ inputs: outputs: result: - value: "${{ steps.testrun.result }}" + value: ${{ steps.testrun.outputs.result }} description: "the output of the tests" status: - value: "${{ steps.status.status }}" + value: ${{ steps.status.outputs.status }} description: "the status of the tests" runs: @@ -207,7 +207,7 @@ runs: id: testrun shell: bash run: | - echo "::group::go test file" + echo "::group::go test" set -e set -o pipefail @@ -233,18 +233,19 @@ runs: TF_ACC_KEK_KEY_VERSION=${TF_ACC_KEK_KEY_VERSION} \ TF_ACC_KEK_SERVICE_ACCOUNT=${TF_ACC_KEK_SERVICE_ACCOUNT} \ go test -v ${testfile} -timeout=${{ inputs.test_timeout_string }} | tee -a acc_test_run.log - echo "::endgroup::" set -e - echo "::group::go test result" if [[ $(cat acc_test_run.log | grep "FAIL") ]]; then + echo "::endgroup::" + echo "::group::go test result" 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=FAIL: ${res}" >> "$GITHUB_OUTPUT" + echo "::endgroup::" exit 1 - else - echo "result=no FAIL detected" >> "$GITHUB_OUTPUT" fi + + echo "result=no FAIL detected" >> "$GITHUB_OUTPUT" echo "::endgroup::" env: TF_ACC_PROJECT_ID: ${{ inputs.project_id }} diff --git a/.github/actions/clean_up/action.yaml b/.github/actions/clean_up/action.yaml index 72ee1dad..c8e142fa 100644 --- a/.github/actions/clean_up/action.yaml +++ b/.github/actions/clean_up/action.yaml @@ -49,6 +49,10 @@ outputs: description: "number of resources found" value: ${{ steps.retrieve_post.outputs.count }} + status: + description: "status of the test" + value: ${{ steps.status.outputs.status }} + runs: using: "composite" steps: @@ -148,11 +152,14 @@ runs: - name: Delete SQL Server Flex resources if: ${{ inputs.list_only != 'true' }} + id: del_sql run: | echo "::group::delete SQL Server Flex resources" - set -e stackit --verbosity ${{ inputs.log_level }} auth activate-service-account --service-account-key-path .svc_acc.json - for s in $(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 }}")) | .id'); do stackit --verbosity ${{ inputs.log_level }} -y --project-id ${{ inputs.project_id }} beta sqlserverflex instance delete $s; done + for s in $(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 }}")) | .id'); + do + stackit --verbosity ${{ inputs.log_level }} -y --project-id ${{ inputs.project_id }} beta sqlserverflex instance delete $s || echo "status=FAILURE" >> ${GITHUB_OUTPUT}; + done echo "::endgroup::" shell: bash @@ -165,11 +172,14 @@ runs: - name: Delete PostgreSQL Flex resources if: ${{ inputs.list_only != 'true' }} + id: del_pg run: | 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" --force; 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 || echo "status=FAILURE" >> ${GITHUB_OUTPUT}; + done echo "::endgroup::" shell: bash @@ -202,3 +212,16 @@ runs: echo "count=$(( ${pg_count} + ${sql_count} ))" >> $GITHUB_OUTPUT echo "::endgroup::" shell: bash + + - name: Set status + if: always() + id: status + run: | + status="SUCCESS" + if [[ "${{ steps.del_pg.outputs.status }}" == "FAILURE" ]]; then + status=FAILURE" + elif [[ "${{ steps.del_sql.outputs.status }}" == "FAILURE" ]]; then + status=FAILURE" + fi + echo "status=$status" >> $GITHUB_OUTPUT + shell: bash diff --git a/.github/workflows/ci_new.yaml b/.github/workflows/ci_new.yaml index d79f806a..61288df4 100644 --- a/.github/workflows/ci_new.yaml +++ b/.github/workflows/ci_new.yaml @@ -34,15 +34,17 @@ jobs: uses: actions/checkout@v6 - name: Notify + if: always() uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: CI pipeline started - event_title: ${{ github.event.type }} - event_author: ${{ github.event.actor.login }} - event_body: 'No event body.' - event_number: ${{ github.event.id }} - event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ github.run_id }}" + title: "[START] CI pipeline (#${{ forgejo.run_number }})" + subtitle: "${{ forgejo.event_name }} on ${{ forgejo.ref_name }}" + event_title: "${{ forgejo.event_name }} for ${{ forgejo.repository }}" + event_author: ${{ forgejo.actor }} + event_body: "${{ forgejo.event_name }} on ${{ forgejo.ref }} for ${{ forgejo.repository }}" + 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: Check GoReleaser uses: goreleaser/goreleaser-action@v7 diff --git a/.github/workflows/clean_up.yaml b/.github/workflows/clean_up.yaml index d9e61d2c..e1cc291b 100644 --- a/.github/workflows/clean_up.yaml +++ b/.github/workflows/clean_up.yaml @@ -38,7 +38,7 @@ jobs: uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: "[START] CLEAN UP pipeline" + title: "[START] CLEAN UP pipeline (#${{ forgejo.run_number }})" subtitle: "${{ forgejo.repository }}" event_title: ${{ forgejo.event_name }} event_author: ${{ forgejo.actor }} @@ -62,7 +62,7 @@ jobs: uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: "[END] CLEAN UP pipeline" + title: "[END] CLEAN UP pipeline (#${{ forgejo.run_number }})" subtitle: "${{ forgejo.repository }}" event_title: ${{ forgejo.event_name }} event_author: ${{ forgejo.actor }} diff --git a/.github/workflows/publish.yaml b/.github/workflows/publish.yaml index 2810d5c4..dbfbc247 100644 --- a/.github/workflows/publish.yaml +++ b/.github/workflows/publish.yaml @@ -51,12 +51,13 @@ jobs: uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: Publish started - event_title: ${{ github.event.type }} - event_author: ${{ github.event.actor.login }} - event_body: "Trigger: ${{ github.event_name }}" - event_number: ${{ github.event.id }} - event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ github.run_id }}" + title: "[START] Publish (#${{ forgejo.run_number }})" + subtitle: "${{ forgejo.event_name }} on branch ${{ forgejo.ref }}" + event_title: "run started" + event_author: ${{ forgejo.actor }} + event_body: "" + event_number: ${{ forgejo.event.id }} + event_url: "https://tf-provider.git.onstackit.cloud/stackit-dev-tools/terraform-provider-stackitprivatepreview/actions/runs/${{ forgejo.run_number }}" - name: Setup Go uses: actions/setup-go@v6 @@ -145,6 +146,7 @@ jobs: --outFile nav.md - name: Publish provider to S3 + id: publish_to_s3 run: | set -e cd release/ @@ -165,3 +167,17 @@ jobs: # echo "${{ github.ref_name }}" >docs/_version.txt scp -o StrictHostKeyChecking=no -r docs ubuntu@${{ vars.DOCS_SERVER_IP }}:/srv/www/ scp -o StrictHostKeyChecking=no nav.md ubuntu@${{ vars.DOCS_SERVER_IP }}:/srv/www/ + + - name: Notify + if: always() + uses: ./.github/actions/notify + with: + webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} + title: "[END] Publish (#${{ forgejo.run_number }})" + subtitle: "${{ forgejo.event_name }} on branch ${{ forgejo.ref }}" + event_title: "released: ${{ steps.get_version.outputs.version }}" + event_author: ${{ forgejo.actor }} + event_body: "" + 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: "${{ steps.publish_to_s3.outcome == 'success' && 'SUCCESS' || 'FAILURE' }}" diff --git a/.github/workflows/tf-acc-test.yaml b/.github/workflows/tf-acc-test.yaml index be9c4c58..730fb0ca 100644 --- a/.github/workflows/tf-acc-test.yaml +++ b/.github/workflows/tf-acc-test.yaml @@ -41,17 +41,20 @@ jobs: - name: set start time id: start_time + continue-on-error: true run: | - echo "time=$(date --rfc-3339=ns)" >> ${GITHUB_ENV} - echo "start=$(date +%s%N)" >> ${GITHUB_ENV} + time=$(date --rfc-3339=ns) + echo "start_time=$time" >> ${GITHUB_OUTPUT} + start=$(date +%s%N) + echo "start=$start" >> ${GITHUB_OUTPUT} - name: Notify uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: "[START] Terraform Acceptance Tests" + title: "[START] Terraform Acceptance Tests (#${{ forgejo.run_number }})" subtitle: "${{ forgejo.event_name }} on branch ${{ forgejo.ref }}" - event_title: "started: ${{ steps.start_time.outputs.time }}" + event_title: "started: ${{ steps.start_time.outputs.start_time }}" event_author: ${{ forgejo.actor }} event_body: ${{ inputs.test_file }} event_number: ${{ forgejo.run_number }} @@ -60,6 +63,7 @@ jobs: - name: Run Test (workflow dispatch) if: ${{ forgejo.event_name == 'workflow_dispatch' }} id: manual_run + continue-on-error: true uses: ./.github/actions/acc_test with: go-version: ${{ env.GO_VERSION }} @@ -78,6 +82,7 @@ jobs: - name: Run Test (automatic) if: ${{ forgejo.event_name != 'workflow_dispatch' }} id: automatic_run + continue-on-error: true uses: ./.github/actions/acc_test with: go-version: ${{ env.GO_VERSION }} @@ -92,22 +97,27 @@ jobs: - name: set end time id: end_time + continue-on-error: true run: | - echo "time=$(date --rfc-3339=ns)" >> ${GITHUB_ENV} + set -e + echo "auto status: ${{ steps.automatic_run.outputs.status }}" + echo "manual status: ${{ steps.manual_run.outputs.status }}" + echo "status: ${{ forgejo.event_name == 'workflow_dispatch' && steps.manual_run.outputs.status || steps.automatic_run.outputs.status }}" + echo "end_time=$(date --rfc-3339=ns)" >> ${GITHUB_OUTPUT} end=$(date +%s%N) - echo "end=${end}" >> ${GITHUB_ENV} + echo "end=${end}" >> ${GITHUB_OUTPUT} start=${{ steps.start_time.outputs.start }} diff=$((end-start)) duration=$(printf "%s.%s" "${diff:0: -9}" "${diff: -9:3}") - echo "duration=${duration}" >> ${GITHUB_ENV} + echo "duration=${duration}" >> ${GITHUB_OUTPUT} - name: Notify uses: ./.github/actions/notify with: webhook_url: ${{ secrets.GOOGLE_WEBHOOK_URL }} - title: "[END] Terraform Acceptance Tests" + title: "[END] Terraform Acceptance Tests (#${{ forgejo.run_number }})" 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_title: "run ended: ${{ steps.end_time.outputs.end_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 }}