Skip to content

Merge pull request #52 from vlizBE/dependabot/npm_and_yarn/express-4.… #5

Merge pull request #52 from vlizBE/dependabot/npm_and_yarn/express-4.…

Merge pull request #52 from vlizBE/dependabot/npm_and_yarn/express-4.… #5

name: Docker Image Build & Push to ghrc.io
on:
push:
branches: [ "main" ]
tags: [ "v*.*.*" ]
pull_request:
branches: [ "main" ]
jobs:
build:
runs-on: ubuntu-latest
steps:
- name: Checkout the codebase
uses: actions/checkout@v3
- name: Login to GitHub Container Registry
uses: docker/login-action@v1
with:
registry: ghcr.io
username: ${{ github.actor }}
password: ${{ secrets.GITHUB_TOKEN }}
- name: Extract tag name
id: get_tag
run: echo ::set-output name=TAG_NAME::${GITHUB_REF#refs/tags/}
- name: Use tag name
run: echo ${{ steps.get_tag.outputs.TAG_NAME }}
- name: Build the Docker image
run: |
export REG_NS=ghcr.io/
TAG_NAME=${GITHUB_REF#refs/tags/}
# build tag is the same as tag name for releases if this matches the semver format else it is latest
# The string you want to check
# The regular expression
regex="^(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)\\.(0|[1-9][0-9]*)(-((0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*)(\\.(0|[1-9][0-9]*|[0-9]*[a-zA-Z-][0-9a-zA-Z-]*))*))?(\\+([0-9a-zA-Z-]+(\\.[0-9a-zA-Z-]+)*))?$"
if [[ $TAG_NAME =~ $regex ]]; then
export BUILD_TAG=$TAG_NAME
else
export BUILD_TAG="latest"
fi
echo $BUILD_TAG
REPOSITORY_NAME=$(echo $GITHUB_REPOSITORY | tr '[:upper:]' '[:lower:]')
echo $REG_NS$REPOSITORY_NAME:$BUILD_TAG
docker build -t $REG_NS$REPOSITORY_NAME:$BUILD_TAG .
docker push $REG_NS$REPOSITORY_NAME:$BUILD_TAG