Williamhe/1684436 add dotnet runtime automation (#1766)

* Update azure pipeline trigger

* Add code to trigger and retry base image pipeline

* Add maxRetries and maxSeconds ENV option

* Add sudo to command

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Remove sudo

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Update pipeline trigger

* Add ENVVARS to workflow

* Add ENVVARS to workflow

* Update pipeline status check

* Update pipeline status check

* Update pipeline status check

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry

* Update retry for checking pipeline status

* Update retry for checking pipeline status

* Update retry for checking pipeline status

* Update permissions

* Remove bash shebang

* Update invocation

* Add shebang back

* Update retry

* Update retry

* Update filename

* Update logging

* Update logging

* Update logging

* Update to get buildNumber

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update command invocation

* Update constants path

* Update constants path

* Update the automation workflow file

* Update the automation workflow file

* Update the automation workflow file

* Add re-usable workflow

* Update trigger

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Update workflow reference

* Add runtime pipeline trigger

* Minor upate

* Update to comment out sdk pipeline trigger

* Update branch name for testing

* Updates for testing

* Updates for testing

* Updates for testing

* Update changing branch convention

* Update changing branch convention

* Update with a force change

* Update with a force change

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update for testing

* Update pull request invocation

* Update pull request invocation

* Update pull request invocation

* Update to fetch origin main

* Update to fetch origin main

* Update to fetch origin main

* Update to fetch origin main

* Update pull request logic

* Update pull request logic

* Update pull request logic

* Update pull request logic

* Update for testing validation and nightly run

* Update for testing validation and nightly run

* Add script description

* Add camel case platform name

* Update to use platform name

* Update to use platform name

* Update base branch

* Update for testing

* Update for testing

* Update

* Update cron

* Update cron

* Update git add

* Update git add

* Update jq order

* Update jq order

* Rename files

* Remove white space

* Add manual input to caller workflow

* Revert retry for images

* Remove auto-trigger

* Update platformCamelCase variable

* Remove setting git user

* Update comment

* Update timeout

* Update variable name

* Add temporary auto-trigger

* Remove camel case vars

* Update username to Oryx

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Update with minor changes

* Remove test code

* Update var name

* Remove extra trigger
This commit is contained in:
william-msft 2022-12-30 15:15:12 -08:00 коммит произвёл GitHub
Родитель bfe4c451e7
Коммит df89ea1db9
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
4 изменённых файлов: 209 добавлений и 72 удалений

143
.github/workflows/automationTemplate.yaml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,143 @@
name: Oryx-SDK-Runtime-Automation-Template
on:
workflow_call:
inputs:
releaseDate:
required: false
type: string
platformName:
required: true
type: string
workflow_dispatch:
inputs:
releaseDate:
description: 'The date to check for new releases. Format: yyyy-mm-dd'
required: false
type: string
platformName:
required: true
type: string
default: 'dotnet'
description: 'The platform name should be all lowercase'
env:
MAX_RETRIES: 10
TIMEOUT_SECONDS: 900
jobs:
build:
runs-on: ubuntu-20.04
steps:
- uses: actions/checkout@v3
- name: Set Required Environment Variables
run: |
set -x
releaseDate=${{ inputs.releaseDate }}
if ! [[ "${releaseDate}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]
then
echo "release date is empty or invalid $releaseDate."
echo "Expecting date format yyyy-mm-dd"
releaseDate=`date +%F`
echo "Defaulting to todays date ${releaseDate}"
fi
echo "RELEASE_DATE=${releaseDate}" >> $GITHUB_ENV
declare -A platformNamesAsInBasePipeline
platformNamesAsInBasePipeline=( ["dotnet"]="DotNetCore" )
echo "PLATFORM_NAME_CAMEL_CASE=${platformNamesAsInBasePipeline[${{ inputs.platformName }}]}" >> $GITHUB_ENV
- name: Run SDK Automation
run: dotnet run --project build/tools/Automation/Automation.csproj ${RELEASE_DATE} ${{ github.workspace }}
- name: Check if any git changes exist.
run: |
changes=$(git diff-index --name-only HEAD --)
echo ${changes}
if [ -z "${changes}" ]; then
echo "No git changes to commit. Cancelling workflow..."
exit 1
fi
git status
- name: Commit new ${{ env.PLATFORM_NAME_CAMEL_CASE }} SDK versions
run: |
git status
git config user.name 'Oryx Team'
git config user.email 'oryx@microsoft.com'
git add -A
git commit -m "Add new SDK versions"
# TODO: paramterize branch/title platfrom name
# and list of versions to the PR decription
#
# branch name example: automation/add-new-{PlatfornName}-sdks
# TODO: remove peter-evans/create-pull-request and use github.rest
# Example: https://stackoverflow.com/questions/68057744/create-pull-request-with-github-action/71224444#71224444
- name: Create Pull Request
uses: peter-evans/create-pull-request@171dd555b9ab6b18fa02519fdfacbb8bf671e1b4 # locking to a commit version for now
with:
branch: automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }}
title: New ${{ env.PLATFORM_NAME_CAMEL_CASE }} Sdks ${{ env.RELEASE_DATE }}
- name: Install jq
run: |
sudo apt-get update
sudo apt-get install jq -y
jq --version
- name: Trigger Dev SDK Pipeline
run: |
echo "${{ secrets.AZURE_DEVOPS_TOKEN }}" | az devops login --organization https://devdiv.visualstudio.com/
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-PlatformBinary-${{ env.PLATFORM_NAME_CAMEL_CASE }} --branch automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }} > /tmp/sdkPipelineTriggerResponse.json
- name: Check Dev SDK Pipeline Ran Successfully
run: |
pipelineInvocationId=$( cat /tmp/sdkPipelineTriggerResponse.json | jq ".id" )
${{ github.workspace }}/build/tools/Automation/checkPipelineStatus.sh $pipelineInvocationId
- name: Trigger Runtime Pipeline
run: |
echo "${{ secrets.AZURE_DEVOPS_TOKEN }}" | az devops login --organization https://devdiv.visualstudio.com/
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-BaseImages-${{ env.PLATFORM_NAME_CAMEL_CASE }} --branch automation/add-new-${{ inputs.platformName }}-release-${{ env.RELEASE_DATE }} > /tmp/runtimePipelineTriggerResponse.json
- name: Check Runtime Pipeline Ran Successfully
run: |
pipelineInvocationId=$( cat /tmp/runtimePipelineTriggerResponse.json | jq ".id" )
${{ github.workspace }}/build/tools/Automation/checkPipelineStatus.sh $pipelineInvocationId
- name: Install yq
run: sudo wget https://github.com/mikefarah/yq/releases/latest/download/yq_linux_amd64 -O /usr/bin/yq && sudo chmod +x /usr/bin/yq
- name: Update Runtime Build Number
run: |
yq --version
buildNumber=$(cat /tmp/status.json | jq ".buildNumber" | tr -d '"')
echo "buildNumber: $buildNumber"
platform=${{ inputs.platformName }}
[[ "$platform" == "dotnet" ]] && platform="dot-net-core" || platform=$platform
echo "platform: $platform"
yq -i "(.[] | select(.name==\"$platform-run-time-versions\") | .constants.$platform-runtime-base-tag) = $buildNumber" build/constants.yaml
./build/generateConstants.sh
- name: Commit and Push
run: |
git status
git config user.name 'William Hernandez'
git config user.email 'williamhe@microsoft.com'
git add -A
git commit -m "Add runtime build number"
git push origin automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }}
- name: Trigger Validation Pipeline
run: |
echo "${{ secrets.AZURE_DEVOPS_TOKEN }}" | az devops login --organization https://devdiv.visualstudio.com/
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-Validation --branch automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }}
- name: Trigger Nightly Pipeline
run: |
echo "${{ secrets.AZURE_DEVOPS_TOKEN }}" | az devops login --organization https://devdiv.visualstudio.com/
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-Nightly --branch automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }}

