Skip to content

Commit 198d943

Browse files
committed
test: add actions to .github
Signed-off-by: Peter Balogh <p.balogh.sa@gmail.com>
1 parent d30c4e2 commit 198d943

File tree

5 files changed

+205
-29
lines changed

5 files changed

+205
-29
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
6+
name: Detect changes
7+
description: Detect changes in as list of directories
8+
inputs:
9+
dirs:
10+
description: 'Directories where to search for changes'
11+
required: true
12+
default: "./"
13+
outputs:
14+
changed-dirs:
15+
description: 'Directories with changes'
16+
value: ${{ steps.detect-changes.outputs.changed-dirs }}
17+
18+
runs:
19+
using: "composite"
20+
steps:
21+
- name: Detect changes
22+
id: detect-changes
23+
run: |
24+
# Function to get the diff in a directory in case of pr or push event
25+
get_diff() {
26+
dir=${1}
27+
28+
if [[ "${{ github.event_name }}" == "pull_request" ]]; then
29+
base_ref="${{ github.event.pull_request.base.sha }}"
30+
head_ref="${{ github.event.pull_request.head.sha }}"
31+
else
32+
# For push to main, compare against the previous commit
33+
base_ref="${{ github.event.before }}"
34+
head_ref="${{ github.sha }}"
35+
fi
36+
37+
git diff --quiet --name-only $base_ref $head_ref -- ${dir}
38+
}
39+
40+
# Check if any of the folder have changed
41+
CHANGED_DIRS=()
42+
for DIR in ${{ inputs.dirs }}; do
43+
if get_diff ${DIR}; then
44+
echo "No changes in ${DIR}"
45+
else
46+
echo "Changes detected in ${DIR}"
47+
CHANGED_DIRS+=($DIR)
48+
fi
49+
done
50+
51+
# Set the output variable
52+
dirs_out=$(echo -n ${CHANGED_DIRS[*]} | jq -R -s -c 'split(" ") | map(select(length > 0))')
53+
echo changed-dirs=${dirs_out} >> $GITHUB_OUTPUT
54+
shell: bash
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
6+
name: Setup Kubernetes tooling
7+
description: Setup Kubernetes tooling
8+
inputs:
9+
helm-version:
10+
description: 'Helm version'
11+
required: false
12+
default: "3.12.1"
13+
helm-ct-version:
14+
description: 'Helm chart-testing version'
15+
required: false
16+
default: "3.11.0"
17+
kind-version:
18+
description: 'Kind version'
19+
required: false
20+
default: "0.24.0"
21+
kind-create-cluster:
22+
description: 'Create kind K8s cluster'
23+
required: false
24+
default: "false"
25+
kind-cluster-name:
26+
description: 'Kind K8s cluster name to create'
27+
required: false
28+
default: "kind"
29+
kind-cluster-gateway:
30+
description: 'Gateway IP to use for kind server nodes. Useful when running actions inside containers.'
31+
required: false
32+
default: "127.0.0.1"
33+
runs:
34+
using: "composite"
35+
steps:
36+
#
37+
# Install kubernetes tools
38+
#
39+
- name: Setup Helm
40+
uses: azure/setup-helm@fe7b79cd5ee1e45176fcad797de68ecaf3ca4814 # v4.2.0
41+
with:
42+
version: ${{ inputs.helm-version }}
43+
44+
- name: Set up Helm chart-testing
45+
uses: helm/chart-testing-action@e6669bcd63d7cb57cb4380c33043eebe5d111992 # v2.6.1
46+
with:
47+
version: ${{ inputs.helm-ct-version }}
48+
49+
- name: Setup kind
50+
uses: helm/kind-action@0025e74a8c7512023d06dc019c617aa3cf561fde # v1.10.0
51+
with:
52+
version: v${{ inputs.kind-version }}
53+
install_only: true
54+
55+
- name: Setup kubectl
56+
uses: azure/setup-kubectl@3e0aec4d80787158d308d7b364cb1b702e7feb7f # v4.0.0
57+
58+
#
59+
# Setup cluster
60+
#
61+
- name: Setup Kind cluster
62+
if: ${{ inputs.kind-create-cluster == 'true' }}
63+
shell: bash
64+
run: |
65+
# Create cluster config
66+
KIND_CONFIG_FILE=$(mktemp -p /tmp)
67+
cat <<EOF > $KIND_CONFIG_FILE
68+
kind: Cluster
69+
apiVersion: kind.x-k8s.io/v1alpha4
70+
networking:
71+
apiServerAddress: "${{ inputs.kind-cluster-gateway }}"
72+
apiServerPort: 6443
73+
EOF
74+
75+
# Create cluster
76+
kind create cluster --config $KIND_CONFIG_FILE --name ${{ inputs.kind-cluster-name }}
77+
kubectl cluster-info
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2025 Cisco and/or its affiliates.
2+
# SPDX-License-Identifier: Apache-2.0
3+
4+
---
5+
6+
name: Setup Python Environment
7+
description: setup environment to build/test/lint python applications
8+
inputs:
9+
py-version:
10+
description: 'Python version to install'
11+
required: false
12+
default: "3.12"
13+
py-package-manager:
14+
description: 'Python package manager to use'
15+
required: false
16+
default: "poetry"
17+
py-poetry-version:
18+
description: 'Poetry version to use'
19+
required: false
20+
default: "1.7.1"
21+
22+
runs:
23+
using: "composite"
24+
steps:
25+
- name: Setup Python
26+
id: setup-python
27+
uses: actions/setup-python@v5
28+
with:
29+
python-version: ${{ inputs.py-version }}
30+
31+
- name: Load cached Poetry Binary
32+
uses: actions/cache@v4
33+
with:
34+
path: ~/.local
35+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ inputs.py-poetry-version }}
36+
37+
- name: Install Poetry
38+
shell: bash
39+
run: |
40+
if [[ -f ~/.local/bin/poetry ]]; then
41+
echo "Poetry already installed"
42+
else
43+
curl -sSL https://install.python-poetry.org | POETRY_VERSION=${{ inputs.py-poetry-version }} python3 -
44+
fi
45+
46+
- name: Install uv
47+
shell: bash
48+
run: |
49+
curl -LsSf https://astral.sh/uv/install.sh | env UV_INSTALL_DIR="${HOME}/.local/bin" sh
50+
51+
- name: Load cached venv
52+
uses: actions/cache@v4
53+
with:
54+
path: ~/.cache/pypoetry/virtualenvs
55+
key: venv-${{ runner.os }}-${{ steps.setup-python.outputs.python-version }}-${{ hashFiles('**/poetry.lock') }}
56+
57+
- name: Update GITHUB_PATH
58+
shell: bash
59+
run: echo "$HOME/.local/bin" >> $GITHUB_PATH

