From 5e86fc37246e370e3ed472ac6916c7992a9d6ca6 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 13:59:05 -0500 Subject: [PATCH 01/12] ci: .NET workflow tweaks --- .github/workflows/dotnet.yml | 59 ++++++++++++++++++++++-------------- 1 file changed, 37 insertions(+), 22 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index ffa4ec0..81110c0 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -1,22 +1,33 @@ -# Copyright 2010 New Relic, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright New Relic, Inc. +# SPDX-License-Identifier: Apache-2.0 --- name: .NET Agent CI on: - workflow_dispatch: # run test job only + workflow_dispatch: # run test job always, optionally publish a specific version + inputs: + publish_agent: + description: Publish the agent? + type: boolean + required: true + default: false + agent_version: + description: The agent version to publish (in SemVer format xx.xx.xx) + type: string + required: true pull_request: # run check modified files / test jobs + paths: + - 'src/dotnet/**' + - '.github/workflows/dotnet.yml' + push: # run check modified files / test jobs + branches: + - main + paths: + - 'dotnet/**' + - '.github/workflows/dotnet.yml' + # Do not run when a tag is created. + tags-ignore: + - "**" release: # run check modified files / test / publish jobs types: - published @@ -35,7 +46,7 @@ permissions: jobs: check-modified-files: - name: Check whether any Dotnet-related files were modified, skip the test job if not + name: Check whether any Dotnet-related files were modified uses: ./.github/workflows/check-modified-files.yml secrets: inherit permissions: @@ -113,8 +124,8 @@ jobs: publish: runs-on: ubuntu-latest - # only publish on a dotnet release - if: github.event_name == 'release' && endsWith(github.ref_name, '_dotnet') + # publish on a dotnet release or when selected on a manual invocation + if: (github.event_name == 'release' && endsWith(github.ref_name, '_dotnet')) || (github.event_name == 'workflow_dispatch' && inputs.publish_agent) needs: - test @@ -125,13 +136,17 @@ jobs: disable-sudo: true egress-policy: audit - - name: Extract Agent Version from release tag + - name: Extract Agent Version from release tag or workflow input id: version run: | - agent_version=${{ github.ref_name }} # Use tag name - agent_version=${agent_version##v} # Remove v prefix - agent_version=${agent_version%%_dotnet} # Remove language suffix - echo "agent_version=${agent_version}" | tee -a "$GITHUB_OUTPUT" + if (${{ github.event_name == 'workflow_dispatch'}}) then + echo "agent_version=${{ inputs.agent_version }}" | tee -a "$GITHUB_OUTPUT" + else + agent_version=${{ github.ref_name }} # Use tag name + agent_version=${agent_version##v} # Remove v prefix + agent_version=${agent_version%%_dotnet} # Remove language suffix + echo "agent_version=${agent_version}" | tee -a "$GITHUB_OUTPUT" + fi - name: Checkout code uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1 From 9d113670f566a31e2e7dca347518255759b05511 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:33:44 -0500 Subject: [PATCH 02/12] bug fix --- .github/workflows/dotnet.yml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 81110c0..c5211c7 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,9 +12,9 @@ on: required: true default: false agent_version: - description: The agent version to publish (in SemVer format xx.xx.xx) + description: Agent version to publish (in SemVer format xx.xx.xx). Leave blank for latest version. type: string - required: true + required: false pull_request: # run check modified files / test jobs paths: - 'src/dotnet/**' @@ -139,7 +139,7 @@ jobs: - name: Extract Agent Version from release tag or workflow input id: version run: | - if (${{ github.event_name == 'workflow_dispatch'}}) then + if [[ ${{ github.event_name == 'workflow_dispatch' }} && "${{ inputs.agent_version }}"]]; then echo "agent_version=${{ inputs.agent_version }}" | tee -a "$GITHUB_OUTPUT" else agent_version=${{ github.ref_name }} # Use tag name From 93f81e3b0ab0b1e712fd6d74d64066d2065d0615 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 14:56:58 -0500 Subject: [PATCH 03/12] set latest tag only if no agent version was specified on input --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index c5211c7..f5b811a 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -165,7 +165,7 @@ jobs: images: newrelic/newrelic-dotnet-init tags: | type=raw,value=${{ steps.version.outputs.agent_version }} - type=raw,value=latest + type=raw,value=latest,enable=${{ inputs.agent_version == '' }} - name: Login to Docker Hub Container Registry uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # 3.1.0 From 6c50eae5a1f1ac99f7aaefd2394e4249ba490e83 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:05:13 -0500 Subject: [PATCH 04/12] update license header in check-modified-files --- .github/workflows/check-modified-files.yml | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/.github/workflows/check-modified-files.yml b/.github/workflows/check-modified-files.yml index 78582e1..d1cc7aa 100644 --- a/.github/workflows/check-modified-files.yml +++ b/.github/workflows/check-modified-files.yml @@ -1,16 +1,5 @@ -# Copyright 2010 New Relic, Inc. -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -# See the License for the specific language governing permissions and -# limitations under the License. +# Copyright New Relic, Inc. +# SPDX-License-Identifier: Apache-2.0 --- name: Check for modified files From f0ad1c7e3e8a3b6ccde54c67a4321599fde79747 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:17:41 -0500 Subject: [PATCH 05/12] fix conditional --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index f5b811a..214f2f5 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -139,7 +139,7 @@ jobs: - name: Extract Agent Version from release tag or workflow input id: version run: | - if [[ ${{ github.event_name == 'workflow_dispatch' }} && "${{ inputs.agent_version }}"]]; then + if [[ ${{ github.event_name == 'workflow_dispatch' }} && ${{ inputs.agent_version != '' }} ]]; then echo "agent_version=${{ inputs.agent_version }}" | tee -a "$GITHUB_OUTPUT" else agent_version=${{ github.ref_name }} # Use tag name From 00dc482177a09d7f457ad42ccae9ceb9ec8445ce Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:38:14 -0500 Subject: [PATCH 06/12] agent version is required --- .github/workflows/dotnet.yml | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 214f2f5..afb81ae 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,9 +12,10 @@ on: required: true default: false agent_version: - description: Agent version to publish (in SemVer format xx.xx.xx). Leave blank for latest version. + description: Agent version to publish (in SemVer format xx.xx.xx). type: string - required: false + required: true + default: 'xx.xx.xx' pull_request: # run check modified files / test jobs paths: - 'src/dotnet/**' @@ -139,7 +140,7 @@ jobs: - name: Extract Agent Version from release tag or workflow input id: version run: | - if [[ ${{ github.event_name == 'workflow_dispatch' }} && ${{ inputs.agent_version != '' }} ]]; then + if [[ ${{ github.event_name == 'workflow_dispatch' }} ]]; then echo "agent_version=${{ inputs.agent_version }}" | tee -a "$GITHUB_OUTPUT" else agent_version=${{ github.ref_name }} # Use tag name From 71ae295622d0a6cb88db2202299eb3aed73e8ace Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:39:19 -0500 Subject: [PATCH 07/12] tweak --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index afb81ae..e4f22be 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -12,7 +12,7 @@ on: required: true default: false agent_version: - description: Agent version to publish (in SemVer format xx.xx.xx). + description: Agent version to publish type: string required: true default: 'xx.xx.xx' From 864b9f208532ec6ba8211907ee4898f1bca02725 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:47:11 -0500 Subject: [PATCH 08/12] one more --- .github/workflows/dotnet.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index e4f22be..54e360b 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -166,7 +166,7 @@ jobs: images: newrelic/newrelic-dotnet-init tags: | type=raw,value=${{ steps.version.outputs.agent_version }} - type=raw,value=latest,enable=${{ inputs.agent_version == '' }} + type=raw,value=latest,enable=${{ github.event_name == 'release' }} - name: Login to Docker Hub Container Registry uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # 3.1.0 From cc9685d9b4c7cf5b6d162f0e95616b66a599a4e1 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Wed, 5 Jun 2024 15:49:41 -0500 Subject: [PATCH 09/12] Add input for latest tag --- .github/workflows/dotnet.yml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 54e360b..27df906 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -16,6 +16,10 @@ on: type: string required: true default: 'xx.xx.xx' + set_latest_tag: + description: Set the "latest" image tag? + type: boolean + default: false pull_request: # run check modified files / test jobs paths: - 'src/dotnet/**' @@ -166,7 +170,7 @@ jobs: images: newrelic/newrelic-dotnet-init tags: | type=raw,value=${{ steps.version.outputs.agent_version }} - type=raw,value=latest,enable=${{ github.event_name == 'release' }} + type=raw,value=latest,enable=${{ github.event_name == 'release' || inputs.set_latest_tag }} - name: Login to Docker Hub Container Registry uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # 3.1.0 From 4a01fe7e211818683052ca653806f56e54f52986 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:08:44 -0500 Subject: [PATCH 10/12] refactor dotnet to use test.yml, tweak test.yml to take an extra parameter --- .github/workflows/dotnet.yml | 69 ++++-------------------------------- .github/workflows/test.yml | 4 +++ 2 files changed, 10 insertions(+), 63 deletions(-) diff --git a/.github/workflows/dotnet.yml b/.github/workflows/dotnet.yml index 27df906..f272334 100644 --- a/.github/workflows/dotnet.yml +++ b/.github/workflows/dotnet.yml @@ -60,72 +60,15 @@ jobs: agent-language: dotnet test: - name: Run Dotnet init container tests - runs-on: ubuntu-latest + uses: ./.github/workflows/test.yml needs: check-modified-files # run only if files were modified or the workflow was manually invoked or on a publish if: needs.check-modified-files.outputs.files-changed == 'true' || github.event_name == 'workflow_dispatch' || (github.event_name == 'release' && endsWith(github.ref_name, '_dotnet')) - - steps: - # For some reason, Harden Runner causes setup-minikube to not work correctly - # - name: Harden Runner - # uses: step-security/harden-runner@a4aa98b93cab29d9b1101a6143fb8bce00e2eac4 # v2.7.1 - # with: - # #disable-sudo: true - # egress-policy: audit - - - name: Checkout code - uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1 - with: - persist-credentials: false - fetch-depth: 0 - - - name: Set up Docker Buildx - id: buildx - uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # 3.3.0 - - - name: Start minikube - uses: medyagh/setup-minikube@317d92317e473a10540357f1f4b2878b80ee7b95 # 0.0.16 - - - name: Deploy cert-manager to minikube - run: | - helm repo add jetstack https://charts.jetstack.io --force-update - helm install cert-manager jetstack/cert-manager --namespace cert-manager --create-namespace --version v1.14.5 --set installCRDs=true - echo "waiting for cert-manager pods to be ready..." - sleep 5 - kubectl wait --for=condition=Ready -n cert-manager --all pods --timeout=60s - - - name: Deploy New Relic k8s-agents-operator to minikube - run: | - helm repo add k8s-agents-operator https://newrelic.github.io/k8s-agents-operator - helm upgrade --install k8s-agents-operator k8s-agents-operator/k8s-agents-operator \ - --namespace=default \ - --set=licenseKey=${{ secrets.NEW_RELIC_LICENSE_KEY }} \ - --set=controllerManager.manager.image.tag=${{ env.K8S_OPERATOR_IMAGE_TAG }} - sleep 5 - kubectl wait --for=condition=Ready -n default --all pods --timeout=60s - - - name: Build init container for e2e test - run: | - minikube image build -t e2e/newrelic-dotnet-init:e2e src/dotnet/ \ - --build-opt=build-arg=TARGETARCH=${{ env.DOTNET_AGENT_ARCHITECTURE }} - - - name: Build test app container - run: | - minikube image build -t e2e/test-app-dotnet:e2e tests/dotnet/ - - - name: Run e2e-test - uses: newrelic/newrelic-integration-e2e-action@a97ced80a4841c8c6261d1f9dca6706b1d89acb1 # 1.11.0 - with: - retry_seconds: 60 - retry_attempts: 5 - agent_enabled: false - spec_path: tests/dotnet/test-specs.yml - account_id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }} - api_key: ${{ secrets.NEW_RELIC_API_KEY }} - license_key: ${{ secrets.NEW_RELIC_LICENSE_KEY }} - # set the region to Staging if using a staging license key. Also set NEW_RELIC_HOST in tests/chart/templates/deployment.yaml - #region: Staging + secrets: inherit + with: + INITCONTAINER_LANGUAGE: dotnet + K8S_OPERATOR_IMAGE_TAG: edge + TEST_APP_BUILD_ARGS: --build-opt=build-arg=TARGETARCH=amd64 publish: runs-on: ubuntu-latest diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 6a5290d..3f8f81c 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -26,6 +26,9 @@ on: RUNTIME_VERSION: required: false type: string + TEST_APP_BUILD_ARGS: + required: false + type: string jobs: check-license-key: @@ -80,6 +83,7 @@ jobs: - name: Build test app container run: | minikube image build -t e2e/test-app-${{ inputs.INITCONTAINER_LANGUAGE }}:e2e tests/${{ inputs.INITCONTAINER_LANGUAGE }}/ + ${{ inputs.TEST_APP_BUILD_ARGS}} - name: Run e2e-test uses: newrelic/newrelic-integration-e2e-action@a97ced80a4841c8c6261d1f9dca6706b1d89acb1 # 1.11.0 From f146fdbdd168eaede7020100782f4d3bad78ae5e Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:12:53 -0500 Subject: [PATCH 11/12] oops --- .github/workflows/test.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 3f8f81c..ca047cd 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -82,7 +82,7 @@ jobs: - name: Build test app container run: | - minikube image build -t e2e/test-app-${{ inputs.INITCONTAINER_LANGUAGE }}:e2e tests/${{ inputs.INITCONTAINER_LANGUAGE }}/ + minikube image build -t e2e/test-app-${{ inputs.INITCONTAINER_LANGUAGE }}:e2e tests/${{ inputs.INITCONTAINER_LANGUAGE }}/ \ ${{ inputs.TEST_APP_BUILD_ARGS}} - name: Run e2e-test From 25534f2bfe22380ee55dcb57c6310b3a1c72c564 Mon Sep 17 00:00:00 2001 From: Marty Tippin <120425148+tippmar-nr@users.noreply.github.com> Date: Fri, 7 Jun 2024 15:17:49 -0500 Subject: [PATCH 12/12] cosmetics --- .github/workflows/test.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index ca047cd..f74d215 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -41,6 +41,7 @@ jobs: echo ${#NEW_RELIC_LICENSE_KEY} test: + name: Run E2E tests for ${{ inputs.INITCONTAINER_LANGUAGE }} runs-on: ubuntu-latest steps: