Skip to content

Merge pull request #236 from bcgov/hotfix/10699-fix-length-mismatch #19

Merge pull request #236 from bcgov/hotfix/10699-fix-length-mismatch

Merge pull request #236 from bcgov/hotfix/10699-fix-length-mismatch #19

name: Test - Build & Push docker images
on:
push:
branches: [ "main" ]
paths-ignore:
- '.github/**'
- '.gitignore'
- 'database/**'
- 'documentation/**'
- 'openshift/**'
- 'COMPLIANCE.yaml'
- 'CONTRIBUTING.md'
- 'LICENSE'
- 'README.md'
- 'SECURITY..md'
# Repository variables VERSION_MAJOR_MINOR 0.1 VERSION_MESSAGE Dev to Test - VERSION_PREFIX v
env:
OPENSHIFT_CLUSTER: https://api.silver.devops.gov.bc.ca:6443
OPENSHIFT_AUTH_TOKEN: ${{secrets.OPENSHIFT_TOKEN_TEST}}
RELEASE_PREFIX: ${{vars.VERSION_PREFIX}}
RELEASE_VERSION: ${{vars.VERSION_MAJOR_MINOR}}
RELEASE_MESSAGE: ${{vars.VERSION_MESSAGE}}
jobs:
# This workflow contains a jobs called "GenerateTag" "PushTag" "Build" "PushAlert"
GenerateTag:
runs-on: ubuntu-latest
outputs:
TAGNAME: ${{steps.nexttag.outputs.gittag}}
IMAGETAG: ${{steps.nexttag.outputs.imagetag}}
TAGMESSAGE: ${{steps.nexttag.outputs.tagmsg}}
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Get current date
id: date
run: echo "date=$(date +'%B %e, %Y')" >> $GITHUB_OUTPUT
- name: Generate Next Git Tag
id: nexttag
run: |
VERSION_PATCH=$(git tag --list "${{env.RELEASE_PREFIX}}${{env.RELEASE_VERSION}}.*" --sort=-version:refname | head -n 1 | grep -oE '[0-9]+$')
if [ -z "$VERSION_PATCH" ]; then
VERSION_PATCH=0
else
VERSION_PATCH=$((VERSION_PATCH + 1))
fi
echo "gittag=${{env.RELEASE_PREFIX}}${{env.RELEASE_VERSION}}.${VERSION_PATCH}" >> $GITHUB_OUTPUT
echo "imagetag=v${{env.RELEASE_VERSION}}.${VERSION_PATCH}" >> $GITHUB_OUTPUT
echo "tagmsg=${{env.RELEASE_MESSAGE}} ${{steps.date.outputs.date}}" >> $GITHUB_OUTPUT
PushTag:
needs: [GenerateTag]
runs-on: ubuntu-latest
steps:
- name: Checkout repository
uses: actions/checkout@v4
with:
fetch-depth: '0'
- name: Push Git Tag
env:
TAGNAME: ${{needs.GenerateTag.outputs.TAGNAME}}
TAGMESSAGE: ${{needs.GenerateTag.outputs.TAGMESSAGE}}
run: |
git config user.name "GitHub Actions"
git config user.email "[email protected]"
git tag ${{env.TAGNAME}} -m "${{env.TAGMESSAGE}}"
git push origin ${{env.TAGNAME}}
Build:
needs: [GenerateTag, PushTag]
runs-on: ubuntu-latest
outputs:
PROJECT: ${{steps.project.outputs.TARGET_PROJECT}}
steps:
- uses: actions/checkout@v3
- name: Build application Docker images
run: |
rm -f ./docker-compose.override.yml
docker compose build
working-directory: ./applications/Unity.GrantManager
- name: Connect to OpenShift API
id: project
run: |
oc login --token=${{env.OPENSHIFT_AUTH_TOKEN}} --server=${{env.OPENSHIFT_CLUSTER}}
echo "PROJECT=$(oc project | grep -oE '[0-9a-z]*-[dev\|test\|prod\|tools]*')" >> $GITHUB_OUTPUT
oc registry login
- name: Push build images to OpenShift container registry
run: |
echo project = ${{steps.project.outputs.PROJECT}}
docker tag unity-grantmanager-web image-registry.apps.silver.devops.gov.bc.ca/${{steps.project.outputs.PROJECT}}/unity-grantmanager-web:${{needs.GenerateTag.outputs.IMAGETAG}}
docker tag unity-grantmanager-dbmigrator image-registry.apps.silver.devops.gov.bc.ca/${{steps.project.outputs.PROJECT}}/unity-grantmanager-dbmigrator:${{needs.GenerateTag.outputs.IMAGETAG}}