.github/workflows/test-integrations.yaml

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ on:
2121
description: 'Python version to install'
2222
required: false
2323
default: '3.12'
24+
kind-version:
25+
description: 'Kind version'
26+
required: false
27+
default: '0.24.0'
2428

2529
jobs:
2630
run-tests-gateway:
@@ -42,16 +46,16 @@ jobs:
4246
uses: docker/login-action@v3
4347
with:
4448
registry: ghcr.io
45-
username: ${{github.actor}}
46-
password: ${{secrets.github-token}}
49+
username: ${{ github.actor }}
50+
password: ${{ secrets.GITHUB_TOKEN }}
4751

4852
- name: Setup Taskfile
4953
shell: bash
5054
run: sh -c "$(curl --location https://taskfile.dev/install.sh)" -- -d -b ~/.local/bin
5155

5256
- name: Setup Python
5357
if: ${{ inputs.python == 'true' }}
54-
uses: cisco-eti/phoenix-actions/setup-python@setup-python-v1.0.1
58+
uses: ./.github/actions/setup-python
5559
with:
5660
py-version: ${{ inputs.python-version }}
5761

@@ -60,7 +64,7 @@ jobs:
6064
run: echo "$HOME/.local/bin" >> $GITHUB_PATH
6165

6266
- name: Setup K8S Tools
63-
uses: cisco-eti/phoenix-actions/setup-k8s@setup-k8s-v0.0.2
67+
uses: ./.github/actions/setup-k8s
6468
with:
6569
kind-version: "0.25.0"
6670

