Skip to content

Commit

Permalink
Reusable python workflow usage
Browse files Browse the repository at this point in the history
  • Loading branch information
TimPansino committed Jun 6, 2024
1 parent d0828d0 commit 3a1540d
Showing 1 changed file with 58 additions and 111 deletions.
169 changes: 58 additions & 111 deletions .github/workflows/python.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,18 @@
# See the License for the specific language governing permissions and
# limitations under the License.
---
name: Python Agent CI

name: "Python Init Container CI"

on:
pull_request:
paths:
- 'src/python/**'
- '.github/workflows/python.yml'
push:
# Run on push to main or PR.
paths:
- 'python/**'
- '.github/workflows/python.yml'
branches:
- main
# Do not run when a tag is created.
Expand All @@ -28,122 +34,63 @@ on:
- published

env:
INITCONTAINER_LANGUAGE: python
K8S_OPERATOR_IMAGE_TAG: edge

jobs:
check-modified-files:
name: Check whether any Python-related files were modified, skip the test job if not
name: Check whether any Node-related files were modified, skip the test job if not
uses: ./.github/workflows/check-modified-files.yml
secrets: inherit
permissions:
contents: read
with:
agent-language: python

test:
runs-on: ubuntu-latest
needs: check-modified-files
# run only if Python-related files were modified
if: needs.check-modified-files.outputs.files-changed == 'true'

steps:
- 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
sleep 5
kubectl wait --for=condition=Ready -n cert-manager --all pods
- 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
- name: Build init container
run: |
minikube image build -t e2e/newrelic-${{ env.INITCONTAINER_LANGUAGE }}-init:e2e src/${{ env.INITCONTAINER_LANGUAGE }}/
- name: Build test app container
run: |
minikube image build -t e2e/test-app-${{ env.INITCONTAINER_LANGUAGE }}:e2e tests/${{ env.INITCONTAINER_LANGUAGE }}/
- 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/${{ env.INITCONTAINER_LANGUAGE }}/test-specs.yml
account_id: ${{ secrets.NEW_RELIC_ACCOUNT_ID }}
api_key: ${{ secrets.NEW_RELIC_API_KEY }}
license_key: ${{ secrets.NEW_RELIC_LICENSE_KEY }}
agent-language: nodejs

publish:
if: github.event_name == 'release' && endsWith(github.ref, '_python')
runs-on: ubuntu-latest
needs:
- test

steps:
- name: Checkout code
uses: actions/checkout@b4ffde65f46336ab88eb53be808477a3936bae11 # 4.1.1
with:
persist-credentials: false
fetch-depth: 0

- name: Extract Agent Version
id: version
run: |
agent_version=${{ github.ref_name }} # Use tag name
agent_version=${agent_version##v} # Remove v prefix
agent_version=${agent_version%%_${{ env.INITCONTAINER_LANGUAGE }}} # Remove language suffix
echo "agent_version=${agent_version}" | tee -a "$GITHUB_OUTPUT"
- name: Set up Docker Buildx
id: buildx
uses: docker/setup-buildx-action@d70bba72b1f3fd22344832f00baa16ece964efeb # 3.3.0

- name: Generate Docker metadata (tags and labels)
id: meta
uses: docker/metadata-action@8e5442c4ef9f78752691e2d8f8d19755c6f78e81 # 5.5.1
with:
images: newrelic/newrelic-${{ env.INITCONTAINER_LANGUAGE }}-init
tags: |
type=raw,value=${{ steps.version.outputs.agent_version }}
type=raw,value=latest
- name: Login to Docker Hub Container Registry
uses: docker/login-action@e92390c5fb421da1463c202d546fed0ec5c39f20 # 3.1.0
with:
username: ${{ github.repository_owner }}
password: ${{ secrets.DOCKER_TOKEN }}

- name: Build and publish init container image
uses: docker/build-push-action@2cdde995de11925a030ce8070c3d77a52ffcf1c0 # 5.3.0
with:
push: true
context: src/${{ env.INITCONTAINER_LANGUAGE }}/
platforms: linux/amd64,linux/arm64,linux/arm
tags: ${{ steps.meta.outputs.tags }}
labels: ${{ steps.meta.outputs.labels }}
build-args: |
AGENT_VERSION=${{ steps.version.outputs.agent_version }}
call-test:
uses: ./.github/workflows/test.yml
secrets: inherit
with:
INITCONTAINER_LANGUAGE: python
K8S_OPERATOR_IMAGE_TAG: edge

# call-publish:
# if: github.event_name == 'release' && endsWith(github.ref, '_python') # Skip everything if this isn't Node
# runs-on: ubuntu-latest
# needs:
# - call-test

# strategy:
# fail-fast: false
# matrix:
# node-version: [16, 18, 20]
# agent-version: ['latest']

# steps:
# - uses: actions/setup-node@v4
# - name: Get agent version
# run: |
# if [[ ${{ matrix.agent-version }} == 'latest' ]]; then
# cd nodejs && npm i newrelic@${{ matrix.agent-version }} && cd ..
# echo AGENT_VERSION=$(cat nodejs/package.json | jq -r '.dependencies."newrelic"') >> $GITHUB_ENV
# elif
# echo AGENT_VERSION=${{ matrix.agent-version }} >> $GITHUB_ENV
# fi

# - name: Format Agent Version
# id: version
# run: |
# agent_version=${{ env.AGENT_VERSION }} # Use output
# echo NEW_RELIC_AGENT_VERSION=${{ env.AGENT_VERSION }} >> $GITHUB_ENV # Make ure to send the agent version to the dockerfile
# agent_version=${agent_version##v} # Remove v prefix
# agent_version=${agent_version%%_python} # Remove language suffix
# echo "agent_version=${agent_version}" | tee -a "$GITHUB_OUTPUT"

# - name: Call Publish Workflow for ${{ matrix.node-version }}
# uses: ./.github/workflows/publish.yml
# with:
# INITCONTAINER_LANGUAGE: python
# K8S_OPERATOR_IMAGE_TAG: ${{ env.K8S_OPERATOR_IMAGE_TAG }}
# NEW_RELIC_AGENT_VERSION: ${{ env.NEW_RELIC_AGENT_VERSION }}
# AGENT_VERSION_TAG: ${{steps.version.output.agent_version}}
# RUNTIME_VERSION: ${{ matrix.node-version }}
# DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }}

0 comments on commit 3a1540d

Please sign in to comment.