ci: untested cut at updating CI for Cranko

This commit is contained in:
Peter Williams 2020-10-12 12:51:15 -04:00
Родитель 9be33c07a2
Коммит 635a721c6a
5 изменённых файлов: 301 добавлений и 95 удалений

Просмотреть файл

@ -1,95 +0,0 @@
# Azure Pipelines: build the Webclient
trigger:
# Note that this pipeline will still run on pull requests. However,
# operations that require service connections -- namely the AzureFileCopy --
# will be skipped on PR builds, so randos can't just update our website by
# submitting a PR.
branches:
include:
- master
- "refs/tags/v*"
pool:
# We need to run on Windows to take advantage of the AzureFileCopy@3 task.
vmImage: 'windows-latest'
steps:
- powershell: |
$branch = "$(Build.SourceBranch)"
if($branch.StartsWith("refs/tags/v")) {
$version = $branch.Substring(11)
Write-Host "##vso[task.setvariable variable=pub_prefix;]webclient"
Write-Host "##vso[task.setvariable variable=profile;]prod"
} else {
# Won't actually get published on PRs, etc.
Write-Host "##vso[task.setvariable variable=pub_prefix;]testing_webclient"
Write-Host "##vso[task.setvariable variable=profile;]testing"
}
displayName: Set deployment parameters
- task: Npm@1
displayName: NPM install
inputs:
command: 'install'
- task: Grunt@0
displayName: Build distribution directory with Grunt
inputs:
gruntFile: 'Gruntfile.js'
targets: 'dist-$(profile)'
- task: CopyFiles@2
displayName: Copy dist directory to artifact staging
inputs:
sourceFolder: '$(build.sourcesDirectory)/dist'
targetFolder: '$(build.artifactStagingDirectory)'
- task: PublishPipelineArtifact@1
displayName: Publish web deployment artifacts
inputs:
targetPath: '$(build.artifactStagingDirectory)'
publishLocation: 'pipeline'
artifactName: wwt-webclient-deployment
- task: AzureFileCopy@3
displayName: Publish artifacts to Azure Blob storage
inputs:
SourcePath: '$(build.artifactStagingDirectory)'
azureSubscription: 'aas@wwtadmindotnetfoundation'
Destination: 'AzureBlob'
storage: 'wwtwebstatic'
ContainerName: '$web'
blobPrefix: '$(pub_prefix)'
# For annoying reasons, we have to include a default.aspx file that does a
# JavaScript redirection. In order for that to work, we have to tell the web
# server to serve up the file with a non-default "text/html" Content-Type.
# This task does the setting. Note that the service principal associated with
# the azureSubscription account needs to be set up with the "Storage Blob Data
# Contribtor" role on the storage account in order for this to work.
- task: AzurePowerShell@4
displayName: Update Azure Blob storage content types
inputs:
azureSubscription: 'aas@wwtadmindotnetfoundation'
azurePowerShellVersion: 'LatestVersion'
scriptType: 'inlineScript'
inline: |
$ctxt = New-AzStorageContext -UseConnectedAccount -StorageAccountName "wwtwebstatic"
$blob = Get-AzStorageBlob -Context $ctxt -Container '$web' -Blob "$(pub_prefix)/default.aspx"
$blob.ICloudBlob.Properties.ContentType = "text/html"
$blob.ICloudBlob.SetProperties()
- task: AzurePowerShell@4
displayName: Purge CDN
inputs:
azureSubscription: 'aas@wwtadmindotnetfoundation'
azurePowerShellVersion: 'LatestVersion'
scriptType: 'inlineScript'
inline: |
Unpublish-AzCdnEndpointContent `
-ProfileName wwt-cdn-01 `
-ResourceGroupName wwt-web01 `
-EndpointName wwtweb-prod `
-PurgeContent '/$(pub_prefix)/*'

146
ci/azure-deployment.yml Normal file
Просмотреть файл

