PIMS-1622: Handle task array #85
Workflow file for this run
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# GitHub Actions workflow for deploying API image on PR merge to main branch | |
name: EXPRESS API-DEV Deploy | |
on: | |
pull_request: | |
types: | |
- closed | |
branches: [main] | |
paths: | |
- 'express-api/**' # Triggers on changes to files in the express-api/ directory. | |
workflow_dispatch: | |
inputs: | |
image_tag: | |
description: 'Image Tag to deploy' | |
required: true | |
env: | |
IMAGE_TAG: ${{ github.event_name == 'workflow_dispatch' && github.event.inputs.image_tag || github.event.pull_request.number }} | |
jobs: | |
# Job to deploy API image to OpenShift | |
Deploy-To-OpenShift: | |
if: ${{ github.event_name == 'workflow_dispatch' || github.event.pull_request.merged }} | |
name: Deploy to OpenShift | |
runs-on: ubuntu-latest | |
steps: | |
# Checkout the repository | |
- name: Checkout Repository | |
uses: actions/checkout@v3 | |
with: | |
fetch-depth: 0 | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }} | |
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
# Process and Apply API DeploymentConfig | |
- name: Process and Apply API DeploymentConfig | |
env: | |
NAMESPACE: '${{ secrets.OPENSHIFT_DEV_NAMESPACE }}' | |
DC_TEMPLATE: 'api-v2-dc-template.yaml' | |
IMAGE_TAG: ${{ env.IMAGE_TAG }} | |
ENVIRONMENT: 'dev' | |
APPLICATION_NAME: 'pims-api-v2' | |
LICENSE_PLATE: '${{ secrets.LICENSE_PLATE }}' | |
run: | | |
./.github/helpers/deploy.sh | |
# Job to check the health of the deployed API | |
Health-Check: | |
name: Check Deployment Health | |
runs-on: ubuntu-latest | |
needs: [Deploy-To-OpenShift] | |
steps: | |
# Login to OpenShift | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
env: | |
OPENSHIFT_USER: github-actions | |
OPENSHIFT_PROJECT: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }} | |
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
# Check Deployment Status | |
- name: Check Deployment Status | |
run: | | |
oc rollout status -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} dc/pims-api-v2 --watch | |
# Job to clean up previous objects in OpenShift | |
Clean-Up: | |
name: Clean Up | |
runs-on: ubuntu-latest | |
needs: [Health-Check] | |
steps: | |
# Login to OpenShift | |
- name: Login to OpenShift | |
uses: redhat-actions/oc-login@v1 | |
env: | |
OPENSHIFT_USER: github-actions | |
OPENSHIFT_PROJECT: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
with: | |
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER_URL }} | |
openshift_token: ${{ secrets.OPENSHIFT_SA_DEV_TOKEN }} | |
namespace: ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} | |
# Remove previous objects | |
- name: Remove previous objects | |
run: | | |
oc delete pod -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} --field-selector status.phase=Succeeded | |
# Remove previous replication controllers | |
- name: Remove previous replication controllers | |
run: | | |
oc delete rc -n ${{ secrets.OPENSHIFT_DEV_NAMESPACE }} --field-selector status.replicas=0 | |
# Job to update the wiki with deployed image tag information | |
Update_Wiki_Tags: | |
needs: [Health-Check, Deploy-To-OpenShift] | |
name: Update table in wiki | |
runs-on: ubuntu-latest | |
env: | |
GH_TOKEN: ${{ github.token }} | |
steps: | |
# Checkout the repository | |
- name: Checkout | |
uses: actions/checkout@v3 | |
# Clone wiki repository | |
- name: Clone wiki repository | |
run: | | |
echo "Cloning wiki repo https://github.com/$GITHUB_REPOSITORY.wiki.git" | |
git clone "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" ./wiki | |
# Setup Python | |
- name: Setup Python | |
uses: actions/setup-python@v4 | |
with: | |
python-version: '3.10' | |
# Run update wiki python script | |
- name: Run update wiki python script | |
run: python ./.github/helpers/update-wiki-table.py ./wiki/Image-tags.md "API V2" "Deployed Image Tag in DEV" "${{ env.IMAGE_TAG }}" | |
# Commit and push changes to wiki | |
- name: Commit and push changes to wiki | |
run: | | |
cd ./wiki | |
git config user.name "$GITHUB_ACTOR" | |
git config user.email "$GITHUB_ACTOR@users.noreply.github.com" | |
git add . | |
if git diff-index --quiet HEAD; then | |
echo "Nothing changed" | |
exit 0 | |
fi | |
echo "Pushing changes to wiki" | |
git commit -m "Value populated at Deploy API" && git push "https://$GITHUB_ACTOR:$GH_TOKEN@github.com/$GITHUB_REPOSITORY.wiki.git" |