Skip to content

Caller Workflow to test Fork CI pipeline #275

Caller Workflow to test Fork CI pipeline

Caller Workflow to test Fork CI pipeline #275

name: Caller Workflow to test Fork CI pipeline
permissions: write-all
on:
workflow_dispatch:
inputs:
ref_name:
description: "Branch or tag to use (e.g., network-operator-test)"
required: true
ref_type:
description: "Type of ref to use (tag or branch)"
required: true
distinct_id:
description: "Unique identifier for the run"
jobs:
# this job is needed for the parent job to de able to detect workflow run id and later its status
test:
runs-on: ubuntu-latest
steps:
- name: echo distinct ID ${{ inputs.distinct_id }}
run: echo ${{ inputs.distinct_id }}
create-test-environment:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- if: inputs.ref_type == 'tag'
name: Create release tag and branch
run: |
git tag ${{ inputs.ref_name }}
git push origin ${{ inputs.ref_name }} -f
# We need to cut the release branch from the 'network-operator' master branch
git fetch origin master --depth 1
git checkout origin/master
release_branch=$(echo ${{ inputs.ref_name }} | sed -E 's/^network-operator-([0-9]+\.[0-9]+).+/v\1.x/') # example: transforms "network-operator-25.1.0-beta.2" to "v25.1.x"
git checkout -b $release_branch
git push origin $release_branch -f
echo BRANCH=$release_branch | tee -a $GITHUB_ENV
echo TAG=${{ inputs.ref_name }} | tee -a $GITHUB_ENV
- if: inputs.ref_type == 'branch'
name: Create release branch
run: |
git checkout -b ${{ inputs.ref_name }}
git push origin ${{ inputs.ref_name }} -f
echo BRANCH=${{ inputs.ref_name }} | tee -a $GITHUB_ENV
- name: Store branch and tag
id: store-tag-branch
run: |
echo BRANCH=$BRANCH >> $GITHUB_OUTPUT
echo TAG=$TAG >> $GITHUB_OUTPUT
outputs:
branch: ${{ steps.store-tag-branch.outputs.BRANCH }}
tag: ${{ steps.store-tag-branch.outputs.TAG }}
call-reusable-ci-fork-workflow:
needs: create-test-environment
uses: ./.github/workflows/fork-ci-reusable.yml
with:
registry-internal: ghcr.io/mellanox
service-account-username: nvidia-ci-cd
service-account-email: [email protected]
components: '[{"name": "nicConfigurationOperator", "imageName": "cloud-orchestration-reusable-workflows", "dockerfile": "Dockerfile.test"}, {"name": "nicConfigurationConfigDaemon", "imageName": "another-cloud-orchestration-reusable-workflows", "dockerfile": "Dockerfile.another-test"}]'
chart-name: node-feature-discovery
chart-path: "charts-to-test/node-feature-discovery"
exclude-chart-files: '["Chart.yaml", "new-file-to-exclude"]'
ref-name: ${{ inputs.ref_name }}
ref-type: ${{ inputs.ref_type }}
network-operator-repo: cloud-orchestration-reusable-workflows
secrets:
registry-username: ${{ github.repository_owner }}
registry-token: ${{ secrets.GITHUB_TOKEN }}
cicd-gh-token: ${{ secrets.GITHUB_TOKEN }}
goproxy: "direct"
validate-docker-images-built:
needs: call-reusable-ci-fork-workflow
runs-on: ubuntu-latest
env:
DOCKER_TAG: ${{ needs.call-reusable-ci-fork-workflow.outputs.docker-tag }}
DOCKER_REGISTRY: ghcr.io/mellanox
EXPECTED_PLATFORMS: "linux/amd64,linux/arm64"
steps:
- name: Login to Container Registry
uses: docker/login-action@v3
with:
registry: ${{ env.DOCKER_REGISTRY }}
username: ${{ github.repository_owner }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Validate that docker images were built successfully
run: |
echo "Validating that docker tag was generated: $DOCKER_TAG"
if [ -z "$DOCKER_TAG" ]; then
echo "Error: Docker tag was not generated" >&2
exit 1
fi
# Define the images to check based on the components from the workflow
IMAGES=(
"$DOCKER_REGISTRY/cloud-orchestration-reusable-workflows:$DOCKER_TAG"
"$DOCKER_REGISTRY/another-cloud-orchestration-reusable-workflows:$DOCKER_TAG"
)
echo "Verifying built images with docker manifest..."
for image in "${IMAGES[@]}"; do
echo "Checking image: $image"
# Check if the image manifest exists
if ! docker manifest inspect "$image" > /dev/null 2>&1; then
echo "Error: Image $image does not exist or cannot be accessed" >&2
exit 1
fi
# Get the manifest and check platforms
MANIFEST=$(docker manifest inspect "$image" 2>/dev/null)
if [ $? -ne 0 ]; then
echo "Error: Failed to inspect manifest for $image" >&2
exit 1
fi
# Extract platforms from manifest
PLATFORMS=$(echo "$MANIFEST" | jq -r '.manifests[]?.platform | select(. != null) | "\(.os)/\(.architecture)"' | sort | tr '\n' ',' | sed 's/,$//')
echo "Found platforms for $image: $PLATFORMS"
# Check if expected platforms are present
IFS=',' read -ra EXPECTED_ARRAY <<< "$EXPECTED_PLATFORMS"
for expected_platform in "${EXPECTED_ARRAY[@]}"; do
if [[ "$PLATFORMS" != *"$expected_platform"* ]]; then
echo "Error: Expected platform $expected_platform not found in image $image" >&2
echo "Available platforms: $PLATFORMS" >&2
exit 1
fi
done
echo "Successfully verified image $image with platforms: $PLATFORMS"
done
echo "All docker images successfully verified!"
cleanup:
if: always()
env:
GH_TOKEN: ${{ github.token }}
needs:
- create-test-environment
- validate-docker-images-built
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- name: Delete all tags and branches that might have been created in the repo
env:
BRANCH: ${{ needs.create-test-environment.outputs.branch }}
TAG: ${{ needs.create-test-environment.outputs.tag }}
run: |
if [ -n "$BRANCH" ]; then
echo "Deleting branch $BRANCH from origin..."
git push origin --delete "$BRANCH"
fi
if [ -n "$TAG" ]; then
echo "Deleting tag $TAG from origin..."
git push origin --delete refs/tags/$TAG
fi
echo "Test completed successfully - no cleanup needed since no test resources were created"