CI #1017
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 | |
on: | |
push: | |
branches: | |
- '**' | |
- '!ws-iac-scan-results/**' | |
- '!whitesource-remediate/master-all**' | |
- '!whitesource/migrate-configuration**' | |
tags: | |
- '*' | |
schedule: | |
- cron: '0 4 * * *' | |
jobs: | |
build-and-publish: | |
runs-on: ubuntu-latest | |
env: | |
TOOL_NAME: ws_nexus_integration | |
strategy: | |
matrix: | |
python-version: ['3.8', '3.9', '3.10'] | |
steps: | |
- name: Set Environment Variables | |
run: | | |
echo "VERSION=0.0.0.ci0" >> $GITHUB_ENV | |
echo "RELEASE=false" >> $GITHUB_ENV | |
echo "TOOL_DIR=$TOOL_NAME" >> $GITHUB_ENV | |
if [[ $GITHUB_REF == refs/tags/v* ]]; then | |
echo "VERSION=$(echo ${{github.ref}} | sed -r 's/^[\/a-zA-z-]+//')" >> $GITHUB_ENV | |
if [[ $VERSION != *@(a|b)* ]]; then | |
echo "RELEASE=true" >> $GITHUB_ENV | |
fi | |
fi | |
- uses: actions/checkout@v2 | |
- name: Set package version | |
run: | | |
sed -E -i "s/^__version__ = \"[a-z0-9\.]+\"/__version__ = \"$VERSION\"/g" ${{ env.TOOL_DIR }}/_version.py | |
# - uses: UnicornGlobal/trufflehog-actions-scan@master | |
# with: | |
# branch: ${{ github.head_ref }} | |
- name: Set up Python ${{ matrix.python-version }} | |
uses: actions/setup-python@v2 | |
with: | |
python-version: ${{ matrix.python-version }} | |
- name: Change to last ws-sdk version on odd days (Mon, Wed, Fri, Sun) | |
run: | | |
sdk_c_ver=$(grep "ws-sdk" requirements.txt | awk -F '=' '{print $NF}') | |
sdk_t_ver=$(curl -sL https://pypi.org/pypi/ws-sdk/json | jq -r '.releases| keys[]' | sort -t. -k 1,1n -k 2,2n -k 3,3n -k 4,4n | tail -n1) | |
if (( $(date +"%u") % 2 )) ; then | |
echo "Odd day - Replacing current ws-sdk version: ${sdk_c_ver} with latest release: ${sdk_t_ver}" | |
sed -E -i "s/^ws-sdk.+/ws-sdk==${sdk_t_ver}/g" requirements.txt | |
fi | |
- name: Install dependencies | |
run: | | |
python -m pip install --upgrade pip | |
pip install flake8 wheel docker pytest pytest-mock | |
pip install -r requirements.txt --no-cache-dir | |
- 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: Run tests with pytest #Todo fix tests | |
# run: pytest | |
- name: Create Wheel Package | |
run: python setup.py bdist_wheel | |
- name: Install Wheel package | |
run: pip install dist/${{ env.TOOL_DIR }}-${{ env.VERSION }}-py3-none-any.whl | |
- name: Publish to Test PyPI | |
if: startsWith(github.ref, 'refs/tags/test-v') | |
uses: pypa/gh-action-pypi-publish@release/v1 | |
with: | |
skip_existing: true | |
user: __token__ | |
password: ${{ secrets.TEST_PYPI_API_TOKEN }} | |
repository_url: https://test.pypi.org/legacy/ | |
- 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 }} | |
- name: Create Release | |
if: startsWith(github.ref, 'refs/tags/v') | |
uses: ncipollo/release-action@v1 | |
with: | |
token: ${{ secrets.GITHUB_TOKEN }} | |
allowUpdates: true | |
artifacts: dist/${{ env.TOOL_DIR }}-${{ env.VERSION }}-py3-none-any.whl | |
prerelease: ${{ env.RELEASE != 'true' }} | |
generateReleaseNotes: true | |
- name: Publish to Confluence - Public | |
if: ${{ env.RELEASE == 'true' }} | |
uses: cupcakearmy/confluence-markdown-sync@v1 | |
with: | |
from: README.md | |
to: 2313290408 | |
cloud: whitesource | |
user: ${{ secrets.CONFLUENCE_USER }} | |
token: ${{ secrets.CONFLUENCE_TOKEN }} | |
- name: Publish to Confluence - Internal | |
if: ${{ env.RELEASE == 'true' }} | |
uses: cupcakearmy/confluence-markdown-sync@v1 | |
with: | |
from: README.md | |
to: 1782579576 | |
cloud: whitesource | |
user: ${{ secrets.CONFLUENCE_USER }} | |
token: ${{ secrets.CONFLUENCE_TOKEN }} |