24
.github/workflows/automationTrigger.yaml поставляемый Normal file
Просмотреть файл

@ -0,0 +1,24 @@
name: Oryx-SDK-Runtime-Automation-Trigger
on:
# runs on 12:55 (5:55AM PST) & 23:55 UTC
schedule:
- cron: '55 12,23 * * *'
workflow_call:
inputs:
releaseDate:
required: false
type: string
platformName:
required: true
type: string
jobs:
SdkRuntimeAutomation:
strategy:
matrix:
platformName: [dotnet]
uses: ./.github/workflows/automationTemplate.yaml
with:
platformName: ${{ matrix.platformName }}
secrets: inherit

72
.github/workflows/main.yaml поставляемый
Просмотреть файл

@ -1,72 +0,0 @@
name: Oryx-SDK-Automation
on:
# runs on 12:55 (5:55AM PST) & 23:55 UTC
schedule:
- cron: '55 12,23 * * *'
workflow_dispatch:
inputs:
releaseDate:
description: 'The date to check for new releases. Format: yyyy-mm-dd'
required: true
type: string
jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: Run SDK automation
run: |
releaseDate=${{ inputs.releaseDate }}
if ! [[ "${releaseDate}" =~ ^[0-9]{4}-[0-9]{2}-[0-9]{2}$ ]]
then
echo "release date is invalid $releaseDate."
echo "Expecting date format yyyy-mm-dd"
releaseDate=`date +%F`
echo "Defaulting to todays date ${releaseDate}"
fi
echo "releaseDate=${releaseDate}" >> $GITHUB_ENV
dotnet run --project build/tools/Automation/Automation.csproj ${releaseDate} ${{ github.workspace }}
- name: Check if any git changes exist.
run: |
changes=$(git diff-index --name-only HEAD --)
echo ${changes}
if [ -z "${changes}" ]; then
echo "No git changes to commit. Cancelling workflow..."
exit 1
fi
- name: Run Generate Constants
run: ./build/generateConstants.sh
# TODO: replace William with new bot GitHub Account credentials
- name: Create commits
run: |
git config user.name 'William Hernandez'
git config user.email 'williamhe@microsoft.com'
git add -A
git commit -m "Add new SDK versions"
# TODO: paramterize branch/title platfrom name
# and list of versions to the PR decription
#
# branch name example: automation/add-new-{PlatfornName}-sdks
# TODO: remove peter-evans/create-pull-request and use github.rest
# Example: https://stackoverflow.com/questions/68057744/create-pull-request-with-github-action/71224444#71224444
- name: Create Pull Request
uses: peter-evans/create-pull-request@171dd555b9ab6b18fa02519fdfacbb8bf671e1b4 # locking to a commit version for now
with:
branch: automation/add-new-dotnet-release-${{ env.releaseDate }}
title: New DotNetCore Sdks ${{ env.releaseDate }}
- name: Run Azure Pipeline
run: |
echo "${{ secrets.AZURE_DEVOPS_TOKEN }}" | az devops login --organization https://devdiv.visualstudio.com/
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-PlatformBinary-DotNetCore --branch automation/add-new-dotnet-release-${{ env.releaseDate }}
az pipelines run --organization https://devdiv.visualstudio.com/ --project DevDiv --name Oryx-Validation --branch automation/add-new-dotnet-release-${{ env.releaseDate }}

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

