-
Notifications
You must be signed in to change notification settings - Fork 2
151 lines (134 loc) · 6.73 KB
/
Test and Deploy Mend.yml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
name: CI
on:
push:
branches:
- '**'
- 'feature/**'
- '!ws-iac-scan-results/**'
- '!whitesource-remediate/master-all**'
- '!whitesource/migrate-configuration**'
tags:
- '*'
env:
TOOL_NAME: mend_sca_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: Full test Time-Based
run: $TOOL_NAME -r 50000 -m FilterProjectsByUpdateTime -u ${{ secrets.WS_USER_KEY }} -k ${{ secrets.WS_ORG_TOKEN }} -y true -o /tmp
- name: Full test Copy-Based
run: $TOOL_NAME -r 50000 -m FilterProjectsByLastCreatedCopies -u ${{ secrets.WS_USER_KEY }} -k ${{ secrets.WS_ORG_TOKEN }} -y true -o /tmp
- 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 }}
- name: Full test Time-Based - WS
run: ws_cleanup_tool -r 50000 -m FilterProjectsByUpdateTime -u ${{ secrets.WS_USER_KEY }} -k ${{ secrets.WS_ORG_TOKEN }} -y true -o /tmp
- name: Full test Copy-Based - WS
run: ws_cleanup_tool -r 50000 -m FilterProjectsByLastCreatedCopies -u ${{ secrets.WS_USER_KEY }} -k ${{ secrets.WS_ORG_TOKEN }} -y true -o /tmp
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