From 87fd42a7ab5257ac58dd7c600cf022cab7e9f050 Mon Sep 17 00:00:00 2001 From: Yurii Puchkov Date: Wed, 27 Dec 2023 14:24:37 -0700 Subject: [PATCH] feat(CICD): Add pip build and push to the build steps --- .github/workflows/build.yaml | 52 +++++++++++++++++++++++++++++------- pyproject.toml | 2 +- 2 files changed, 44 insertions(+), 10 deletions(-) diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml index 0a0108a..824d768 100644 --- a/.github/workflows/build.yaml +++ b/.github/workflows/build.yaml @@ -1,4 +1,4 @@ -name: Docker Build & Push +name: Build & Push permissions: write-all on: @@ -41,12 +41,15 @@ jobs: pip install -U tox pip install tox tox + build: runs-on: ubuntu-latest needs: unittests - if: github.ref == 'refs/heads/main' + # if: github.ref == 'refs/heads/main' steps: - uses: actions/checkout@v3 + with: + fetch-depth: 0 - name: Docker Build shell: bash @@ -55,19 +58,50 @@ jobs: docker build -t "${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}" . - name: Log in to Docker Hub - if: github.ref == 'refs/heads/main' uses: docker/login-action@v3 with: - username: ${{ env.DOCKER_USERNAME }} + username: ${{ secrets.DOCKER_USERNAME }} password: ${{ secrets.DOCKER_PASSWORD }} + - name: Detect package version + shell: bash + run: | + set -x + PACKAGE_VERSION="$(git tag --contains)" + if [[ "${PACKAGE_VERSION}" == "" ]]; then + PACKAGE_VERSION="$(docker run --rm -v $(pwd):/app -w /app --user "$(id -u):$(id -g)" panpuchkov/pygitver --next-ver)-dev" + PACKAGE_VERSION=$(echo "${PACKAGE_VERSION}" | sed 's/^v*//' ) + DOCKER_TAG_LATEST="${PACKAGE_VERSION}" + else + DOCKER_TAG_LATEST="latest" + fi + + echo "PACKAGE_VERSION=$PACKAGE_VERSION" >> $GITHUB_ENV + echo "DOCKER_TAG_LATEST=$DOCKER_TAG_LATEST" >> $GITHUB_ENV + - name: Docker Push shell: bash run: | set -x - DOCKER_TAG="$(git tag --contains)" - if [[ "${DOCKER_TAG}" == "" ]]; then - DOCKER_TAG="latest" + # Generate docker tags + IMAGE_NAME_WITH_TAG_VERSION="${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${PACKAGE_VERSION}" + IMAGE_NAME_WITH_TAG_LATEST="${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${DOCKER_TAG_LATEST}" + + # Set docker tag + docker tag "${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:latest" "${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${PACKAGE_VERSION}" + docker push "${IMAGE_NAME_WITH_TAG_VERSION}" + + # Push latest if required + if [[ "${IMAGE_NAME_WITH_TAG_LATEST}" != "${IMAGE_NAME_WITH_TAG_LATEST}" ]]; then + docker push "${IMAGE_NAME_WITH_TAG_LATEST}" fi - IMAGE_NAME_WITH_VERSION="${{ env.DOCKER_USERNAME }}/${{ env.IMAGE_NAME }}:${DOCKER_TAG}" - docker push "${IMAGE_NAME_WITH_VERSION}" + + - name: Pip Build & Push + shell: bash + run: | + set -x + pip install -r requirements-build.txt + python -m build + sudo apt-get -y install twine + twine check dist/* + twine upload --skip-existing -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} dist/* --verbose diff --git a/pyproject.toml b/pyproject.toml index bec520b..169146e 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [project] name = "pygitver" -version = "0.0.2" +version = "0.1.0-dev" authors = [ { name="Yurii Puchkov", email="panpuchkov@gmail.com" }, ]