Skip to content

Commit

Permalink
workflow runner env var
Browse files Browse the repository at this point in the history
  • Loading branch information
mwarman committed Oct 16, 2024
1 parent 90a913e commit 10d10f8
Show file tree
Hide file tree
Showing 11 changed files with 23 additions and 4 deletions.
10 changes: 6 additions & 4 deletions .appflow/scripts/prebuild.sh
Original file line number Diff line number Diff line change
@@ -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
1 change: 1 addition & 0 deletions .github/workflows/deploy-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-prod.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/deploy-qa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/common/providers/ConfigProvider.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,7 @@ const configSchema: ObjectSchema<Config> = 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),
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/i18n/resources/en/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name": "Name",
"native": "Native",
"platforms": "Platforms",
"runner": "Runner",
"sha": "SHA",
"time": "Time",
"version": "Version",
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/i18n/resources/es/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name": "Nombre",
"native": "Nativo",
"platforms": "Plataformas",
"runner": "Corredor",
"sha": "SHA",
"time": "Tiempo",
"version": "Versión",
Expand Down
1 change: 1 addition & 0 deletions src/common/utils/i18n/resources/fr/account.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
"name": "Nom",
"native": "Natal",
"platforms": "Plateformes",
"runner": "Coureur",
"sha": "SHA",
"time": "Temps",
"version": "Version",
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Account/components/Diagnostics/BuildDiagnostics.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,12 @@ const BuildDiagnostics = ({
{config.VITE_BUILD_COMMIT_SHA}
</IonText>
</IonItem>
<IonItem className="text-sm">
<IonLabel className="font-medium ion-margin-end">
{t('diagnostics.label.runner', { ns: 'account' })}
</IonLabel>
<IonText data-testid={`${testid}-runner`}>{config.VITE_BUILD_WORKFLOW_RUNNER}</IonText>
</IonItem>
<IonItem className="text-sm">
<IonLabel className="font-medium ion-margin-end">
{t('diagnostics.label.workflow', { ns: 'account' })}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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');
});
});

0 comments on commit 10d10f8

Please sign in to comment.