|
| 1 | +name: Release workflow |
| 2 | + |
| 3 | +on: |
| 4 | + push: |
| 5 | + tags: |
| 6 | + - 'v*' # Push events to matching v*, i.e. v1.0, v20.15.10 |
| 7 | + branches: |
| 8 | + - ci-migration |
| 9 | +env: |
| 10 | + repository: https://github.com/powerapi-ng/powerapi |
| 11 | +jobs: |
| 12 | + lint_and_test: |
| 13 | + name: Lint and test |
| 14 | + runs-on: ubuntu-latest |
| 15 | + strategy: |
| 16 | + matrix: |
| 17 | + python-version: [3.9] |
| 18 | + # services: |
| 19 | + # mongo: |
| 20 | + # image: mongo:latest |
| 21 | + # ports: |
| 22 | + # - 27017:27017 |
| 23 | + # influx: |
| 24 | + # image: influxdb:1.8 |
| 25 | + # ports: |
| 26 | + # - 8086:8086 |
| 27 | + steps: |
| 28 | + - name: Install tools |
| 29 | + run: | |
| 30 | + sudo apt update |
| 31 | + sudo apt install -y libvirt-dev procps |
| 32 | + - uses: actions/checkout@v2 |
| 33 | + - name: Set up Python ${{ matrix.python-version }} |
| 34 | + uses: actions/setup-python@v2 |
| 35 | + with: |
| 36 | + python-version: ${{ matrix.python-version }} |
| 37 | + - name: Convert to python3.6 code |
| 38 | + if: ${{ matrix.python-version == 3.6 }} |
| 39 | + run: ./to_36.sh |
| 40 | + - name: Cache pip |
| 41 | + uses: actions/cache@v2 |
| 42 | + with: |
| 43 | + path: ~/.cache/pip |
| 44 | + key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }} |
| 45 | + restore-keys: | |
| 46 | + ${{ runner.os }}-pip- |
| 47 | + ${{ runner.os }}- |
| 48 | + - name: Install dependencies |
| 49 | + run: | |
| 50 | + python3 -m venv venv |
| 51 | + . venv/bin/activate |
| 52 | + python -m pip install --upgrade pip |
| 53 | + pip install flake8 pylint |
| 54 | + pip install -e ".[mongodb, influxdb, prometheus, libvirt]" |
| 55 | + # - name: Test with pytest |
| 56 | + # run: | |
| 57 | + # . venv/bin/activate |
| 58 | + # python setup.py test |
| 59 | + # - name: Lint with flake8 |
| 60 | + # if: ${{ matrix.python-version != 3.6 }} |
| 61 | + # run: | |
| 62 | + # . venv/bin/activate |
| 63 | + # flake8 powerapi |
| 64 | + # - name: Lint with pylint |
| 65 | + # if: ${{ matrix.python-version != 3.6 }} |
| 66 | + # run: | |
| 67 | + # . venv/bin/activate |
| 68 | + # pylint powerapi |
| 69 | + check_release: |
| 70 | + name: Check release and version correspondance |
| 71 | + runs-on: ubuntu-latest |
| 72 | + needs: lint_and_test |
| 73 | + outputs: |
| 74 | + version: ${{ steps.step2.outputs.version }} |
| 75 | + steps: |
| 76 | + - uses: actions/checkout@v2 |
| 77 | + - name: Check tag and package version |
| 78 | + id: step2 |
| 79 | + run: | |
| 80 | + export GIT_TAG=$(echo $GITHUB_REF | sed -e 's/refs\/tags\/v//g') |
| 81 | + test $GIT_TAG == $(grep __version__ powerapi/__init__.py | cut -d \" -f 2) |
| 82 | + echo "::set-output name=version::$GIT_TAG" |
| 83 | + # build_pypi: |
| 84 | + # name: Push package on pypi |
| 85 | + # runs-on: ubuntu-latest |
| 86 | + # env: |
| 87 | + # PYPI_PASS: ${{ secrets.PYPI_PASS }} |
| 88 | + # needs: check_release |
| 89 | + # steps: |
| 90 | + # - uses: actions/checkout@v2 |
| 91 | + # - name: Prepare environement |
| 92 | + # run: pip install -U pip twine |
| 93 | + # - name: Init .pypirc |
| 94 | + # run: | |
| 95 | + # echo -e "[pypi]" >> ~/.pypirc |
| 96 | + # echo -e "username = powerapi" >> ~/.pypirc |
| 97 | + # echo -e "password = $PYPI_PASS" >> ~/.pypirc |
| 98 | + # - name: Generate package |
| 99 | + # run: | |
| 100 | + # python3 -m venv venv |
| 101 | + # . venv/bin/activate |
| 102 | + # python3 setup.py sdist bdist_wheel |
| 103 | + # - name: Upload to pypi |
| 104 | + # run: twine upload dist/* |
| 105 | + # build_and_push_to_dockerHub: |
| 106 | + # name: Build and push docker image to DockerHub |
| 107 | + # runs-on: ubuntu-latest |
| 108 | + # needs: check_release |
| 109 | + # steps: |
| 110 | + # - uses: actions/checkout@v2 |
| 111 | + # - name: Log in to Docker Hub |
| 112 | + # uses: docker/login-action@f054a8b539a109f9f41c372932f1ae047eff08c9 |
| 113 | + # with: |
| 114 | + # username: ${{ secrets.DOCKER_USERNAME }} |
| 115 | + # password: ${{ secrets.DOCKER_PASSWORD }} |
| 116 | + # - name: Build and push Cpython image |
| 117 | + # uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc |
| 118 | + # with: |
| 119 | + # context: . |
| 120 | + # push: true |
| 121 | + # file: Dockerfile-cpython |
| 122 | + # tags: powerapi/powerapi:latest, powerapi/powerapi:${{needs.check_release.outputs.version}} |
| 123 | + # - name: Build and push pypy image |
| 124 | + # uses: docker/build-push-action@ad44023a93711e3deb337508980b4b5e9bcdc5dc |
| 125 | + # with: |
| 126 | + # context: . |
| 127 | + # push: true |
| 128 | + # file: Dockerfile-pypy |
| 129 | + # tags: powerapi/powerapi-pypy:latest, powerapi/powerapi:pypy-${{needs.check_release.outputs.version}} |
| 130 | + build_deb_package: |
| 131 | + name: Build debian binary package |
| 132 | + runs-on: ubuntu-latest |
| 133 | + needs: check_release |
| 134 | + container: |
| 135 | + image: powerapi/powerapi-build-deb |
| 136 | + steps: |
| 137 | + - uses: actions/checkout@v2 |
| 138 | + - name: Set up Python 3.6 |
| 139 | + uses: actions/setup-python@v2 |
| 140 | + with: |
| 141 | + python-version: 3.6 |
| 142 | + - name: Cache pip |
| 143 | + uses: actions/cache@v2 |
| 144 | + with: |
| 145 | + path: ~/.cache/pip |
| 146 | + key: ${{ runner.os }}-pip-${{ hashFiles('setup.cfg') }} |
| 147 | + restore-keys: | |
| 148 | + ${{ runner.os }}-pip- |
| 149 | + ${{ runner.os }}- |
| 150 | + - name: Remove tests |
| 151 | + run: | |
| 152 | + rm -R ./tests |
| 153 | + sed -i 's/setup_requires =//g' setup.cfg |
| 154 | + sed -i 's/pytest-runner >=3.9.2//g' setup.cfg |
| 155 | + sed -i 's/test = pytest//g' setup.cfg |
| 156 | + sed -i 's/\[aliases\]//g' setup.cfg |
| 157 | + sed -i 's/test_suite = tests//g' setup.cfg |
| 158 | + sed -i 's/tests_require =//g' setup.cfg |
| 159 | + sed -i 's/pytest >=3.9.2//g' setup.cfg |
| 160 | + sed -i 's/pytest-asyncio >=0.14.0//g' setup.cfg |
| 161 | + sed -i 's/mock >=2.0//g' setup.cfg |
| 162 | + sed -i 's/requests >=2.0//g' setup.cfg |
| 163 | + - name: Convert to python3.6 code |
| 164 | + run: ./to_36.sh |
| 165 | + - name: Create source package |
| 166 | + run: | |
| 167 | + apt install -y python3-setuptools python3-stdeb python3-numpy |
| 168 | + mkdir package |
| 169 | + mv LICENSE README.md contributing.md powerapi setup.* package/ |
| 170 | + tar czvf powerapi.tar.gz package |
| 171 | + py2dsc powerapi.tar.gz |
| 172 | + sed -i '/Depends: ${misc:Depends}, ${python3:Depends}/a Suggests: python3-libvirt,python3-pymongo,python3-prometheus-client,python3-influxdb' ./deb_dist/powerapi-${{needs.check_release.outputs.version}}/debian/control |
| 173 | + - name: Build binary package and upload it github release page |
| 174 | + env: |
| 175 | + VERSION: ${{needs.check_release.outputs.version}} |
| 176 | + run: | |
| 177 | + cd ./deb_dist/powerapi-$VERSION |
| 178 | + DEB_BUILD_OPTIONS=nocheck dpkg-buildpackage |
| 179 | + mkdir -p ~/deb |
| 180 | + cp ../python3-powerapi_$VERSION-1_all.deb ~/deb/ |
| 181 | + ls ~/deb/ |
| 182 | + - uses: actions/upload-artifact@v2 |
| 183 | + with: |
| 184 | + name: deb_package |
| 185 | + path: ~/deb/ |
| 186 | + |
| 187 | + publish_release: |
| 188 | + name: Publish release on github |
| 189 | + runs-on: ubuntu-latest |
| 190 | + needs: [check_release, build_deb_package] |
| 191 | + steps: |
| 192 | + - uses: actions/checkout@v2 |
| 193 | + - uses: actions/download-artifact@v2 |
| 194 | + with: |
| 195 | + name: deb_package |
| 196 | + path: ~/deb |
| 197 | + - name: Create pre-changelog |
| 198 | + id: pre-changelog |
| 199 | + uses: TriPSs/conventional-changelog-action@v3 |
| 200 | + with: |
| 201 | + github-token: ${{ secrets.github_token }} |
| 202 | + preset: angular |
| 203 | + output-file: ~/pre-changelog.md |
| 204 | + release-count: 2 |
| 205 | + - name: Create Changelog |
| 206 | + env: |
| 207 | + CHANGELOG_CONTENT: ${{ steps.changelog.outputs.clean_changelog }} |
| 208 | + run: | |
| 209 | + sudo apt install -y npm |
| 210 | + sudo npm install -g conventional-changelog-cli |
| 211 | + conventional-changelog -p angular -r 2 | grep -v "^# \[\]" | sed 's/^#//g' > ~/final-changelog.md |
| 212 | + cat ~/final-changelog.md |
| 213 | + cat ~/final-changelog.md >> CHANGELOG.md |
| 214 | + - name: Download thespian debian package |
| 215 | + run: | |
| 216 | + wget https://github.com/powerapi-ng/powerapi-ci-env/raw/main/python3-thespian_3.10.0-1_all.deb |
| 217 | + cp python3-thespian_3.10.0-1_all.deb ~/deb |
| 218 | + - name: Create Release |
| 219 | + env: |
| 220 | + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} |
| 221 | + VERSION: ${{needs.check_release.outputs.version}} |
| 222 | + run: gh release create $VERSION -d -t $VERSION -F ~/final-changelog.md ~/deb/* |
0 commit comments