@ -0,0 +1,146 @@
# Copyright 2020 the .NET Foundation
# Licensed under the MIT License
parameters:
- name: isMainDev
type: boolean
default: false
- name: isRelease
type: boolean
default: false
jobs:
# Deployment jobs that might happen on updates to either `master` *or* `rc`.
# On updates to master, we deploy everything under the "latest" name. On
# updates to `rc`, we deploy some subset of the projects that can only be
# determined at runtime.
- job: deploy
pool:
vmImage: windows-latest
variables:
- group: Deployment Credentials
steps:
- template: azure-job-setup.yml
- bash: |
set -euo pipefail
if [[ ${isMainDev} == True ]] ; then
tag=testing_webclient
elif cranko show if-released --exit-code @wwtelescope/webclient ; then
tag=webclient
else
# This should never happen in the current setup, but doesn't hurt
# to future-proof.
tag=skip
fi
echo "webclient deployment tag: $isMainDev, $isRelease => $tag"
echo "##vso[task.setvariable variable=WEBCLIENT_DEPLOYMENT_TAG;]$tag"
displayName: Determine deployment tag
env:
isMainDev: ${{ parameters.isMainDev }}
isRelease: ${{ parameters.isRelease }}
- task: AzureFileCopy@3
condition: and(succeeded(), ne(variables['WEBCLIENT_DEPLOYMENT_TAG'], 'skip'))
displayName: Deploy webclient artifacts
inputs:
SourcePath: '$(Pipeline.Workspace)/webclient-dist'
azureSubscription: 'aas@wwtadmindotnetfoundation'
Destination: 'AzureBlob'
storage: 'wwtwebstatic'
ContainerName: '$web'
blobPrefix: '$(WEBCLIENT_DEPLOYMENT_TAG)'
# For annoying reasons, we have to include a default.aspx file that does a
# JavaScript redirection. In order for that to work, we have to tell the web
# server to serve up the file with a non-default "text/html" Content-Type.
# This task does the setting. Note that the service principal associated with
# the azureSubscription account needs to be set up with the "Storage Blob Data
# Contribtor" role on the storage account in order for this to work.
- task: AzurePowerShell@4
condition: and(succeeded(), ne(variables['WEBCLIENT_DEPLOYMENT_TAG'], 'skip'))
displayName: Update Azure Blob storage content types
inputs:
azureSubscription: 'aas@wwtadmindotnetfoundation'
azurePowerShellVersion: 'LatestVersion'
scriptType: 'inlineScript'
inline: |
$ctxt = New-AzStorageContext -UseConnectedAccount -StorageAccountName "wwtwebstatic"
$blob = Get-AzStorageBlob -Context $ctxt -Container '$web' -Blob "$(WEBCLIENT_DEPLOYMENT_TAG)/default.aspx"
$blob.ICloudBlob.Properties.ContentType = "text/html"
$blob.ICloudBlob.SetProperties()
- task: AzurePowerShell@4
condition: and(succeeded(), ne(variables['WEBCLIENT_DEPLOYMENT_TAG'], 'skip'))
displayName: CDN purge - webclient artifacts
inputs:
azureSubscription: 'aas@wwtadmindotnetfoundation'
azurePowerShellVersion: 'LatestVersion'
scriptType: 'inlineScript'
inline: |
Unpublish-AzCdnEndpointContent `
-ProfileName wwt-cdn-01 `
-ResourceGroupName wwt-web01 `
-EndpointName wwtweb-prod `
-PurgeContent '/$(WEBCLIENT_DEPLOYMENT_TAG)/*'
# Deployment jobs that should only happen on updates to `rc`, i.e.
# primary releases.
- ${{ if parameters.isRelease }}:
- job: branch_and_tag
pool:
vmImage: ubuntu-20.04
variables:
- group: Deployment Credentials
steps:
- template: azure-job-setup.yml
parameters:
setupGit: true
- bash: |
set -xeou pipefail
cranko release-workflow tag
git push --tags origin release:release
displayName: Tag and push
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
- job: github_releases
dependsOn: branch_and_tag # otherwise, GitHub creates the tags itself!
pool:
vmImage: ubuntu-20.04
variables:
- group: Deployment Credentials
steps:
- template: azure-job-setup.yml
parameters:
setupGit: true
- bash: |
set -xeou pipefail
cranko github create-releases
displayName: Create GitHub releases
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
- job: npm_publish
pool:
vmImage: ubuntu-20.04
variables:
- group: Deployment Credentials
steps:
- template: azure-job-setup.yml
parameters:
setupBuild: true
setupNpm: true
- bash: npm run build
displayName: NPM build
- bash: |
set -xeou pipefail
cranko npm foreach-released npm publish
displayName: Publish to NPM
- bash: shred ~/.npmrc
displayName: Clean up credentials

75
ci/azure-job-setup.yml Normal file
Просмотреть файл

