-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Netlify ci/cd * Netlify ci/cd * Update Netlify azure pipeline * Fix environment name * Cleanup * temp comment yarn check * Add back yarn check * remove npmAlwaysAuth * Adding back npmAlwaysAuth remove from yarnrc.yml * Update param
- Loading branch information
1 parent
053ef7e
commit 09b95e1
Showing
12 changed files
with
854 additions
and
2 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env pwsh | ||
#Requires -Version 7 | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $True)] | ||
[string]$SiteName, | ||
[Parameter(Mandatory = $True)] | ||
[string]$Context | ||
) | ||
|
||
Set-StrictMode -Version Latest | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$projectRoot = Split-Path -Path $PSScriptRoot -Parent | ||
Push-Location -Path $projectRoot | ||
try { | ||
. (Join-Path -Path $projectRoot -ChildPath '.azure-pipelines' -AdditionalChildPath 'utilities.ps1') | ||
|
||
# Setting up environment variables | ||
Show-LogSection -Content 'Setting up environment variables...' | ||
if ($Context -eq 'production') { | ||
Show-LogInfo -Content 'Setting public url and mixpanel token.' | ||
$Env:PUBLIC_URL = '/app' | ||
if ($SiteName -eq 'test') { | ||
$Env:REACT_APP_MIXPANEL_TOKEN = '4b245bace4eed86ffdfa35efc3addf1d' | ||
$Env:REACT_APP_API_URL = 'https://app-api-testing.salad.com' | ||
$Env:REACT_APP_PAYPAL_URL = 'https://www.sandbox.paypal.com/connect/?flowEntry=static&client_id=AYjYnvjB968mKTIhMqUtLlNa8CJuF9rg_Q4m0Oym5gFvBkZEMPPoooXcG94OjSCjih7kI1_KM25EgfDs&response_type=code&scope=openid%20email%20https%3A%2F%2Furi.paypal.com%2Fservices%2Fpaypalattributes&redirect_uri=https%253A%252F%252Fapp-api-testing.salad.com%252Fapi%252Fv2%252Fpaypal-account-callback' | ||
$Env:REACT_APP_PROHASHING_USERNAME = 'saladtest' | ||
$Env:REACT_APP_SEARCH_ENGINE = 'salad-rewards-test' | ||
$Env:REACT_APP_SEARCH_KEY = 'search-qced4ibef8m4s7xacm9hoqyk' | ||
$Env:REACT_APP_STRAPI_UPLOAD_URL = 'https://cms-api-testing.salad.io' | ||
$Env:REACT_APP_UNLEASH_API_KEY = 'zrujLzhnwVZkIOlS74oZZ0DK7ZXs3Ifo' | ||
$Env:REACT_APP_UNLEASH_URL = 'https://features-testing.salad.com/proxy' | ||
} | ||
else { | ||
$Env:REACT_APP_MIXPANEL_TOKEN = '68db9194f229525012624f3cf368921f' | ||
} | ||
} | ||
|
||
# Build projects. | ||
Show-LogSection -Content 'Building projects...' | ||
Show-LogCommand -Content "yarn run build " | ||
& yarn run build | ||
Assert-LastExitCodeSuccess -LastExecutableName 'yarn' | ||
} | ||
catch { | ||
if (($null -ne $_.ErrorDetails) -and ($null -ne $_.ErrorDetails.Message)) { | ||
Show-LogError -Content $_.ErrorDetails.Message | ||
} | ||
elseif (($null -ne $_.Exception) -and ($null -ne $_.Exception.Message)) { | ||
Show-LogError -Content $_.Exception.Message | ||
} | ||
else { | ||
Show-LogError -Content $_ | ||
} | ||
|
||
exit 1 | ||
} | ||
finally { | ||
Pop-Location | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
#!/usr/bin/env pwsh | ||
[CmdletBinding()] | ||
param( | ||
[Parameter(Mandatory = $True)] | ||
[string]$Context | ||
) | ||
|
||
Set-StrictMode -Version Latest | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$projectRoot = Split-Path -Path $PSScriptRoot -Parent | ||
Push-Location -Path $projectRoot | ||
try { | ||
. (Join-Path -Path $projectRoot -ChildPath '.azure-pipelines' -AdditionalChildPath 'utilities.ps1') | ||
|
||
$buildDirectory = Join-Path -Path $projectRoot -ChildPath 'build' | ||
|
||
# Deploy to Netlify | ||
Write-LogSection -Content 'Deploying to Netlify...' | ||
if ($Context -eq 'production') { | ||
Write-LogCommand -Content "netlify deploy --dir ${buildDirectory} --prodIfUnlocked" | ||
& netlify deploy --dir $buildDirectory --prodIfUnlocked | ||
Assert-LastExitCodeSuccess -LastExecutableName 'netlify' | ||
} | ||
else { | ||
$alias = '' | ||
$message = '' | ||
if (Test-AzureDevOpsEnvironment) { | ||
$shortHash = $Env:BUILD_SOURCEVERSION.Substring(0, 7) | ||
$message = "Deploy Preview #${Env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}: ${Env:SYSTEM_PULLREQUEST_SOURCEBRANCH}@${shortHash}" | ||
$alias = "deploy-preview-${Env:SYSTEM_PULLREQUEST_PULLREQUESTNUMBER}" | ||
} | ||
else { | ||
$alias = 'no-alias' | ||
$message = 'no-message' | ||
} | ||
Write-LogCommand -Content "netlify deploy --dir ${buildDirectory} --alias ${alias} --message ${message}" | ||
& netlify deploy --dir $buildDirectory --alias $alias --message $message | ||
Assert-LastExitCodeSuccess -LastExecutableName 'netlify' | ||
} | ||
} | ||
catch { | ||
if (($null -ne $_.ErrorDetails) -and ($null -ne $_.ErrorDetails.Message)) { | ||
Write-LogError -Content $_.ErrorDetails.Message | ||
} | ||
elseif (($null -ne $_.Exception) -and ($null -ne $_.Exception.Message)) { | ||
Write-LogError -Content $_.Exception.Message | ||
} | ||
else { | ||
Write-LogError -Content $_ | ||
} | ||
|
||
exit 1 | ||
} | ||
finally { | ||
Pop-Location | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
#!/usr/bin/env pwsh | ||
[CmdletBinding()] | ||
param() | ||
|
||
Set-StrictMode -Version Latest | ||
$ErrorActionPreference = 'Stop' | ||
|
||
$projectRoot = Split-Path -Path $PSScriptRoot -Parent | ||
Push-Location -Path $projectRoot | ||
try { | ||
. (Join-Path -Path $projectRoot -ChildPath '.azure-pipelines' -AdditionalChildPath 'utilities.ps1') | ||
|
||
$buildDirectory = Join-Path -Path $projectRoot -ChildPath 'build' | ||
$srcDirectory = Join-Path -Path $projectRoot -ChildPath 'src' | ||
|
||
# Verify Node.js and npm | ||
Show-LogSection -Content 'Verifying Node.js, npm, and Yarn...' | ||
|
||
$nodeVersion = Get-NodeVersion | ||
if ($null -eq $nodeVersion) { | ||
Write-Error -Message 'Node.js is not installed' | ||
} | ||
|
||
$nvmrcVersion = Get-NvmrcVersion | ||
if ($null -eq $nvmrcVersion -or 0 -ne (Compare-NodeVersion -FirstVersion $nodeVersion -SecondVersion $nvmrcVersion)) { | ||
Write-Error -Message "Node.js ${nvmrcVersion} is not installed (found ${nodeVersion})" | ||
} | ||
|
||
Show-LogInfo -Content "Node.js ${nodeVersion} is installed" | ||
|
||
$npmVersion = Get-NpmVersion | ||
if ($null -eq $npmVersion) { | ||
Write-Error -Message 'npm is not installed' | ||
} | ||
|
||
Show-LogInfo -Content "npm ${npmVersion} is installed" | ||
|
||
$yarnVersion = Get-YarnVersion | ||
if ($null -eq $yarnVersion) { | ||
Write-Error -Message 'Yarn is not installed' | ||
} | ||
|
||
Show-LogInfo -Content "Yarn ${yarnVersion} is installed" | ||
|
||
# Install dependencies | ||
Show-LogSection -Content 'Installing dependencies...' | ||
|
||
Show-LogCommand -Content 'yarn install' | ||
& yarn install | ||
Assert-LastExitCodeSuccess -LastExecutableName 'yarn' | ||
|
||
$netlifyVersion = $null | ||
& npm list netlify-cli --global --depth 0 | Out-Null | ||
if (0 -eq $LastExitCode) { | ||
$netlifyVersion = Get-NetlifyVersion | ||
} | ||
|
||
if ($null -eq $netlifyVersion) { | ||
Show-LogCommand -Content 'npm install --global netlify-cli' | ||
& npm install --global netlify-cli | ||
Assert-LastExitCodeSuccess -LastExecutableName 'npm' | ||
|
||
$netlifyVersion = Get-NetlifyVersion | ||
if ($null -eq $netlifyVersion) { | ||
Write-Error -Message 'Failed to install Netlify CLI' | ||
} | ||
} | ||
|
||
Show-LogInfo -Content "Netlify CLI ${netlifyVersion} is installed" | ||
|
||
# Clean | ||
Show-LogSection -Content 'Cleaning...' | ||
|
||
if (Test-Path -Path $buildDirectory) { | ||
Remove-Item -Path $buildDirectory -Recurse -Force | ||
} | ||
|
||
New-Item -ItemType Directory -Path $buildDirectory | Out-Null | ||
|
||
} | ||
catch { | ||
if (($null -ne $_.ErrorDetails) -and ($null -ne $_.ErrorDetails.Message)) { | ||
Show-LogError -Content $_.ErrorDetails.Message | ||
} | ||
elseif (($null -ne $_.Exception) -and ($null -ne $_.Exception.Message)) { | ||
Show-LogError -Content $_.Exception.Message | ||
} | ||
else { | ||
Show-LogError -Content $_ | ||
} | ||
|
||
exit 1 | ||
} | ||
finally { | ||
Pop-Location | ||
} |
24 changes: 24 additions & 0 deletions
24
packages/web-app/.azure-pipelines/stages/deploy-preview-stage.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
parameters: | ||
- name: workingDirectory | ||
type: string | ||
default: "" | ||
|
||
stages: | ||
- stage: DeployPreview | ||
displayName: Deploy Site Preview | ||
jobs: | ||
- deployment: DeployPreview | ||
displayName: Deploy Site Preview | ||
variables: | ||
- group: Netlify | ||
environment: Netlify Test | ||
strategy: | ||
runOnce: | ||
deploy: | ||
steps: | ||
- template: ../steps/deploy-steps.yaml | ||
parameters: | ||
workingDirectory: ${{ parameters.workingDirectory }} | ||
siteId: b32d496d-3b42-4727-bd8c-5798a32b1ad4 | ||
siteName: test | ||
context: deploy-preview |
25 changes: 25 additions & 0 deletions
25
packages/web-app/.azure-pipelines/stages/deploy-prod-stage.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
parameters: | ||
- name: workingDirectory | ||
type: string | ||
default: "" | ||
|
||
stages: | ||
- stage: DeployProd | ||
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest')) | ||
displayName: Deploy to Production Site | ||
jobs: | ||
- deployment: DeployProd | ||
displayName: Deploy to Production Site | ||
variables: | ||
- group: Netlify | ||
environment: Netlify Web App | ||
strategy: | ||
runOnce: | ||
deploy: | ||
steps: | ||
- template: ../steps/deploy-steps.yaml | ||
parameters: | ||
workingDirectory: ${{ parameters.workingDirectory }} | ||
siteId: d5fb99c8-d018-48be-a2c8-1a1900831793 | ||
siteName: production | ||
context: production |
25 changes: 25 additions & 0 deletions
25
packages/web-app/.azure-pipelines/stages/deploy-test-stage.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
parameters: | ||
- name: workingDirectory | ||
type: string | ||
default: "" | ||
|
||
stages: | ||
- stage: DeployDev | ||
condition: and(succeeded(), eq(variables['Build.SourceBranch'], 'refs/heads/master'), ne(variables['Build.Reason'], 'PullRequest')) | ||
displayName: Deploy to Test Site | ||
jobs: | ||
- deployment: DeployDev | ||
displayName: Deploy to Test Site | ||
variables: | ||
- group: Netlify | ||
environment: Netlify Test | ||
strategy: | ||
runOnce: | ||
deploy: | ||
steps: | ||
- template: ../steps/deploy-steps.yaml | ||
parameters: | ||
workingDirectory: ${{ parameters.workingDirectory }} | ||
siteId: b32d496d-3b42-4727-bd8c-5798a32b1ad4 | ||
siteName: test | ||
context: production |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
parameters: | ||
- name: workingDirectory | ||
type: string | ||
default: "" | ||
- name: siteId | ||
type: string | ||
default: "" | ||
- name: siteName | ||
type: string | ||
default: "" | ||
- name: context | ||
type: string | ||
default: "" | ||
|
||
steps: | ||
- download: none | ||
- checkout: self | ||
- template: ../tasks/install-node-task.yaml | ||
parameters: | ||
projectDirectory: ${{ parameters.workingDirectory }} | ||
- template: ../tasks/pwsh-task.yaml | ||
parameters: | ||
projectDirectory: ${{ parameters.workingDirectory }} | ||
scriptFile: initialize.ps1 | ||
- template: ../tasks/pwsh-task.yaml | ||
parameters: | ||
projectDirectory: ${{ parameters.workingDirectory }} | ||
scriptFile: build.ps1 | ||
arguments: -SiteName "${{ parameters.siteName }}" -Context "${{ parameters.context }}" | ||
env: | ||
NETLIFY_AUTH_TOKEN: $(NETLIFY_AUTH_TOKEN) | ||
NETLIFY_SITE_ID: ${{ parameters.siteId }} | ||
- template: ../tasks/pwsh-task.yaml | ||
parameters: | ||
projectDirectory: ${{ parameters.workingDirectory }} | ||
scriptFile: deploy.ps1 | ||
arguments: -Context "${{ parameters.context }}" | ||
env: | ||
NETLIFY_AUTH_TOKEN: $(NETLIFY_AUTH_TOKEN) | ||
NETLIFY_SITE_ID: ${{ parameters.siteId }} |
40 changes: 40 additions & 0 deletions
40
packages/web-app/.azure-pipelines/tasks/install-node-task.yaml
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
parameters: | ||
- name: projectDirectory | ||
type: string | ||
default: "" | ||
- name: authenticateNpm | ||
type: boolean | ||
default: true | ||
- name: authenticateYarn | ||
type: boolean | ||
default: true | ||
|
||
steps: | ||
- pwsh: | | ||
$version = (Get-Content -Path .nvmrc -Raw -Encoding utf8).Trim() | ||
Write-Host -Object "##vso[task.setvariable variable=Argument.NodeVersion;isreadonly=true;]${version}" | ||
displayName: Get Node.js version | ||
workingDirectory: ${{ parameters.projectDirectory }} | ||
- task: NodeTool@0 | ||
displayName: Install Node.js | ||
inputs: | ||
versionSpec: "$(Argument.NodeVersion)" | ||
- ${{ if eq(parameters.authenticateNpm, true) }}: | ||
- task: npmAuthenticate@0 | ||
displayName: Login to Azure Artifacts (npm) | ||
inputs: | ||
workingFile: ${{ parameters.projectDirectory }}/.npmrc | ||
- ${{ if eq(parameters.authenticateYarn, true) }}: | ||
- pwsh: | | ||
$yarnConfig = Get-Content -Path .yarnrc.yml -Encoding utf8 | ||
$yarnRegistryLine = $yarnConfig | Select-String -Pattern 'npmRegistryServer:' -SimpleMatch -CaseSensitive | ||
if ($null -ne $yarnRegistryLine) { | ||
$yarnConfig[0..$($yarnRegistryLine[0].LineNumber - 1)], ` | ||
' npmAlwaysAuth: true', " npmAuthIdent: `"ApiKey:$($Env:SYSTEM_ACCESSTOKEN)`"", ` | ||
$yarnConfig[$($yarnRegistryLine[0].LineNumber)..$($yarnConfig.Count - 1)] | ` | ||
Set-Content -Path .yarnrc.yml -Encoding utf8 | ||
} | ||
displayName: Login to Azure Artifacts (Yarn) | ||
workingDirectory: ${{ parameters.projectDirectory }} | ||
env: | ||
SYSTEM_ACCESSTOKEN: $(System.AccessToken) |
Oops, something went wrong.