.github/workflows/test-samples.yaml

Lines changed: 7 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ jobs:
2424
fetch-depth: 0
2525

2626
- name: Detect changes
27-
uses: cisco-eti/phoenix-actions/detect-changes@detect-changes-v0.0.3
27+
uses: ./.github/actions/detect-changes
2828
id: detect-changes
2929
with:
3030
dirs: $(find ./samples \( -name 'pyproject.toml' -o -name 'Taskfile.yaml' \) | xargs -n1 dirname | sort -u)
@@ -44,39 +44,21 @@ jobs:
4444
with:
4545
fetch-depth: 0
4646

47-
- name: Setup Environment
48-
uses: cisco-eti/phoenix-actions/setup-env@setup-env-v0.0.8
47+
- name: Setup Python
48+
uses: ./.github/actions/setup-python
4949
with:
50-
python: true
51-
python-version: "3.12"
52-
node: false
53-
go: false
54-
keeper-phoenix-role-id: ${{ secrets.VAULT_PHOENIX_APPROLE_ROLE_ID }}
55-
keeper-phoenix-secret-id: ${{ secrets.VAULT_PHOENIX_APPROLE_SECRET_ID }}
56-
57-
- name: Import Vault Secrets
58-
id: import-secrets
59-
uses: cisco-eti/phoenix-actions/vault-action@vault-action-v1.0.0 # proxy
60-
with:
61-
method: approle
62-
url: ${{ vars.KEEPER_URL }}
63-
roleId: ${{ secrets.VAULT_ESPRESSO_APPROLE_ROLE_ID }}
64-
secretId: ${{ secrets.VAULT_ESPRESSO_APPROLE_SECRET_ID }}
65-
namespace: eticloud/apps/espresso
66-
secrets: |
67-
secret/data/artifactory.devhub-cloud.cisco.com identity-token | DEVHUB_CLOUD_TOKEN ;
68-
secret/data/artifactory.devhub-cloud.cisco.com username | DEVHUB_CLOUD_USERNAME ;
50+
py-version: "3.12"
6951

7052
- name: Setup K8S Tools
71-
uses: cisco-eti/phoenix-actions/setup-k8s@setup-k8s-v0.0.2
53+
uses: ./.github/actions/setup-k8s
7254
with:
7355
kind-version: "0.25.0"
7456

7557
- name: Run tests
7658
env:
7759
POETRY_REPOSITORIES_DEVHUBCLOUD_URL: "https://artifactory.devhub-cloud.cisco.com/artifactory/api/pypi/espresso-cloud-pypi"
78-
POETRY_HTTP_BASIC_DEVHUBCLOUD_USERNAME: ${{ env.DEVHUB_CLOUD_USERNAME }}
79-
POETRY_HTTP_BASIC_DEVHUBCLOUD_PASSWORD: ${{ env.DEVHUB_CLOUD_TOKEN }}
60+
POETRY_HTTP_BASIC_DEVHUBCLOUD_USERNAME: ${{ secrets.DEVHUB_CLOUD_USERNAME }}
61+
POETRY_HTTP_BASIC_DEVHUBCLOUD_PASSWORD: ${{ secrets.DEVHUB_CLOUD_TOKEN }}
8062
run: |
8163
cd ${{ matrix.app }}
8264
task run:test

0 commit comments

Comments
 (0)