@ -0,0 +1,75 @@
# Copyright 2020 the .NET Foundation
# Licensed under the MIT License
# Setup steps for the deployment processes.
parameters:
- name: setupGit
type: boolean
default: false
- name: setupNpm
type: boolean
default: false
steps:
- download: current
- checkout: self
submodules: recursive
- bash: |
set -euo pipefail
d="$(mktemp -d /tmp/cranko.XXXXXX)"
cd "$d"
curl --proto '=https' --tlsv1.2 -sSf https://pkgw.github.io/cranko/fetch-latest.sh | sh
echo "##vso[task.prependpath]$d"
displayName: Install latest Cranko (not Windows)
condition: and(succeeded(), ne(variables['Agent.OS'], 'Windows_NT'))
- pwsh: |
$d = Join-Path $Env:Temp cranko-$(New-Guid)
[void][System.IO.Directory]::CreateDirectory($d)
cd $d
[System.Net.ServicePointManager]::SecurityProtocol = [System.Net.ServicePointManager]::SecurityProtocol -bor 3072
iex ((New-Object System.Net.WebClient).DownloadString('https://pkgw.github.io/cranko/fetch-latest.ps1'))
echo "##vso[task.prependpath]$d"
displayName: Install latest Cranko (Windows)
condition: and(succeeded(), eq(variables['Agent.OS'], 'Windows_NT'))
# work around https://github.com/microsoft/azure-pipelines-tasks/issues/10653
# also note that `set -x` messes up `task.setvariable`
- bash: |
set -euo pipefail
PIPELINE_WORKSPACE="$(Pipeline.Workspace)"
ARTIFACT_STAGING="$(Build.ArtifactStagingDirectory)"
if [[ $AGENT_OS == Windows_NT ]] ; then
PIPELINE_WORKSPACE=$(echo "$PIPELINE_WORKSPACE" | sed -e 's|\\|\/|g' -e 's|^\([A-Za-z]\)\:/\(.*\)|/\L\1\E/\2|')
ARTIFACT_STAGING=$(echo "$ARTIFACT_STAGING" | sed -e 's|\\|\/|g' -e 's|^\([A-Za-z]\)\:/\(.*\)|/\L\1\E/\2|')
fi
echo "##vso[task.setvariable variable=PIPELINE_WORKSPACE;]$PIPELINE_WORKSPACE"
echo "##vso[task.setvariable variable=ARTIFACT_STAGING;]$ARTIFACT_STAGING"
displayName: Ensure bash-friendly variable names
- bash: |
set -xeuo pipefail
git switch -c release
git pull --ff-only $PIPELINE_WORKSPACE/git-release/release.bundle
displayName: Restore release commit
- ${{ if parameters.setupGit }}:
- bash: |
cranko github install-credential-helper
displayName: Set up Git pushes
env:
GITHUB_TOKEN: $(GITHUB_TOKEN)
- ${{ if parameters.setupNpm }}:
- bash: |
cranko npm install-token
displayName: Set up NPM authentication
env:
NPM_TOKEN: $(NPM_TOKEN)

59
ci/azure-main-build.yml Normal file
Просмотреть файл

@ -0,0 +1,59 @@
# Copyright 2020 the .NET Foundation
# Licensed under the MIT License
jobs:
- job: build_linux
pool:
vmImage: ubuntu-20.04
# Cranko: make and publish release commit
steps:
- bash: |
set -euo pipefail
d="$(mktemp -d /tmp/cranko.XXXXXX)"
cd "$d"
curl --proto '=https' --tlsv1.2 -sSf https://pkgw.github.io/cranko/fetch-latest.sh | sh
echo "##vso[task.prependpath]$d"
displayName: Install latest Cranko (not Windows)
condition: and(succeeded(), ne(variables['Agent.OS'], 'Windows_NT'))
- bash: |
set -xeuo pipefail
cranko release-workflow apply-versions
git add .
cranko release-workflow commit
git show HEAD
displayName: Make release commit
- bash: |
artifact_dir="$(Build.ArtifactStagingDirectory)/git-release"
mkdir -p "$artifact_dir"
git bundle create "$artifact_dir/release.bundle" origin/master..HEAD
displayName: Bundle release commit
- task: PublishPipelineArtifact@1
displayName: Publish release git bundle artifact
inputs:
targetPath: '$(Build.ArtifactStagingDirectory)/git-release'
artifactName: git-release
# Main build:
- task: Npm@1
displayName: NPM install
inputs:
command: 'install'
- task: Grunt@0
displayName: Build distribution directory with Grunt
inputs:
gruntFile: 'Gruntfile.js'
targets: 'dist-$(profile)'
- task: PublishPipelineArtifact@1
displayName: Publish web deployment artifacts
inputs:
targetPath: 'dist'
publishLocation: 'pipeline'
artifactName: webclient-dist

21
ci/azure-pipelines.yml Normal file
Просмотреть файл

@ -0,0 +1,21 @@
# Copyright 2020 the .NET Foundation
# Licensed under the MIT License
trigger:
branches:
include:
- master
- rc
stages:
- stage: MainBuild
jobs:
- template: azure-main-build.yml
- stage: Deploy
condition: and(succeeded('MainBuild'), ne(variables['build.reason'], 'PullRequest'))
jobs:
- template: azure-deployment.yml
parameters:
isMainDev: ${{ ne(variables['Build.SourceBranchName'], 'rc') }}
isRelease: ${{ eq(variables['Build.SourceBranchName'], 'rc') }}