From 9485075ea46cb108cdcef470d383336b81fdbc7d Mon Sep 17 00:00:00 2001 From: crackitty Date: Wed, 30 Oct 2024 10:01:40 +0100 Subject: [PATCH] Allowing the developer to set the version in the codebase --- .github/workflows/build-books-universium.yml | 10 ++++++++-- .github/workflows/build-demo-comics.yml | 10 ++++++++-- books-universium/__version__.py | 1 + demo-comics/__version__.py | 1 + 4 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 books-universium/__version__.py create mode 100644 demo-comics/__version__.py diff --git a/.github/workflows/build-books-universium.yml b/.github/workflows/build-books-universium.yml index 45ba13f..1bed9ee 100644 --- a/.github/workflows/build-books-universium.yml +++ b/.github/workflows/build-books-universium.yml @@ -13,7 +13,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: middlewaregruppen/books-universium - IMAGE_VERSION: 0.1.1 + APP_PATH: books-universium jobs: build-and-push-image: @@ -34,6 +34,12 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version from __version__.py + id: get_version + run: | + VERSION=$(python -c 'import sys; sys.path.insert(0, "${{ env.APP_PATH }}"); from my_package import __version__; print(__version__)') + echo "IMAGE_VERSION=$VERSION" >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 @@ -47,7 +53,7 @@ jobs: id: push uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: - context: books-universium + context: ${{ env.APP_PATH }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/.github/workflows/build-demo-comics.yml b/.github/workflows/build-demo-comics.yml index 51c3029..dac08a5 100644 --- a/.github/workflows/build-demo-comics.yml +++ b/.github/workflows/build-demo-comics.yml @@ -13,7 +13,7 @@ on: env: REGISTRY: ghcr.io IMAGE_NAME: middlewaregruppen/demo-comics - IMAGE_VERSION: 0.21 + APP_PATH: demo-comics jobs: build-and-push-image: @@ -34,6 +34,12 @@ jobs: username: ${{ github.actor }} password: ${{ secrets.GITHUB_TOKEN }} + - name: Get version from __version__.py + id: get_version + run: | + VERSION=$(python -c 'import sys; sys.path.insert(0, "${{ env.APP_PATH }}"); from my_package import __version__; print(__version__)') + echo "IMAGE_VERSION=$VERSION" >> $GITHUB_ENV + - name: Extract metadata (tags, labels) for Docker id: meta uses: docker/metadata-action@9ec57ed1fcdbf14dcef7dfbe97b2010124a938b7 @@ -47,7 +53,7 @@ jobs: id: push uses: docker/build-push-action@f2a1d5e99d037542a71f64918e516c093c6f3fc4 with: - context: demo-comics + context: ${{ env.APP_PATH }} push: true tags: ${{ steps.meta.outputs.tags }} labels: ${{ steps.meta.outputs.labels }} diff --git a/books-universium/__version__.py b/books-universium/__version__.py new file mode 100644 index 0000000..d1f2e39 --- /dev/null +++ b/books-universium/__version__.py @@ -0,0 +1 @@ +__version__ = "0.1.1" \ No newline at end of file diff --git a/demo-comics/__version__.py b/demo-comics/__version__.py new file mode 100644 index 0000000..caea779 --- /dev/null +++ b/demo-comics/__version__.py @@ -0,0 +1 @@ +__version__ = "0.21" \ No newline at end of file