@ -0,0 +1,42 @@
# --------------------------------------------------------------------------------------------
# Copyright (c) Microsoft Corporation. All rights reserved.
# Licensed under the MIT license.
# --------------------------------------------------------------------------------------------
# This script will check the pipeline status' result
# for a given pipeline invocation id.
# A status.json file contains the meta data for a pipeline invocation id
# of the point in time it was called, until the result has 'succeeded'.
# The 'buildNumber' field of status.json is used later in the workflow
# to update constants.yaml runtime image tag.
pipelineInvocationId=$1
maxRetries=10
if [[ -n "${MAX_RETRIES}" ]]; then
maxRetries=${MAX_RETRIES}
fi
retryDelaySeconds=900
if [[ -n "${TIMEOUT_SECONDS}" ]]; then
retryDelaySeconds=${TIMEOUT_SECONDS}
fi
retryCount=0
while [ "$retryCount" -le "$maxRetries" ]
do
echo "retry $retryCount"
# store response in status.json for later use
az pipelines runs show --id ${pipelineInvocationId} --organization https://devdiv.visualstudio.com/ --project DevDiv > /tmp/status.json
result=$( cat /tmp/status.json | jq ".result" | tr -d '"' )
echo "pipeline ${pipelineInvocationId} invocation result: $result"
if [[ "$result" == "succeeded" ]]; then
exit 0
elif [[ "$result" != "null" ]]; then
exit 1
fi
echo "retrying in $retryDelaySeconds seconds..."
retryCount=$((retryCount+1))
sleep ${retryDelaySeconds}
done
echo "The pipeline invocation has not succeeded within the allocated retries."
exit 1