Skip to content

LCFS 0.2.0 Test CI

LCFS 0.2.0 Test CI #40

Workflow file for this run

name: LCFS 0.2.0 Test CI
on:
workflow_dispatch:
env:
VERSION: 0.2.0
GIT_URL: https://github.com/bcgov/lcfs.git
DEV_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-dev
TEST_NAMESPACE: ${{ secrets.OPENSHIFT_NAMESPACE_PLATE }}-test
concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true
jobs:
install-oc:
runs-on: ubuntu-latest
outputs:
cache-hit: ${{ steps.cache.outputs.cache-hit }}
steps:
- name: Set up cache for OpenShift CLI
id: cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc # Path where the `oc` binary will be installed
key: oc-cli-${{ runner.os }}
- name: Install OpenShift CLI (if not cached)
if: steps.cache.outputs.cache-hit != 'true'
run: |
curl -LO https://mirror.openshift.com/pub/openshift-v4/clients/ocp/stable/openshift-client-linux.tar.gz
tar -xvf openshift-client-linux.tar.gz
sudo mv oc /usr/local/bin/
oc version --client
- name: Confirm OpenShift CLI is Available
run: oc version --client
run-tests:
name: Run Tests
runs-on: ubuntu-latest
needs: [install-oc]
steps:
- uses: actions/checkout@v3
with:
repository: bcgov/lcfs
ref: ${{ github.ref }}
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: "3.10.13"
- name: Set up Node.js
uses: actions/setup-node@v3
with:
node-version: "20"
- name: Install Docker Compose
run: |
sudo apt-get update
sudo apt-get install -y docker-compose
- name: Cache Poetry dependencies
uses: actions/cache@v3
with:
path: ~/.cache/pypoetry
key: ${{ runner.os }}-poetry-${{ hashFiles('**/poetry.lock') }}
restore-keys: |
${{ runner.os }}-poetry-
- name: Cache npm dependencies
uses: actions/cache@v3
with:
path: ~/.npm
key: ${{ runner.os }}-node-${{ hashFiles('**/package-lock.json') }}
restore-keys: |
${{ runner.os }}-node-
- name: Install Poetry
run: pip install poetry==1.6.1
- name: Install backend dependencies
run: |
cd backend
poetry config virtualenvs.create false
poetry install
pip install pytest-github-actions-annotate-failures typing_extensions
- name: Install frontend dependencies
run: |
cd frontend
npm ci
- name: Fix docker-compose.yml
run: |
sed -i 's/: true/: "true"/g; s/: false/: "false"/g' docker-compose.yml
- name: Build and start services
run: |
docker-compose build
docker-compose up -d
- name: Run backend tests
id: backend_tests
continue-on-error: true
run: |
cd backend
poetry run pytest --junitxml=pytest-results.xml
env:
LCFS_DB_HOST: localhost
LCFS_DB_PORT: 5432
LCFS_DB_USER: lcfs
LCFS_DB_PASS: development_only
LCFS_DB_BASE: lcfs
LCFS_REDIS_HOST: localhost
LCFS_REDIS_PORT: 6379
LCFS_REDIS_PASSWORD: development_only
APP_ENVIRONMENT: dev
LCFS_CHES_CLIENT_ID: mock_client_id
LCFS_CHES_CLIENT_SECRET: mock_client_secret
LCFS_CHES_AUTH_URL: http://mock_auth_url
LCFS_CHES_SENDER_EMAIL: [email protected]
LCFS_CHES_SENDER_NAME: Mock Notification System
LCFS_CHES_EMAIL_URL: http://mock_email_url
- name: Run frontend tests
id: frontend_tests
continue-on-error: true
run: |
cd frontend
npm run test:run -- --reporter=junit --outputFile=vitest-results.xml
env:
CI: true
# Comment until all cypress tests are fixed for success.
# - name: Create cypress.env.json
# run: |
# echo '{
# "admin_idir_username": "${{ secrets.ADMIN_IDIR_USERNAME }}",
# "admin_idir_password": "${{ secrets.ADMIN_IDIR_PASSWORD }}",
# "org1_bceid_username": "${{ secrets.ORG1_BCEID_USERNAME }}",
# "org1_bceid_password": "${{ secrets.ORG1_BCEID_PASSWORD }}",
# "org1_bceid_id": "${{ secrets.ORG1_BCEID_ID }}",
# "org1_bceid_userId": "${{ secrets.ORG1_BCEID_USERID }}",
# "org2_bceid_username": "${{ secrets.ORG2_BCEID_USERNAME }}",
# "org2_bceid_password": "${{ secrets.ORG2_BCEID_PASSWORD }}",
# "org2_bceid_id": "${{ secrets.ORG2_BCEID_ID }}",
# "org2_bceid_userId": "${{ secrets.ORG2_BCEID_USERID }}"
# }' > frontend/cypress.env.json
# - name: Run Cypress tests
# id: cypress_tests
# continue-on-error: true
# uses: cypress-io/github-action@v6
# with:
# command: npm run cypress:run
# wait-on: 'http://localhost:3000'
# working-directory: frontend
- name: Upload test results
if: always()
uses: actions/upload-artifact@v4
with:
name: test-results
path: |
backend/pytest-results.xml
frontend/vitest-results.xml
# frontend/cypress/reports/
# frontend/cypress/screenshots/
- name: Stop services
if: always()
run: docker-compose down
- name: Check test results
if: always()
run: |
if [ "${{ steps.backend_tests.outcome }}" == "failure" ] || \
[ "${{ steps.frontend_tests.outcome }}" == "failure" ]; then
echo "One or more tests failed"
exit 1
fi
set-pre-release:
name: Find Dev deployment pre-release number
needs: run-tests
runs-on: ubuntu-latest
outputs:
output1: ${{ steps.set-pre-release.outputs.PRE_RELEASE }}
steps:
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.DEV_NAMESPACE }}
- id: set-pre-release
run: |
check_string() {
local string="$1"
if [ ${#string} -ne 14 ]; then
echo "String length must be 14 characters"
return 1
fi
if ! [[ $string =~ ^[0-9]+$ ]]; then
echo "String can only contain numbers"
return 1
fi
local year="${string:0:4}"
local month="${string:4:2}"
local day="${string:6:2}"
local hour="${string:8:2}"
local minute="${string:10:2}"
local second="${string:12:2}"
if ! date -d "$year-$month-$day $hour:$minute:$second" &> /dev/null; then
echo "String format must be yyyymmddhhmmss"
return 1
fi
return 0
}
input_string=$(oc -n ${{ env.DEV_NAMESPACE }} describe deployment/lcfs-frontend-dev | grep Image | awk -F '-' '{print $NF}')
echo "The retrieved pre-release number on Dev is $input_string "
if check_string "$input_string"; then
echo "It is valid"
echo "PRE_RELEASE=$input_string" >> $GITHUB_OUTPUT
else
echo "It is not valid"
exit 1
fi
deploy-on-test:
name: Deploy LCFS on Test
runs-on: ubuntu-latest
timeout-minutes: 60
needs: [set-pre-release]
env:
PRE_RELEASE: ${{ needs.set-pre-release.outputs.output1 }}
steps:
- id: get-current-time
run: |
echo "CURRENT_TIME=$(TZ='America/Vancouver' date '+%Y-%m-%d %H:%M:%S %Z')" >> $GITHUB_OUTPUT
- name: Ask for approval for LCFS release-${{ env.VERSION }} Test deployment
uses: trstringer/[email protected]
with:
secret: ${{ github.TOKEN }}
approvers: AlexZorkin,kuanfandevops,hamed-valiollahi,airinggov,areyeslo,dhaselhan,Grulin,kevin-hashimoto
minimum-approvals: 1
issue-title: "LCFS ${{ env.VERSION }}-${{ env.PRE_RELEASE }} Test Deployment at ${{ steps.get-current-time.outputs.CURRENT_TIME }}"
- name: Restore oc command from Cache
uses: actions/[email protected]
with:
path: /usr/local/bin/oc
key: oc-cli-${{ runner.os }}
- name: Log in to Openshift
uses: redhat-actions/[email protected]
with:
openshift_server_url: ${{ secrets.OPENSHIFT_SERVER }}
openshift_token: ${{ secrets.OPENSHIFT_TOKEN }}
insecure_skip_tls_verify: true
namespace: ${{ env.DEV_NAMESPACE }}
- name: Tag LCFS images to Test
run: |
oc tag ${{ env.DEV_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-$PRE_RELEASE ${{ env.TEST_NAMESPACE }}/lcfs-backend:${{ env.VERSION }}-$PRE_RELEASE
oc tag ${{ env.DEV_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-$PRE_RELEASE ${{ env.TEST_NAMESPACE }}/lcfs-frontend:${{ env.VERSION }}-$PRE_RELEASE
- name: Checkout Manifest repository
uses: actions/checkout@v3
with:
repository: bcgov-c/tenant-gitops-d2bd59
ref: main
ssh-key: ${{ secrets.MANIFEST_REPO_DEPLOY_KEY }}
- name: Update frontend tag
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-frontend/values-test.yaml
- name: Update backend tag
uses: mikefarah/[email protected]
with:
cmd: yq -i '.image.tag = "${{ env.VERSION }}-${{ env.PRE_RELEASE }}"' lcfs/charts/lcfs-backend/values-test.yaml
- name: GitHub Commit & Push
run: |
git config --global user.email "[email protected]"
git config --global user.name "GitHub Actions"
git add lcfs/charts/lcfs-frontend/values-test.yaml
git add lcfs/charts/lcfs-backend/values-test.yaml
git commit -m "Update the image tag to ${{ env.VERSION }}-${{ env.PRE_RELEASE }} on LCFS Test Environment"
git push