testing: add unit testing (#11) #35
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
name: CI/CD | |
on: | |
pull_request: | |
push: | |
tags: | |
- "*" | |
branches: | |
- main | |
env: | |
MAIN_PYTHON_VERSION: '3.12' | |
concurrency: | |
group: ${{ github.workflow }}-${{ github.ref }} | |
cancel-in-progress: true | |
permissions: | |
contents: write | |
packages: write | |
jobs: | |
code-style: | |
name: "Code style checks" | |
runs-on: ubuntu-latest | |
steps: | |
- name: "Run PyAnsys code style checks" | |
uses: ansys/actions/code-style@v6 | |
tests: | |
name: "Tests" | |
runs-on: ${{ matrix.os }} | |
needs: [code-style] | |
strategy: | |
matrix: | |
os: [ubuntu-latest, windows-latest] | |
python-version: ['3.9', '3.12'] | |
fail-fast: false | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v5 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install -r requirements.txt | |
- name: Testing | |
uses: ansys/actions/tests-pytest@v6 | |
timeout-minutes: 12 | |
with: | |
checkout: false | |
skip-install: true | |
pytest-extra-args: "--cov=ansys.allie.flowkit.python --cov-report=term --cov-report=html:.cov/html --cov-report=xml:.cov/coverage.xml" | |
- name: Upload coverage results (HTML) | |
uses: actions/upload-artifact@v4 | |
if: (matrix.python-version == env.MAIN_PYTHON_VERSION) && (runner.os == 'Linux') | |
with: | |
name: coverage-html | |
path: .cov/html | |
retention-days: 7 | |
release: | |
name: "Release project" | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags') | |
needs: [code-style] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout code | |
uses: actions/checkout@v4 | |
- name: Release to GitHub | |
uses: softprops/action-gh-release@v2 | |
with: | |
generate_release_notes: true | |
release-docker: | |
name : Generate Docker release | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags') | |
needs: [release] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout repository | |
uses: actions/checkout@v4 | |
- name: Set up Docker Buildx | |
uses: docker/setup-buildx-action@v3 | |
- name: Login to GitHub Container Registry | |
uses: docker/login-action@v3 | |
with: | |
registry: ghcr.io | |
username: ${{ github.actor }} | |
password: ${{ secrets.GITHUB_TOKEN }} | |
- name: Check if tag name contains 'dev' | |
run: echo "IS_DEV_TAG=$(echo ${{ github.ref_name }} | grep -q 'dev' && echo 'true' || echo 'false')" >> $GITHUB_ENV | |
- name: Decompose tag into components | |
if: env.IS_DEV_TAG == 'false' | |
run: | | |
if [[ ${{ github.ref_name }} =~ ^v[0-9]+\.[0-9]+\.[0-9]+$ ]]; then | |
# Split the tag into its components | |
IFS='.' read -ra PARTS <<< "${{ github.ref_name }}" | |
echo "X=${PARTS[0]}" >> $GITHUB_ENV | |
echo "Y=${PARTS[1]}" >> $GITHUB_ENV | |
echo "Z=${PARTS[2]}" >> $GITHUB_ENV | |
else | |
echo "Invalid tag format. Expected vX.Y.Z but got ${{ github.ref_name }}" | |
exit 1 | |
fi | |
- name: Build and push Docker image | |
uses: docker/build-push-action@v6 | |
if: env.IS_DEV_TAG == 'false' | |
with: | |
context: . | |
file: docker/Dockerfile | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ env.X }} , | |
ghcr.io/${{ github.repository }}:${{ env.X }}.${{ env.Y }} , | |
ghcr.io/${{ github.repository }}:${{ env.X }}.${{ env.Y }}.${{ env.Z }} , | |
ghcr.io/${{ github.repository }}:latest | |
- name: Build and push Docker image dev | |
if: env.IS_DEV_TAG == 'true' | |
uses: docker/build-push-action@v6 | |
with: | |
context: . | |
file: docker/Dockerfile | |
push: true | |
platforms: linux/amd64,linux/arm64 | |
tags: | | |
ghcr.io/${{ github.repository }}:${{ github.ref_name }} | |
main-repo-release: | |
name: Update main allie repo and create release | |
if: github.event_name == 'push' && contains(github.ref, 'refs/tags') | |
needs: [release-docker, release] | |
runs-on: ubuntu-latest | |
steps: | |
- name: Checkout allie repository | |
run: | | |
git clone --branch main https://${{ secrets.ALLIE_RELEASE_TOKEN }}@github.com/ansys-internal/allie.git | |
- name: Setup Go | |
uses: actions/setup-go@v5 | |
with: | |
go-version-file: 'allie/scripts/releasehelper/go.mod' | |
- name: Run tag script | |
run: | | |
cd allie/scripts/releasehelper | |
go run main.go "tag" ${{ github.ref_name }} ${{ secrets.ALLIE_RELEASE_TOKEN }} | |
- name: Commit and push to allie | |
run: | | |
cd allie | |
git config --global user.email '${{ github.actor }}@users.noreply.github.com' | |
git config --global user.name '${{ github.actor }}' | |
git commit -a -m 'New release triggered by ${{ github.event.repository.name }}' | |
git push origin main | |
- name: Run release script | |
run: | | |
cd allie/scripts/releasehelper | |
go run main.go "release" ${{ github.ref_name }} ${{ secrets.ALLIE_RELEASE_TOKEN }} |