From cb6b179fe6a164aa943714df0075735be2ab3052 Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 26 Feb 2024 07:40:30 +0000 Subject: [PATCH 01/11] Add error message --- ci/restore_questionnaire_state.yaml | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index 68e9f30fbc..b38e74aca6 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -25,6 +25,11 @@ run: gcloud auth activate-service-account --key-file $GOOGLE_APPLICATION_CREDENTIALS gcloud config set project "${PROJECT_ID}" + if [[ -z "${BACKUP_NAME}"]]; then + echo "BACKUP_NAME variable is not set" + exit 1 + fi + IMPORT_OPERATION=$(gcloud datastore import gs://"${BUCKET_NAME}/${FILE_PREFIX}/${BACKUP_NAME}/${BACKUP_NAME}.overall_export_metadata" --kinds="questionnaire-state" --format="value(name.scope())") IMPORT_STATE=$(gcloud datastore operations describe "${IMPORT_OPERATION}" --format="value(metadata.common.state.scope())") TOTAL_ENTITIES_IMPORTED=$(gcloud datastore operations describe "${IMPORT_OPERATION}" --format="value(metadata.progressEntities.workCompleted.scope())") From 952ff82dcd5b38a2a8bd291bb3b6bdbbf904d45e Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 26 Feb 2024 07:45:26 +0000 Subject: [PATCH 02/11] Fix conditional statement --- ci/restore_questionnaire_state.yaml | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index b38e74aca6..cf366960c0 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -25,7 +25,8 @@ run: gcloud auth activate-service-account --key-file $GOOGLE_APPLICATION_CREDENTIALS gcloud config set project "${PROJECT_ID}" - if [[ -z "${BACKUP_NAME}"]]; then + if [ -z "${BACKUP_NAME}" ] + then echo "BACKUP_NAME variable is not set" exit 1 fi From 6ab7f783a60dc2abdfa280231b6498f29dc6f1ff Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 26 Feb 2024 07:47:33 +0000 Subject: [PATCH 03/11] Fix error message --- ci/restore_questionnaire_state.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index cf366960c0..e1105afbe8 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -27,7 +27,7 @@ run: if [ -z "${BACKUP_NAME}" ] then - echo "BACKUP_NAME variable is not set" + echo "BACKUP_NAME variable must be set" exit 1 fi From aa61152acde0f08c31860ae9dc8d444331ad0712 Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 26 Feb 2024 09:17:56 +0000 Subject: [PATCH 04/11] Change message text --- ci/restore_questionnaire_state.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index e1105afbe8..dcfcbd995d 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -27,7 +27,7 @@ run: if [ -z "${BACKUP_NAME}" ] then - echo "BACKUP_NAME variable must be set" + echo "BACKUP_NAME is unset or set to the empty string" exit 1 fi From fb994e12e555eed92390c47ca6d98d5bb438fce3 Mon Sep 17 00:00:00 2001 From: petechd Date: Mon, 26 Feb 2024 13:13:16 +0000 Subject: [PATCH 05/11] Add if statement at the top --- ci/restore_questionnaire_state.yaml | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index dcfcbd995d..26b36676ba 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -2,7 +2,7 @@ platform: linux image_resource: type: registry-image source: - repository: gcr.io/google.com/cloudsdktool/cloud-sdk + repository: gcr.io/google.com/cloudsdktool/cloud-sdk:slim tag: alpine params: SERVICE_ACCOUNT_JSON: ((gcp.service_account_json)) @@ -17,6 +17,12 @@ run: args: - -exc - | + if [ -z "${BACKUP_NAME}" ] + then + echo "BACKUP_NAME is unset or set to the empty string" + exit 1 + fi + export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json cat >$GOOGLE_APPLICATION_CREDENTIALS < Date: Mon, 26 Feb 2024 13:20:04 +0000 Subject: [PATCH 06/11] Add if statement at the top, reword --- ci/restore_questionnaire_state.yaml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index 26b36676ba..b7d13fbc64 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -2,7 +2,7 @@ platform: linux image_resource: type: registry-image source: - repository: gcr.io/google.com/cloudsdktool/cloud-sdk:slim + repository: gcr.io/google.com/cloudsdktool/cloud-sdk tag: alpine params: SERVICE_ACCOUNT_JSON: ((gcp.service_account_json)) @@ -19,7 +19,7 @@ run: - | if [ -z "${BACKUP_NAME}" ] then - echo "BACKUP_NAME is unset or set to the empty string" + echo "BACKUP_NAME variable must be set" exit 1 fi From d44dd081731eaaa79fe0158b14455c8cee7915a3 Mon Sep 17 00:00:00 2001 From: petechd Date: Wed, 28 Feb 2024 08:50:04 +0000 Subject: [PATCH 07/11] Add a loop to check all vars --- ci/restore_questionnaire_state.yaml | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index b7d13fbc64..ef3f0ed6a6 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -17,11 +17,16 @@ run: args: - -exc - | - if [ -z "${BACKUP_NAME}" ] - then - echo "BACKUP_NAME variable must be set" - exit 1 - fi + VARS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME', 'FILE_PREFIX') + + for VAR in "${VARS[@]}" + do + if [ -z "${!VAR}" ] + then + echo "$VAR variable must be set" + exit 1 + fi + done export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json cat >$GOOGLE_APPLICATION_CREDENTIALS < Date: Wed, 28 Feb 2024 08:59:22 +0000 Subject: [PATCH 08/11] Remove comma --- ci/restore_questionnaire_state.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index ef3f0ed6a6..9dc4567665 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -17,7 +17,7 @@ run: args: - -exc - | - VARS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME', 'FILE_PREFIX') + VARS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME' 'FILE_PREFIX') for VAR in "${VARS[@]}" do From 5dea62247c3af318b6df99f21cbfb783a2848722 Mon Sep 17 00:00:00 2001 From: petechd Date: Wed, 6 Mar 2024 10:01:45 +0000 Subject: [PATCH 09/11] Fix naming and reduce the number of lines --- ci/restore_questionnaire_state.yaml | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index 9dc4567665..ff4c43badd 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -17,15 +17,9 @@ run: args: - -exc - | - VARS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME' 'FILE_PREFIX') - - for VAR in "${VARS[@]}" - do - if [ -z "${!VAR}" ] - then - echo "$VAR variable must be set" - exit 1 - fi + PARAMS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME' 'FILE_PREFIX') + for PARAM in "${PARAMS[@]}"; do + : "${!PARAM:?"Error: $PARAM must be set"}" done export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json From 350b64f05c2f141d38efe5c409d0e7a9011d6ee6 Mon Sep 17 00:00:00 2001 From: petechd Date: Fri, 8 Mar 2024 10:01:15 +0000 Subject: [PATCH 10/11] Add indentation --- ci/restore_questionnaire_state.yaml | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index ff4c43badd..739f584fac 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -18,8 +18,9 @@ run: - -exc - | PARAMS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME' 'FILE_PREFIX') - for PARAM in "${PARAMS[@]}"; do - : "${!PARAM:?"Error: $PARAM must be set"}" + for PARAM in "${PARAMS[@]}" + do + "${!PARAM:?"Error: $PARAM must be set"}" done export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json From 12de9e139df47956eff6d5c36dce590c660c11c4 Mon Sep 17 00:00:00 2001 From: petechd Date: Fri, 8 Mar 2024 10:06:53 +0000 Subject: [PATCH 11/11] Fix the command --- ci/restore_questionnaire_state.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ci/restore_questionnaire_state.yaml b/ci/restore_questionnaire_state.yaml index 739f584fac..8c03b5959b 100644 --- a/ci/restore_questionnaire_state.yaml +++ b/ci/restore_questionnaire_state.yaml @@ -20,7 +20,7 @@ run: PARAMS=('PROJECT_ID' 'BUCKET_NAME' 'BACKUP_NAME' 'FILE_PREFIX') for PARAM in "${PARAMS[@]}" do - "${!PARAM:?"Error: $PARAM must be set"}" + : "${!PARAM:?"Error: $PARAM must be set"}" done export GOOGLE_APPLICATION_CREDENTIALS=~/gcloud-service-key.json