empty feature environment test #14
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
name: "Deploy to feature environment" | |
on: | |
pull_request: | |
branches: | |
- main | |
workflow_dispatch: | |
inputs: | |
stack: | |
type: string | |
description: Stack name | |
required: false | |
core-image-tag: | |
type: string | |
description: Core DockerHub image tag | |
required: false | |
countryconfig-image-tag: | |
type: string | |
description: Countryconfig DockerHub image tag | |
required: false | |
jobs: | |
trigger: | |
runs-on: ubuntu-latest | |
outputs: | |
run_id: ${{ steps.get-run-id.outputs.run_id }} | |
steps: | |
- name: Fetch latest commit tag from opencrvs-core develop branch | |
if: inputs.core-image-tag == '' | |
run: | | |
CORE_COMMIT_HASH=$(curl -s https://api.github.com/repos/opencrvs/opencrvs-core/commits/develop | jq -r '.sha' | cut -c1-7) | |
echo "CORE_COMMIT_HASH=$CORE_COMMIT_HASH" >> $GITHUB_ENV | |
- name: Fetch latest commit tag from opencrvs-farajaland mosip branch | |
if: inputs.countryconfig-image-tag == '' | |
run: | | |
FARAJALAND_COMMIT_HASH=$(curl -s https://api.github.com/repos/opencrvs/opencrvs-farajaland/commits/mosip | jq -r '.sha' | cut -c1-7) | |
echo "FARAJALAND_COMMIT_HASH=$FARAJALAND_COMMIT_HASH" >> $GITHUB_ENV | |
- name: Trigger workflow in e2e repository | |
env: | |
GITHUB_TOKEN: ${{ secrets.OLLIE_BOT_GITHUB_TOKEN }} | |
CORE_COMMIT_HASH: ${{ env.CORE_COMMIT_HASH }} | |
FARAJALAND_COMMIT_HASH: ${{ env.FARAJALAND_COMMIT_HASH }} | |
run: | | |
KEBAB_CASE_STACK=$(echo ${{ github.head_ref }} | tr '[:upper:]' '[:lower:]' | tr -c 'a-z' '-' | sed 's/-\+/-/g') | |
MOSIP_STACK=$(echo "mosip-$KEBAB_CASE_STACK" | cut -c 1-35) | |
curl -X POST \ | |
-H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
https://api.github.com/repos/opencrvs/e2e/actions/workflows/deploy.yml/dispatches \ | |
-d '{ | |
"ref": "mosip", | |
"inputs": { | |
"core-image-tag": "'"$CORE_COMMIT_HASH"'", | |
"countryconfig-image-tag": "'"$FARAJALAND_COMMIT_HASH"'", | |
"stack": "'"$MOSIP_STACK"'", | |
"dependencies": false, | |
"reset": true | |
} | |
}' | |
wait-for-completion: | |
needs: trigger | |
runs-on: ubuntu-latest | |
steps: | |
- name: Get run_id of triggered workflow | |
id: get-run-id | |
env: | |
GITHUB_TOKEN: ${{ secrets.OLLIE_BOT_GITHUB_TOKEN }} | |
run: | | |
# Wait for workflow to be created | |
sleep 10 | |
RUN_ID=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/opencrvs/e2e/actions/workflows/deploy.yml/runs?branch=mosip&per_page=1" \ | |
| jq -r '.workflow_runs[0].id') | |
echo "run_id=$RUN_ID" >> $GITHUB_OUTPUT | |
- name: Poll workflow status | |
env: | |
RUN_ID: ${{ steps.get-run-id.outputs.run_id }} | |
GITHUB_TOKEN: ${{ secrets.OLLIE_BOT_GITHUB_TOKEN }} | |
run: | | |
STATUS="in_progress" | |
while [[ "$STATUS" == "in_progress" || "$STATUS" == "queued" ]]; do | |
STATUS=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/opencrvs/e2e/actions/runs/$RUN_ID" \ | |
| jq -r '.status') | |
echo "Workflow run status: $STATUS" | |
[[ "$STATUS" == "completed" ]] && break | |
sleep 10 | |
done | |
CONCLUSION=$(curl -H "Authorization: Bearer $GITHUB_TOKEN" \ | |
-H "Accept: application/vnd.github.v3+json" \ | |
"https://api.github.com/repos/opencrvs/e2e/actions/runs/$RUN_ID" \ | |
| jq -r '.conclusion') | |
if [[ "$CONCLUSION" != "success" ]]; then | |
echo "Workflow run failed with conclusion: $CONCLUSION" | |
exit 1 | |
fi | |
echo "Workflow run succeeded!" |