From 0179f1793e34b4fe89b17b5ee5a036a31b0cc97c Mon Sep 17 00:00:00 2001 From: Martin Buchleitner Date: Mon, 20 Mar 2023 13:48:22 +0100 Subject: [PATCH] Update GitHub action (#5) * fix: next version handling on mutli branch building Signed-off-by: Martin Buchleitner --------- Signed-off-by: Martin Buchleitner Co-authored-by: Edmund Haselwanter --- .github/workflows/ci.yml | 22 ++++++++++++++++------ CHANGELOG.md | 1 + src/app.py | 9 +++++++-- 3 files changed, 24 insertions(+), 8 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 954db8b..372eb33 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -46,15 +46,24 @@ jobs: id: prep run: | + CURRENT_VERSION="${{ needs.prebuild.outputs.version }}" IMAGE_PREFIX="v1" IMAGE_NAME=$(basename ${{ github.repository }}) IMAGE_REPO=${{ github.repository_owner }} + git fetch --tags + LATEST_TAG=$(git describe --tags `git rev-list --tags --max-count=1` | sed 's/v//') if [ "$GITHUB_REF_NAME" == "v2" ] || [ "$GITHUB_BASE_REF" == "v2" ]; then IMAGE_PREFIX="v2" + if [ "$GITHUB_REF_NAME" == "v2" ]; then + CURRENT_VERSION=$LATEST_TAG + fi fi if [ "$GITHUB_REF_NAME" == "v3" ] || [ "$GITHUB_BASE_REF" == "v3" ]; then IMAGE_PREFIX="v3" + if [ "$GITHUB_REF_NAME" == "v3" ]; then + CURRENT_VERSION=$LATEST_TAG + fi fi if [[ -n "${{ secrets.IMAGE_NAME }}" ]]; then @@ -66,18 +75,19 @@ jobs: QUAY_IMAGE="quay.io/$IMAGE_REPO/$IMAGE_NAME" GHCR_IMAGE="ghcr.io/${{ github.repository }}" VERSION="${IMAGE_PREFIX}-dev" - if [[ '${{ needs.prebuild.outputs.version }}' != '' ]]; then - VERSION="${IMAGE_PREFIX}-${{ needs.prebuild.outputs.version }}" + if [[ '${CURRENT_VERSION}' != '' ]]; then + VERSION="${IMAGE_PREFIX}-${CURRENT_VERSION}" fi if [ "${{ github.event_name }}" = "schedule" ]; then VERSION="${IMAGE_PREFIX}-nightly" fi TAGS="${QUAY_IMAGE}:${VERSION},${GHCR_IMAGE}:${VERSION}" - if [[ "${{ needs.prebuild.outputs.version }}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then + if [[ "${CURRENT_VERSION}" =~ ^[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}$ ]]; then TAGS="$TAGS,${QUAY_IMAGE}:${IMAGE_PREFIX},${GHCR_IMAGE}:${IMAGE_PREFIX}" fi echo "settings tag ${TAGS}" echo "tags=${TAGS}" >> $GITHUB_OUTPUT + echo "next_version=${CURRENT_VERSION}" >> $GITHUB_OUTPUT - name: Set up Docker Buildx id: buildx @@ -97,7 +107,7 @@ jobs: ${{ runner.os }}-buildx- - name: Login to Quay - if: needs.prebuild.outputs.version != '' + if: steps.prep.outputs.next_version != '' uses: docker/login-action@v1 with: registry: quay.io @@ -105,7 +115,7 @@ jobs: password: ${{ secrets.QUAY_TOKEN }} - name: Login to GitHub Container Registry - if: needs.prebuild.outputs.version != '' + if: steps.prep.outputs.next_version != '' uses: docker/login-action@v1 with: registry: ghcr.io @@ -119,7 +129,7 @@ jobs: builder: ${{ steps.buildx.outputs.name }} context: . file: ./Dockerfile - push: ${{ github.event_name != 'pull_request' && needs.prebuild.outputs.version != '' }} + push: ${{ github.event_name != 'pull_request' && steps.prep.outputs.next_version != '' }} tags: ${{ steps.prep.outputs.tags }} platforms: 'arm64,amd64' diff --git a/CHANGELOG.md b/CHANGELOG.md index 0474832..6243b2f 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,4 @@ + ## 1.0.1 (2023-03-20) #### Bug Fixes diff --git a/src/app.py b/src/app.py index 6ede23b..a59e921 100644 --- a/src/app.py +++ b/src/app.py @@ -1,15 +1,20 @@ from flask import Flask import os import socket +import datetime app = Flask(__name__) @app.route("/") def hello(): + now = datetime.datetime.now() html = "

Hello {name}!

" \ - "Hostname: {hostname}
" - return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname()) + "Hostname: {hostname}
" \ + "Current Date: {currentdate}
" + return html.format(name=os.getenv("NAME", "world"), + hostname=socket.gethostname(), + currentdate=str(now)) if __name__ == "__main__": app.run(host='0.0.0.0', port=80)