Skip to content

Commit

Permalink
feat(CICD): Add pip build and push to the build steps
Browse files Browse the repository at this point in the history
  • Loading branch information
panpuchkov committed Dec 27, 2023
1 parent d6c6f8a commit ab4c90c
Showing 1 changed file with 42 additions and 9 deletions.
51 changes: 42 additions & 9 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Docker Build & Push
name: Build & Push
permissions: write-all

on:
Expand All @@ -16,7 +16,6 @@ on:

env:
IMAGE_NAME: 'pygitver'
DOCKER_USERNAME: ${{ secrets.DOCKER_USERNAME }}

jobs:
unittests:
Expand All @@ -41,12 +40,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
Expand All @@ -58,16 +60,47 @@ jobs:
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"
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
apt install -y twine
twine check dist/*
# twine upload --skip-existing -u ${{ secrets.PYPI_USERNAME }} -p ${{ secrets.PYPI_PASSWORD }} dist/* --verbose

0 comments on commit ab4c90c

Please sign in to comment.