From 10d10f8499c4e71495e8a4acf23017eaf0ca0343 Mon Sep 17 00:00:00 2001 From: Matthew Warman Date: Wed, 16 Oct 2024 10:47:07 -0400 Subject: [PATCH] workflow runner env var --- .appflow/scripts/prebuild.sh | 10 ++++++---- .github/workflows/deploy-dev.yml | 1 + .github/workflows/deploy-prod.yml | 1 + .github/workflows/deploy-qa.yml | 1 + README.md | 2 ++ src/common/providers/ConfigProvider.tsx | 2 ++ src/common/utils/i18n/resources/en/account.json | 1 + src/common/utils/i18n/resources/es/account.json | 1 + src/common/utils/i18n/resources/fr/account.json | 1 + .../components/Diagnostics/BuildDiagnostics.tsx | 6 ++++++ .../Diagnostics/__tests__/BuildDiagnostics.test.tsx | 1 + 11 files changed, 23 insertions(+), 4 deletions(-) diff --git a/.appflow/scripts/prebuild.sh b/.appflow/scripts/prebuild.sh index c8313be..f09ce5b 100755 --- a/.appflow/scripts/prebuild.sh +++ b/.appflow/scripts/prebuild.sh @@ -1,20 +1,22 @@ #!/bin/bash # npm hook run before the build script # see: https://ionic.io/docs/appflow/automation/environments +# see: https://ionic.io/docs/appflow/cookbook/hooks#npm-pre--post-scripts -# echo ">>> prebuild script" +printenv # create .env file if running in Ionic Appflow -if [ "$CI_AUTOMATED_BUILD" = "1" ] +if [ "$CI_SERVER" = "yes" ] then echo "Appflow build; creating .env file" echo "VITE_BUILD_DATE=$(date +'%Y-%m-%d')" > .env echo "VITE_BUILD_TIME=$(date +'%H:%M:%S%z')" >> .env echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env echo "VITE_BUILD_COMMIT_SHA=$CI_GIT_COMMIT_SHA" >> .env - echo "VITE_BUILD_WORKFLOW_NAME=$CI_AUTOMATION_NAME" >> .env + echo "VITE_BUILD_WORKFLOW_RUNNER=Appflow" >> .env + echo "VITE_BUILD_WORKFLOW_NAME=$CI_APP_NAME" >> .env echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=$CI_BUILD_NUMBER" >> .env - echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=1" >> .env + echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=" >> .env else echo "NOT an Appflow build; skipping .env file creation" fi diff --git a/.github/workflows/deploy-dev.yml b/.github/workflows/deploy-dev.yml index ca55754..9fe562a 100644 --- a/.github/workflows/deploy-dev.yml +++ b/.github/workflows/deploy-dev.yml @@ -51,6 +51,7 @@ jobs: echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env echo "VITE_BUILD_COMMIT_SHA=${{ github.sha }}" >> .env echo "VITE_BUILD_ENV_CODE=${{ env.AWS_ENV_CODE }}" >> .env + echo "VITE_BUILD_WORKFLOW_RUNNER=GitHub Actions" >> .env echo "VITE_BUILD_WORKFLOW_NAME=${{ github.workflow }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=${{ github.run_number }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=${{ github.run_attempt }}" >> .env diff --git a/.github/workflows/deploy-prod.yml b/.github/workflows/deploy-prod.yml index 381095e..a11713d 100644 --- a/.github/workflows/deploy-prod.yml +++ b/.github/workflows/deploy-prod.yml @@ -52,6 +52,7 @@ jobs: echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env echo "VITE_BUILD_COMMIT_SHA=${{ github.sha }}" >> .env echo "VITE_BUILD_ENV_CODE=${{ env.AWS_ENV_CODE }}" >> .env + echo "VITE_BUILD_WORKFLOW_RUNNER=GitHub Actions" >> .env echo "VITE_BUILD_WORKFLOW_NAME=${{ github.workflow }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=${{ github.run_number }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=${{ github.run_attempt }}" >> .env diff --git a/.github/workflows/deploy-qa.yml b/.github/workflows/deploy-qa.yml index 3e5fde2..f673aab 100644 --- a/.github/workflows/deploy-qa.yml +++ b/.github/workflows/deploy-qa.yml @@ -51,6 +51,7 @@ jobs: echo "VITE_BUILD_TS=$(date +'%Y-%m-%dT%H:%M:%S%z')" >> .env echo "VITE_BUILD_COMMIT_SHA=${{ github.sha }}" >> .env echo "VITE_BUILD_ENV_CODE=${{ env.AWS_ENV_CODE }}" >> .env + echo "VITE_BUILD_WORKFLOW_RUNNER=GitHub Actions" >> .env echo "VITE_BUILD_WORKFLOW_NAME=${{ github.workflow }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_NUMBER=${{ github.run_number }}" >> .env echo "VITE_BUILD_WORKFLOW_RUN_ATTEMPT=${{ github.run_attempt }}" >> .env diff --git a/README.md b/README.md index ec81249..e671b16 100644 --- a/README.md +++ b/README.md @@ -148,6 +148,7 @@ VITE_BUILD_TIME=00:00:00 VITE_BUILD_TS=1970-01-01T00:00:00+0000 VITE_BUILD_COMMIT_SHA=local VITE_BUILD_ENV_CODE=local +VITE_BUILD_WORKFLOW_RUNNER=local VITE_BUILD_WORKFLOW_NAME=local VITE_BUILD_WORKFLOW_RUN_NUMBER=1 VITE_BUILD_WORKFLOW_RUN_ATTEMPT=1 @@ -172,6 +173,7 @@ VITE_BUILD_TIME=00:00:00 VITE_BUILD_TS=1970-01-01T00:00:00+0000 VITE_BUILD_COMMIT_SHA=test VITE_BUILD_ENV_CODE=test +VITE_BUILD_WORKFLOW_RUNNER=test VITE_BUILD_WORKFLOW_NAME=test VITE_BUILD_WORKFLOW_RUN_NUMBER=1 VITE_BUILD_WORKFLOW_RUN_ATTEMPT=1 diff --git a/src/common/providers/ConfigProvider.tsx b/src/common/providers/ConfigProvider.tsx index 7e5e99e..b978f00 100644 --- a/src/common/providers/ConfigProvider.tsx +++ b/src/common/providers/ConfigProvider.tsx @@ -11,6 +11,7 @@ export interface Config { VITE_BUILD_TS: string; VITE_BUILD_COMMIT_SHA: string; VITE_BUILD_ENV_CODE: string; + VITE_BUILD_WORKFLOW_RUNNER: string; VITE_BUILD_WORKFLOW_NAME: string; VITE_BUILD_WORKFLOW_RUN_NUMBER: number; VITE_BUILD_WORKFLOW_RUN_ATTEMPT: number; @@ -28,6 +29,7 @@ const configSchema: ObjectSchema = object({ VITE_BUILD_TS: string().default('1970-01-01T00:00:00+0000'), VITE_BUILD_COMMIT_SHA: string().default('local'), VITE_BUILD_ENV_CODE: string().default('local'), + VITE_BUILD_WORKFLOW_RUNNER: string().default('local'), VITE_BUILD_WORKFLOW_NAME: string().default('local'), VITE_BUILD_WORKFLOW_RUN_NUMBER: number().default(1), VITE_BUILD_WORKFLOW_RUN_ATTEMPT: number().default(1), diff --git a/src/common/utils/i18n/resources/en/account.json b/src/common/utils/i18n/resources/en/account.json index 41a1390..622725a 100644 --- a/src/common/utils/i18n/resources/en/account.json +++ b/src/common/utils/i18n/resources/en/account.json @@ -11,6 +11,7 @@ "name": "Name", "native": "Native", "platforms": "Platforms", + "runner": "Runner", "sha": "SHA", "time": "Time", "version": "Version", diff --git a/src/common/utils/i18n/resources/es/account.json b/src/common/utils/i18n/resources/es/account.json index 9301ec2..ca9eaaf 100644 --- a/src/common/utils/i18n/resources/es/account.json +++ b/src/common/utils/i18n/resources/es/account.json @@ -11,6 +11,7 @@ "name": "Nombre", "native": "Nativo", "platforms": "Plataformas", + "runner": "Corredor", "sha": "SHA", "time": "Tiempo", "version": "VersiĆ³n", diff --git a/src/common/utils/i18n/resources/fr/account.json b/src/common/utils/i18n/resources/fr/account.json index 3a54b41..bfacfc9 100644 --- a/src/common/utils/i18n/resources/fr/account.json +++ b/src/common/utils/i18n/resources/fr/account.json @@ -11,6 +11,7 @@ "name": "Nom", "native": "Natal", "platforms": "Plateformes", + "runner": "Coureur", "sha": "SHA", "time": "Temps", "version": "Version", diff --git a/src/pages/Account/components/Diagnostics/BuildDiagnostics.tsx b/src/pages/Account/components/Diagnostics/BuildDiagnostics.tsx index be95f66..f05a06d 100644 --- a/src/pages/Account/components/Diagnostics/BuildDiagnostics.tsx +++ b/src/pages/Account/components/Diagnostics/BuildDiagnostics.tsx @@ -50,6 +50,12 @@ const BuildDiagnostics = ({ {config.VITE_BUILD_COMMIT_SHA} + + + {t('diagnostics.label.runner', { ns: 'account' })} + + {config.VITE_BUILD_WORKFLOW_RUNNER} + {t('diagnostics.label.workflow', { ns: 'account' })} diff --git a/src/pages/Account/components/Diagnostics/__tests__/BuildDiagnostics.test.tsx b/src/pages/Account/components/Diagnostics/__tests__/BuildDiagnostics.test.tsx index dfd7f13..25c0a89 100644 --- a/src/pages/Account/components/Diagnostics/__tests__/BuildDiagnostics.test.tsx +++ b/src/pages/Account/components/Diagnostics/__tests__/BuildDiagnostics.test.tsx @@ -24,6 +24,7 @@ describe('BuildDiagnostics', () => { expect(screen.getByTestId('build-env')).toHaveTextContent('test'); expect(screen.getByTestId('build-time')).toHaveTextContent('1970-01-01 00:00:00 +00:00'); expect(screen.getByTestId('build-sha')).toHaveTextContent('test'); + expect(screen.getByTestId('build-runner')).toHaveTextContent('test'); expect(screen.getByTestId('build-workflow')).toHaveTextContent('test 1.1'); }); });