From 22756a1b63fe23a4ae8ffc042a6ea8f197d84ef3 Mon Sep 17 00:00:00 2001 From: Art Morozov Date: Wed, 10 Jul 2024 09:59:13 -0400 Subject: [PATCH 1/2] Add CI and release workflows --- .env_template | 10 ++ .github/workflows/ci.yaml | 135 ++++++++++++++++++ .github/workflows/release.yaml | 76 ++++++++++ pyproject.toml | 27 +++- .../components/__init__.py | 3 + 5 files changed, 249 insertions(+), 2 deletions(-) create mode 100644 .env_template create mode 100644 .github/workflows/ci.yaml create mode 100644 .github/workflows/release.yaml diff --git a/.env_template b/.env_template new file mode 100644 index 0000000..cdf2904 --- /dev/null +++ b/.env_template @@ -0,0 +1,10 @@ +SOLACE_BROKER_URL="tcps://your_service.messaging.solace.cloud:55443" +SOLACE_BROKER_USERNAME= +SOLACE_BROKER_PASSWORD= +SOLACE_BROKER_VPN= +SOLACE_BROKER_TRUST_STORE_PATH="/usr/share/ca-certificates/mozilla" + +AZURE_OPENAI_API_KEY= +AZURE_OPENAI_API_ENDPOINT= +AZURE_OPENAI_API_VERSION= +AZURE_OPENAI_MODEL_DEPLOYMENT= \ No newline at end of file diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..0a666d4 --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,135 @@ +name: CI +on: + push: + branches: + - main + pull_request: + types: [opened, synchronize] + +permissions: + id-token: write + checks: write + pull-requests: write + contents: write + +jobs: + test: + runs-on: ubuntu-latest + env: + HATCH_CACHE_DIR: ${{ github.workspace }}/.hatch_cache + HATCH_DATA_DIR: ${{ github.workspace }}/.hatch_data + + steps: + - uses: actions/checkout@v4 + with: + fetch-depth: 0 + + - name: Install Hatch + uses: pypa/hatch@install + + - name: Restore Hatch Directory + uses: actions/cache/restore@v4 + id: cache-restore + with: + path: | + ${{ env.HATCH_CACHE_DIR }} + ${{ env.HATCH_DATA_DIR }} + key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }} + + - name: Install Dependencies + if: steps.cache-restore.outputs.cache-hit != 'true' + run: | + hatch python install 3.8 3.12 + + - name: Install Dependencies + if: steps.cache-restore.outputs.cache-hit != 'true' + run: | + hatch env create test + + - name: Cache Hatch Directory + uses: actions/cache/save@v4 + if: steps.cache-restore.outputs.cache-hit != 'true' + id: cache-hatch + with: + path: | + ${{ env.HATCH_CACHE_DIR }} + ${{ env.HATCH_DATA_DIR }} + key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }} + + - name: Run Lint + continue-on-error: true + run: | + hatch run lint:ruff check -o lint.json --output-format json + shell: bash + + - name: Run Unit Tests + continue-on-error: true + shell: bash + run: | + hatch test --cover --all --parallel --junitxml=junit.xml + + - name: Combine Coverage Reports + continue-on-error: true + run: | + hatch run +py=3.12 test:coverage combine + shell: bash + + - name: Report coverage + continue-on-error: true + run: | + hatch run +py=3.12 test:coverage xml + shell: bash + + - name: SonarQube Scan + if: always() + uses: sonarsource/sonarqube-scan-action@v2.2.0 + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} + with: + args: > + -Dsonar.tests=tests/ + -Dsonar.verbose=true + -Dsonar.sources=src/ + -Dsonar.projectKey=${{github.repository_owner}}_${{github.event.repository.name}} + -Dsonar.python.coverage.reportPaths=coverage.xml + -Dsonar.python.ruff.reportPaths=lint.json + + - name: SonarQube Quality Gate check + id: sonarqube-quality-gate-check + uses: sonarsource/sonarqube-quality-gate-action@master + env: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} + + # Build and verify packages + - name: Build + run: hatch build + + - name: Verify Packages + run: | + ls dist/*.tar.gz | hatch run +py=3.12 test:xargs -n1 twine check + ls dist/*.whl | hatch run +py=3.12 test:xargs -n1 twine check + shell: bash + + - name: Surface failing tests + if: always() + uses: pmeier/pytest-results-action@main + with: + # A list of JUnit XML files, directories containing the former, and wildcard + # patterns to process. + # See @actions/glob for supported patterns. + path: junit.xml + + # (Optional) Add a summary of the results at the top of the report + summary: true + + # (Optional) Select which results should be included in the report. + # Follows the same syntax as `pytest -r` + display-options: fEX + + # (Optional) Fail the workflow if no JUnit XML was found. + fail-on-empty: true + + # (Optional) Title of the test results section in the workflow summary + title: Unit Test results diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..27e2412 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,76 @@ +name: Release +on: + workflow_dispatch: + inputs: + version: + type: choice + required: true + description: "Version bump type" + options: + - patch + - minor + - major + +jobs: + release: + name: Release + timeout-minutes: 20 + runs-on: ubuntu-latest + environment: + name: pypi + url: https://pypi.org/p/solace_ai_connector_slack + permissions: + id-token: write + contents: write + + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + fetch-depth: 0 + ssh-key: ${{ secrets.COMMIT_KEY }} + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: "3.x" + + - name: Install hatch + run: | + pip install --upgrade pip + pip install hatch + - name: Get Current Version + run: | + CURRENT_VERSION=$(hatch version) + echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV + + - name: Fail if the current version doesn't exist + if: env.CURRENT_VERSION == '' + run: exit 1 + + - name: Build project for distribution + run: hatch build + + - name: Publish package distributions to PyPI + uses: pypa/gh-action-pypi-publish@release/v1 + + - name: Create Release + uses: ncipollo/release-action@v1 + with: + artifacts: "dist/*.whl" + makeLatest: true + generateReleaseNotes: true + tag: ${{ env.CURRENT_VERSION }} + + - name: Bump Version + run: | + hatch version "${{ github.event.inputs.version }}" + NEW_VERSION=$(hatch version) + echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV + + - name: Commit new version + run: | + git config --local user.email "action@github.com" + git config --local user.name "GitHub Action" + git commit -a -m "[ci skip] Bump version to $NEW_VERSION" + git push diff --git a/pyproject.toml b/pyproject.toml index a9c3890..ff6f3ae 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -5,7 +5,7 @@ build-backend = "hatchling.build" [project] name = "solace_ai_connector_slack" -version = "0.0.1" +dynamic = ["version"] authors = [ { name="Edward Funnekotter", email="edward.funnekotter@solace.com" }, ] @@ -20,7 +20,7 @@ classifiers = [ dependencies = [ "PyYAML>=6.0.1", "slack_bolt>=1.18.1", - "solace_ai_connector>=0.0.1", + "solace_ai_connector>=0.1.1", ] [project.urls] @@ -31,3 +31,26 @@ documentation = "https://github.com/SolaceLabs/solace-ai-connector-slack/blob/ma [tool.hatch.build.targets.wheel] packages = ["src/solace_ai_connector_slack"] + +[tool.hatch.version] +path = "src/solace_ai_connector_slack/components/__init__.py" + +[tool.hatch.envs.test] +dependencies = [ + "pytest>=8.2.2", + "coverage>=7.5.4", + "twine>=5.1.1", +] + +[tool.hatch.envs.lint] +detached = true +dependencies = [ + "ruff>=0.5.0", +] + +[tool.ruff] +lint.select = ["E4", "E7", "E9", "F"] +lint.ignore = ["F401", "E731"] + +[[tool.hatch.envs.test.matrix]] +python = ["3.8", "3.12"] \ No newline at end of file diff --git a/src/solace_ai_connector_slack/components/__init__.py b/src/solace_ai_connector_slack/components/__init__.py index e69de29..8e9a09e 100644 --- a/src/solace_ai_connector_slack/components/__init__.py +++ b/src/solace_ai_connector_slack/components/__init__.py @@ -0,0 +1,3 @@ +# Internal components that are dynamically loaded by the AI Connector +# Listing them here allows for them to use relative imports +__version__ = "0.0.1" From 9f334a1556aabac69e03c94216e857f076696937 Mon Sep 17 00:00:00 2001 From: Art Morozov Date: Tue, 16 Jul 2024 17:10:35 -0400 Subject: [PATCH 2/2] Reuse workflows for CI and release --- .github/workflows/ci.yaml | 125 ++------------------------------- .github/workflows/release.yaml | 71 +++---------------- pyproject.toml | 16 ----- 3 files changed, 15 insertions(+), 197 deletions(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index 0a666d4..7789766 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -13,123 +13,8 @@ permissions: contents: write jobs: - test: - runs-on: ubuntu-latest - env: - HATCH_CACHE_DIR: ${{ github.workspace }}/.hatch_cache - HATCH_DATA_DIR: ${{ github.workspace }}/.hatch_data - - steps: - - uses: actions/checkout@v4 - with: - fetch-depth: 0 - - - name: Install Hatch - uses: pypa/hatch@install - - - name: Restore Hatch Directory - uses: actions/cache/restore@v4 - id: cache-restore - with: - path: | - ${{ env.HATCH_CACHE_DIR }} - ${{ env.HATCH_DATA_DIR }} - key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }} - - - name: Install Dependencies - if: steps.cache-restore.outputs.cache-hit != 'true' - run: | - hatch python install 3.8 3.12 - - - name: Install Dependencies - if: steps.cache-restore.outputs.cache-hit != 'true' - run: | - hatch env create test - - - name: Cache Hatch Directory - uses: actions/cache/save@v4 - if: steps.cache-restore.outputs.cache-hit != 'true' - id: cache-hatch - with: - path: | - ${{ env.HATCH_CACHE_DIR }} - ${{ env.HATCH_DATA_DIR }} - key: ${{ runner.os }}-hatch-${{ hashFiles('pyproject.toml') }} - - - name: Run Lint - continue-on-error: true - run: | - hatch run lint:ruff check -o lint.json --output-format json - shell: bash - - - name: Run Unit Tests - continue-on-error: true - shell: bash - run: | - hatch test --cover --all --parallel --junitxml=junit.xml - - - name: Combine Coverage Reports - continue-on-error: true - run: | - hatch run +py=3.12 test:coverage combine - shell: bash - - - name: Report coverage - continue-on-error: true - run: | - hatch run +py=3.12 test:coverage xml - shell: bash - - - name: SonarQube Scan - if: always() - uses: sonarsource/sonarqube-scan-action@v2.2.0 - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} - with: - args: > - -Dsonar.tests=tests/ - -Dsonar.verbose=true - -Dsonar.sources=src/ - -Dsonar.projectKey=${{github.repository_owner}}_${{github.event.repository.name}} - -Dsonar.python.coverage.reportPaths=coverage.xml - -Dsonar.python.ruff.reportPaths=lint.json - - - name: SonarQube Quality Gate check - id: sonarqube-quality-gate-check - uses: sonarsource/sonarqube-quality-gate-action@master - env: - SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} - SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} - - # Build and verify packages - - name: Build - run: hatch build - - - name: Verify Packages - run: | - ls dist/*.tar.gz | hatch run +py=3.12 test:xargs -n1 twine check - ls dist/*.whl | hatch run +py=3.12 test:xargs -n1 twine check - shell: bash - - - name: Surface failing tests - if: always() - uses: pmeier/pytest-results-action@main - with: - # A list of JUnit XML files, directories containing the former, and wildcard - # patterns to process. - # See @actions/glob for supported patterns. - path: junit.xml - - # (Optional) Add a summary of the results at the top of the report - summary: true - - # (Optional) Select which results should be included in the report. - # Follows the same syntax as `pytest -r` - display-options: fEX - - # (Optional) Fail the workflow if no JUnit XML was found. - fail-on-empty: true - - # (Optional) Title of the test results section in the workflow summary - title: Unit Test results + ci: + uses: SolaceDev/solace-public-workflows/.github/workflows/hatch_ci.yml@v1.0.0 + secrets: + SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }} + SONAR_HOST_URL: ${{ vars.SONAR_HOST_URL }} diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml index 27e2412..ace235f 100644 --- a/.github/workflows/release.yaml +++ b/.github/workflows/release.yaml @@ -11,66 +11,15 @@ on: - minor - major +permissions: + id-token: write + checks: write + jobs: release: - name: Release - timeout-minutes: 20 - runs-on: ubuntu-latest - environment: - name: pypi - url: https://pypi.org/p/solace_ai_connector_slack - permissions: - id-token: write - contents: write - - steps: - - name: Checkout - uses: actions/checkout@v4 - with: - fetch-depth: 0 - ssh-key: ${{ secrets.COMMIT_KEY }} - - - name: Set up Python - uses: actions/setup-python@v5 - with: - python-version: "3.x" - - - name: Install hatch - run: | - pip install --upgrade pip - pip install hatch - - name: Get Current Version - run: | - CURRENT_VERSION=$(hatch version) - echo "CURRENT_VERSION=${CURRENT_VERSION}" >> $GITHUB_ENV - - - name: Fail if the current version doesn't exist - if: env.CURRENT_VERSION == '' - run: exit 1 - - - name: Build project for distribution - run: hatch build - - - name: Publish package distributions to PyPI - uses: pypa/gh-action-pypi-publish@release/v1 - - - name: Create Release - uses: ncipollo/release-action@v1 - with: - artifacts: "dist/*.whl" - makeLatest: true - generateReleaseNotes: true - tag: ${{ env.CURRENT_VERSION }} - - - name: Bump Version - run: | - hatch version "${{ github.event.inputs.version }}" - NEW_VERSION=$(hatch version) - echo "NEW_VERSION=${NEW_VERSION}" >> $GITHUB_ENV - - - name: Commit new version - run: | - git config --local user.email "action@github.com" - git config --local user.name "GitHub Action" - git commit -a -m "[ci skip] Bump version to $NEW_VERSION" - git push + uses: SolaceDev/solace-public-workflows/.github/workflows/hatch_release_pypi.yml@v1.0.0 + with: + version: ${{ github.event.inputs.version }} + pypi-project: solace-ai-connector-slack + secrets: + COMMIT_KEY: ${{ secrets.COMMIT_KEY }} diff --git a/pyproject.toml b/pyproject.toml index ff6f3ae..79c46df 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -35,22 +35,6 @@ packages = ["src/solace_ai_connector_slack"] [tool.hatch.version] path = "src/solace_ai_connector_slack/components/__init__.py" -[tool.hatch.envs.test] -dependencies = [ - "pytest>=8.2.2", - "coverage>=7.5.4", - "twine>=5.1.1", -] - -[tool.hatch.envs.lint] -detached = true -dependencies = [ - "ruff>=0.5.0", -] - [tool.ruff] lint.select = ["E4", "E7", "E9", "F"] lint.ignore = ["F401", "E731"] - -[[tool.hatch.envs.test.matrix]] -python = ["3.8", "3.12"] \ No newline at end of file