Skip to content

updated semver calculation method #3

updated semver calculation method

updated semver calculation method #3

Workflow file for this run

name: Push to Main
on:
push:
branches:
- feature/cicd
jobs:
built-test-publish:
runs-on: ubuntu-latest
strategy:
matrix:
python_image: ["python:3.10-slim", "python:3.11-slim"]
steps:
- name: Checkout
uses: actions/checkout@v3
- name: Cache Poetry Dependencies
uses: actions/cache@v2
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Read .version file
id: semver
run: |
echo "::set-output name=version::$(cat .version)"
- name: Get latest release
id: latest_release
run: |
LATEST_RELEASE=\
$(curl -sH "Authorization: token ${{ secrets.GITHUB_TOKEN }}" \
"https://api.github.com/repos/${{ github.repository }}/releases/latest" \
| jq -r '.tag_name')
echo "::set-output name=release::${LATEST_RELEASE}"
echo "Latest Release: ${LATEST_RELEASE}"
- name: Calculate next version
id: calculate_version
run: |
LATEST_RELEASE=${{ steps.latest_release.outputs.release }}
BASE_VERSION=${{ steps.semver.outputs.version }}
CLEANED_LATEST_RELEASE=${LATEST_RELEASE#v}
echo "Latest Release without v: ${CLEANED_LATEST_RELEASE}"
echo "Base Version: ${BASE_VERSION}"
# Compare versions
if [[ "${BASE_VERSION}" > "${CLEANED_LATEST_RELEASE}" ]]; then
NEXT_VERSION=${BASE_VERSION}
else
# Split version into parts
MAJOR=$(echo ${CLEANED_LATEST_RELEASE} | cut -d. -f1)
MINOR=$(echo ${CLEANED_LATEST_RELEASE} | cut -d. -f2)
PATCH=$(echo ${CLEANED_LATEST_RELEASE} | cut -d. -f3)
# Bump version
PATCH=$((PATCH + 1))
NEXT_VERSION="${MAJOR}.${MINOR}.${PATCH}"
fi
echo "Next Version: ${NEXT_VERSION}"
echo "::set-output name=version::${NEXT_VERSION}"
- name: Build and Test
run: |
echo "Version: ${{ steps.semver.outputs.version }}"
docker build \
--build-arg PYTHON_IMAGE=${{ matrix.python_image }} \
--build-arg BUILD_VERSION=${{ steps.calculate_version.outputs.version }} \
--tag my-image:${{ steps.semver.outputs.version }} \
.
docker run --name test-container my-image:${{ steps.semver.outputs.version }}
docker cp test-container:/app/reports .
mkdir -p temp-dist
docker cp test-container:/app/dist temp-dist/
- name: Publish to PyPi
if: false
run: |
pip install twine
for i in {1..5}; do \
twine upload -u __token__ -p ${{ secrets.PYPI_TOKEN }} temp-dist/* \
&& break \
|| sleep 15; \
done
- name: Cleanup
run: |
docker rmi my-image:${{ steps.semver.outputs.version }} --force
rm -rf temp-dist