Oryx-SDK-Runtime-Automation-Template #148
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
name: Oryx-SDK-Runtime-Automation-Template | |
on: | |
workflow_call: | |
inputs: | |
platformName: | |
required: true | |
type: string | |
workflow_dispatch: | |
inputs: | |
platformName: | |
required: true | |
type: string | |
default: 'dotnet' | |
description: 'The platform name should be all lowercase' | |
env: | |
MAX_RETRIES: 15 | |
TIMEOUT_SECONDS: 900 | |
ORYX_SDK_STORAGE_BASE_URL: ${{ vars.ORYX_SDK_STORAGE_BASE_URL }} | |
DOTNET_MIN_RELEASE_VERSION: ${{ vars.DOTNET_MIN_RELEASE_VERSION }} | |
DOTNET_MAX_RELEASE_VERSION: ${{ vars.DOTNET_MAX_RELEASE_VERSION }} | |
DOTNET_BLOCKED_VERSIONS_ARRAY: ${{ vars.DOTNET_BLOCKED_VERSIONS_ARRAY }} | |
PYTHON_MIN_RELEASE_VERSION: ${{ vars.PYTHON_MIN_RELEASE_VERSION }} | |
PYTHON_MAX_RELEASE_VERSION: ${{ vars.PYTHON_MAX_RELEASE_VERSION }} | |
PYTHON_BLOCKED_VERSIONS_ARRAY: ${{ vars.PYTHON_BLOCKED_VERSIONS_ARRAY }} | |
ORYX_SDK_STORAGE_ACCOUNT_ACCESS_TOKEN: ${{ secrets.ORYX_SDK_STORAGE_ACCOUNT_ACCESS_TOKEN }} | |
jobs: | |
build: | |
runs-on: ubuntu-latest | |
permissions: | |
actions: write | |
contents: write | |
pull-requests: write | |
steps: | |
- uses: actions/checkout@v3 | |
- name: Set Required Environment Variables | |
run: | | |
set -x | |
releaseDate=`date +%F` | |
echo "RELEASE_DATE=${releaseDate}" >> $GITHUB_ENV | |
declare -A platformNamesAsInBasePipeline | |
platformNamesAsInBasePipeline=( ["dotnet"]="DotNetCore" ["python"]="Python" ) | |
echo "PLATFORM_NAME_CAMEL_CASE=${platformNamesAsInBasePipeline[${{ inputs.platformName }}]}" >> $GITHUB_ENV | |
- name: Run SDK Automation | |
run: | | |
dotnet run --project build/tools/Automation/Automation.csproj ${{ inputs.platformName }} ${{ github.workspace }} | |
./build/generateConstants.sh | |
- name: Commit new ${{ env.PLATFORM_NAME_CAMEL_CASE }} SDK versions | |
run: | | |
set -x | |
git config user.name 'Oryx Team' | |
git config user.email '[email protected]' | |
git status | |
git add -A | |
# Skip further checks if the event is not a manual trigger. | |
if [ "${{ github.event_name }}" == "workflow_dispatch" ]; then | |
echo "Forcing the workflow step because the event was manually ran." | |
cancelWorkflow=0 | |
# Check there are no updates in build/constants.yaml | |
elif git diff --quiet --exit-code -- build/constants.yaml; then | |
echo "No new ${{ inputs.platformName }} SDK versions detected. Canceling workflow..." | |
cancelWorkflow=1 | |
else | |
git commit -m "Add new ${{ inputs.platformName }} SDK versions" && true | |
gitCommitExitCode=${PIPESTATUS[0]} | |
if [[ $gitCommitExitCode = 0 ]]; then | |
cancelWorkflow=0 | |
else | |
echo "Error committing changes. Canceling workflow..." | |
cancelWorkflow=1 | |
fi | |
fi | |
echo "CANCEL_WORKFLOW=${cancelWorkflow}" >> $GITHUB_ENV | |
# 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 | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 }} | |
token: ${{ secrets.PAT_TEMP }} | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
name: Install jq | |
run: | | |
sudo apt-get update | |
sudo apt-get install jq -y | |
jq --version | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
name: Check Dev SDK Pipeline Ran Successfully | |
run: | | |
pipelineInvocationId=$( cat /tmp/sdkPipelineTriggerResponse.json | jq ".id" ) | |
${{ github.workspace }}/build/tools/Automation/checkPipelineStatus.sh $pipelineInvocationId | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 }}-versions-${{ env.RELEASE_DATE }} > /tmp/runtimePipelineTriggerResponse.json | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
name: Check Runtime Pipeline Ran Successfully | |
run: | | |
pipelineInvocationId=$( cat /tmp/runtimePipelineTriggerResponse.json | jq ".id" ) | |
${{ github.workspace }}/build/tools/Automation/checkPipelineStatus.sh $pipelineInvocationId | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
name: Update Runtime Build Number | |
run: | | |
set -x | |
buildNumber=$(cat /tmp/status.json | jq ".buildNumber" | tr -d '"') | |
platform=${{ inputs.platformName }} | |
runtimeName=$platform-versions | |
if [[ "$platform" == "dotnet" ]]; then | |
platform="dot-net-core" | |
runtimeName=dot-net-core-run-time-versions | |
fi | |
yq -i "(.[] | select(.name==\"$runtimeName\") | .constants.$platform-runtime-base-tag) = $buildNumber" build/constants.yaml | |
# run automation again to preserve constants.yaml YamlDotNet indentation | |
# since YamlDoNet and yq do not share indentation spacing | |
dotnet run --project build/tools/Automation/Automation.csproj ${{ inputs.platformName }} ${{ github.workspace }} | |
./build/generateConstants.sh | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
name: Commit and Push | |
run: | | |
git status | |
git config user.name 'William Hernandez' | |
git config user.email '[email protected]' | |
git add -A | |
git commit -m "Add runtime build number" | |
git push origin automation/add-new-${{ inputs.platformName }}-versions-${{ env.RELEASE_DATE }} | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 }} | |
- if: ${{ env.CANCEL_WORKFLOW == 0 }} | |
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 }} |