Skip to content

Commit

Permalink
Update GitHub action (#5)
Browse files Browse the repository at this point in the history
* fix: next version handling on mutli branch building

Signed-off-by: Martin Buchleitner <[email protected]>

---------

Signed-off-by: Martin Buchleitner <[email protected]>
Co-authored-by: Edmund Haselwanter <[email protected]>
  • Loading branch information
mabunixda and ehaselwanter authored Mar 20, 2023
1 parent 4ae48c0 commit 0179f17
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 8 deletions.
22 changes: 16 additions & 6 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -97,15 +107,15 @@ 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
username: ${{ secrets.QUAY_USER }}
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
Expand All @@ -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'

Expand Down
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

## 1.0.1 (2023-03-20)

#### Bug Fixes
Expand Down
9 changes: 7 additions & 2 deletions src/app.py
Original file line number Diff line number Diff line change
@@ -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 = "<h3>Hello {name}!</h3>" \
"<b>Hostname:</b> {hostname}<br/>"
return html.format(name=os.getenv("NAME", "world"), hostname=socket.gethostname())
"<b>Hostname:</b> {hostname}<br/>" \
"<b>Current Date:</b> {currentdate}<br/>"
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)

0 comments on commit 0179f17

Please sign in to comment.