Overview
The kubernetes-client/csharp
project is equipped with automation scripts for CI/CD processes. The current setup utilizes GitHub Actions to automate build, test, and other essential processes associated with the development life cycle. This documentation provides a step-by-step guide to understand these automation scripts and how to effectively utilize them.
CI/CD Automation Scripts
Existing CI/CD Setup
The CI/CD setup leverages GitHub Actions through defined workflows located in the .github/workflows/
directory. Here’s a breakdown of the available workflows:
Build and Test Workflow
- File:
.github/workflows/buildtest.yaml
- This workflow is responsible for building the project and executing tests upon each push or pull request. It ensures that all changes to the codebase are valid by running the unit tests using XUnit.
Example Configuration
name: Build and Test on: push: branches: - main pull_request: branches: - main jobs: build: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: '6.0.x' - name: Restore dependencies run: dotnet restore - name: Build run: dotnet build --no-restore - name: Test run: dotnet test --no-build --verbosity normal
- File:
NuGet Package Workflow
- File:
.github/workflows/nuget.yaml
- This workflow is designed to automatically publish NuGet packages when a new version is tagged. It ensures that the latest version of the library is published to the NuGet repository when tagged commits occur.
Example Configuration
name: Publish NuGet Package on: push: tags: - 'v*.*.*' jobs: publish: runs-on: ubuntu-latest steps: - name: Checkout code uses: actions/checkout@v2 - name: Setup .NET uses: actions/setup-dotnet@v1 with: dotnet-version: '6.0.x' - name: Pack run: dotnet pack --configuration Release --no-build --output ./nupkgs - name: Push to NuGet run: dotnet nuget push ./nupkgs/*.nupkg -k ${{ secrets.NUGET_API_KEY }} -s 'https://api.nuget.org/v3/index.json'
- File:
Other Workflow Files
CodeQL Analysis
- File:
.github/workflows/codeql-analysis.yml
- Implements static code analysis for security vulnerabilities.
- File:
Documentation Workflow
- File:
.github/workflows/docfx.yaml
- Automates the building and deployment of project documentation.
- File:
Running CI/CD Locally
To run the tests locally, you can follow these steps:
cd csharp/tests
dotnet restore
dotnet test
Next Steps if CI/CD is Not Set Up
If the CI/CD processes are not yet set up for this project, consider implementing the following steps:
Choose a CI/CD Tool:
- Use popular services such as GitHub Actions, Azure DevOps, GitLab CI, or CircleCI, depending on the project hosting platform.
Define Workflows:
- Create YAML files that specify jobs for building, testing, and deploying your application.
Add Triggers:
- Define events on which the workflows should trigger, such as push events, pull requests, or scheduled workflows.
Test and Validate:
- Ensure that your defined workflows run correctly by committing a change and observing whether the CI/CD pipeline executes as expected.
Monitor and Improve:
- Monitor the performance of builds and tests. Tweak them as needed to suit the evolving needs of the project.
By effectively setting up and automating CI/CD workflows, the development process can be streamlined, leading to a more efficient development lifecycle.