Update README.md #6
This file contains hidden or 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 | |
| on: | |
| push: | |
| branches: | |
| - '**' | |
| - 'feature/**' | |
| - '!ws-iac-scan-results/**' | |
| - '!whitesource-remediate/master-all**' | |
| - '!whitesource/migrate-configuration**' | |
| tags: | |
| - '*' | |
| env: | |
| TOOL_NAME: mend_project_cleanup_tool | |
| GIT_USER: ${{ github.actor }} | |
| COMMIT_ID: ${{ github.sha }} | |
| jobs: | |
| build-and-test: | |
| runs-on: ubuntu-latest | |
| outputs: | |
| python_version: ${{ steps.set_env_vars.outputs.PYTHON_VERSION }} | |
| min_py_ver: ${{ steps.set_env_vars.outputs.MIN_PY_VER }} | |
| version: ${{ steps.set_env_vars.outputs.VERSION }} | |
| release: ${{ steps.set_env_vars.outputs.RELEASE }} | |
| tool_dir: ${{ steps.set_env_vars.outputs.TOOL_DIR }} | |
| source_branch: ${{ steps.get_source_branch.outputs.SOURCE_BRANCH }} | |
| strategy: | |
| matrix: | |
| python-version: ['3.9', '3.10' , '3.11'] | |
| steps: | |
| - name: Set Environment Variables | |
| id: set_env_vars | |
| run: | | |
| echo "PYTHON_VERSION=${{ matrix.python-version }}" >> $GITHUB_OUTPUT | |
| if [[ ${{strategy.job-index}} == 0 ]]; then | |
| echo "MIN_PY_VER=${{ matrix.python-version }}" >> $GITHUB_OUTPUT | |
| fi | |
| echo "VERSION=0.0.0.dev0" >> $GITHUB_OUTPUT | |
| echo "RELEASE=false" >> $GITHUB_OUTPUT | |
| echo "TOOL_DIR=${{env.TOOL_NAME}}" >> $GITHUB_OUTPUT | |
| if [[ "$GITHUB_REF" == *"refs/tags/v"* || "$GITHUB_REF" == *"refs/tags/test-v"* ]]; then | |
| echo "VERSION=$(echo ${{github.ref}} | sed -r 's/^[\/a-zA-z-]+//')" >> $GITHUB_OUTPUT | |
| if [[ $VERSION != *@(a|b)* ]]; then | |
| echo "RELEASE=true" >> $GITHUB_OUTPUT | |
| fi | |
| fi | |
| - uses: actions/checkout@v2 | |
| - name: get source branch | |
| id: get_source_branch | |
| run: | | |
| echo "SOURCE_BRANCH=$(git branch --contains ${{env.COMMIT_ID}} | grep PSD | sed 's/[ *]//g')" >> $GITHUB_OUTPUT | |
| - name: Set package version | |
| run: | | |
| sed -E -i "s/^__version__ = \"[a-z0-9\.]+\"/__version__ = \"${{steps.set_env_vars.outputs.VERSION}}\"/g" ${{ steps.set_env_vars.outputs.TOOL_DIR }}/_version.py | |
| - name: Set up Python ${{ matrix.python-version }} | |
| uses: actions/setup-python@v2 | |
| with: | |
| python-version: ${{ matrix.python-version }} | |
| - name: Install dependencies | |
| run: | | |
| python -m pip install --upgrade pip | |
| pip install flake8 wheel | |
| pip install -r requirements.txt | |
| - name: Lint with flake8 | |
| run: | | |
| # stop the build if there are Python syntax errors or undefined names | |
| flake8 . --count --select=E9,F63,F7,F82 --show-source --statistics --ignore=E501,F841 | |
| # exit-zero treats all errors as warnings. The GitHub editor is 127 chars wide | |
| flake8 . --count --exit-zero --max-complexity=10 --max-line-length=127 --statistics | |
| - name: Create Wheel Package | |
| run: python setup.py bdist_wheel | |
| - name: Install Wheel package | |
| run: pip install dist/${{ steps.set_env_vars.outputs.TOOL_DIR }}-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl | |
| - name: copy whl | |
| run: | | |
| mkdir dist/${{ steps.set_env_vars.outputs.PYTHON_VERSION }} | |
| cp dist/${{ steps.set_env_vars.outputs.TOOL_DIR }}-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl dist/${{ steps.set_env_vars.outputs.PYTHON_VERSION }}/ | |
| - name: cache whl | |
| uses: actions/cache@v3 | |
| with: | |
| path: dist/${{ steps.set_env_vars.outputs.PYTHON_VERSION }}/${{ steps.set_env_vars.outputs.TOOL_DIR }}-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl | |
| key: ${{ steps.set_env_vars.outputs.PYTHON_VERSION }}_${{ steps.set_env_vars.outputs.TOOL_DIR }}_${{ github.run_id }} | |
| - name: Create Wheel Package - WS | |
| run: python setup-ws.py bdist_wheel | |
| - name: Install Wheel package - WS | |
| run: pip install dist/ws_cleanup_tool-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl | |
| - name: copy whl - WS | |
| run: | | |
| cp dist/ws_cleanup_tool-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl dist/${{ steps.set_env_vars.outputs.PYTHON_VERSION }}/ | |
| - name: cache whl - WS | |
| uses: actions/cache@v3 | |
| with: | |
| path: dist/${{ steps.set_env_vars.outputs.PYTHON_VERSION }}/ws_cleanup_tool-${{ steps.set_env_vars.outputs.VERSION }}-py3-none-any.whl | |
| key: ${{ steps.set_env_vars.outputs.PYTHON_VERSION }}_ws_cleanup_tool_${{ github.run_id }} | |
| publish: | |
| if: ${{ startsWith(github.ref, 'refs/tags/v') }} | |
| needs: [build-and-test] | |
| runs-on: ubuntu-latest | |
| steps: | |
| - name: Restore whl | |
| uses: actions/cache@v3 | |
| with: | |
| path: dist/${{needs.build-and-test.outputs.min_py_ver}}/${{needs.build-and-test.outputs.tool_dir}}-${{needs.build-and-test.outputs.version}}-py3-none-any.whl | |
| key: ${{needs.build-and-test.outputs.min_py_ver}}_${{needs.build-and-test.outputs.tool_dir}}_${{ github.run_id }} | |
| - name: Restore whl - ws | |
| uses: actions/cache@v3 | |
| with: | |
| path: dist/${{needs.build-and-test.outputs.min_py_ver}}/ws_cleanup_tool-${{needs.build-and-test.outputs.version}}-py3-none-any.whl | |
| key: ${{needs.build-and-test.outputs.min_py_ver}}_ws_cleanup_tool_${{ github.run_id }} | |
| - name: Publish to PyPI | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: pypa/gh-action-pypi-publish@release/v1 | |
| with: | |
| skip_existing: true | |
| user: __token__ | |
| password: ${{ secrets.PYPI_API_TOKEN }} | |
| packages_dir: dist/${{needs.build-and-test.outputs.min_py_ver}} | |
| - uses: actions/checkout@v2 | |
| - name: Create Release | |
| if: startsWith(github.ref, 'refs/tags/v') | |
| uses: ncipollo/release-action@v1 | |
| with: | |
| token: ${{ secrets.GITHUB_TOKEN }} | |
| allowUpdates: true | |
| artifacts: dist/${{needs.build-and-test.outputs.min_py_ver}}/${{needs.build-and-test.outputs.tool_dir}}-${{needs.build-and-test.outputs.version}}-py3-none-any.whl | |
| prerelease: ${{ needs.build-and-test.outputs.release != 'true' }} | |
| generateReleaseNotes: true |