Create release #23
This file contains hidden or 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: Create release | |
| on: | |
| workflow_dispatch: | |
| inputs: | |
| code_editor_version: | |
| description: 'Code Editor version' | |
| required: true | |
| type: string | |
| sagemaker_version: | |
| description: 'SageMaker Code Editor version' | |
| required: true | |
| type: string | |
| jobs: | |
| release: | |
| runs-on: ubuntu-latest | |
| permissions: | |
| contents: write # Required for creating releases | |
| env: | |
| CODE_EDITOR_VERSION: ${{ github.event.inputs.code_editor_version }} | |
| SAGEMAKER_VERSION: ${{ github.event.inputs.sagemaker_version }} | |
| SAGEMAKER_ARTIFACT_PREFIX: "code-editor-sagemaker-server" | |
| GH_TOKEN: ${{ github.token }} | |
| steps: | |
| - name: Checkout code | |
| uses: actions/checkout@v4 | |
| with: | |
| fetch-depth: 0 | |
| - name: Validate versions and create tag | |
| run: | | |
| if ! echo "$CODE_EDITOR_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+(-rc\.[0-9]+)?$'; then | |
| echo "Code Editor version $CODE_EDITOR_VERSION does not follow semantic version pattern (x.y.z) or x.y.z-rc.N. Skipping release." | |
| exit 1 | |
| fi | |
| echo "Code Editor version $CODE_EDITOR_VERSION is valid" | |
| echo "SageMaker Code Editor version $SAGEMAKER_VERSION will be mapped" | |
| # Check if tag already exists | |
| if git rev-parse "$CODE_EDITOR_VERSION" >/dev/null 2>&1; then | |
| echo "Tag $CODE_EDITOR_VERSION already exists" | |
| else | |
| echo "Creating tag $CODE_EDITOR_VERSION on current commit" | |
| git tag "$CODE_EDITOR_VERSION" | |
| git push origin "$CODE_EDITOR_VERSION" | |
| fi | |
| # Get commit SHA from tag and export it | |
| TAG_COMMIT_SHA=$(git rev-parse "$CODE_EDITOR_VERSION") | |
| echo "COMMIT_SHA=$TAG_COMMIT_SHA" >> $GITHUB_ENV | |
| echo "Tag $CODE_EDITOR_VERSION points to commit $TAG_COMMIT_SHA" | |
| # Verify tag is on correct branch | |
| MAJOR_MINOR=$(echo "$CODE_EDITOR_VERSION" | cut -d'.' -f1,2) | |
| if ! git branch --remote --contains "$CODE_EDITOR_VERSION" | grep -q "origin/$MAJOR_MINOR"; then | |
| echo "Error: Tag $CODE_EDITOR_VERSION is not on branch $MAJOR_MINOR. Skipping release." | |
| exit 1 | |
| fi | |
| echo "Tag validation passed" | |
| - name: Download sagemaker artifacts by commit ID | |
| run: | | |
| gh run download --name "$COMMIT_SHA-code-editor-sagemaker-server-build" --name "$COMMIT_SHA-code-editor-sagemaker-server-src" | |
| - name: Check artifacts exist | |
| run: | | |
| ls -la | |
| FILES=( | |
| "$COMMIT_SHA-$SAGEMAKER_ARTIFACT_PREFIX-build/$SAGEMAKER_ARTIFACT_PREFIX-build.tar.gz" | |
| "$COMMIT_SHA-$SAGEMAKER_ARTIFACT_PREFIX-src/$SAGEMAKER_ARTIFACT_PREFIX-src.tar.gz" | |
| ) | |
| # Check build artifact exists | |
| for file in "${FILES[@]}"; do | |
| if [ ! -f "$file" ]; then | |
| echo "Error: $file not found for commit $COMMIT_SHA" | |
| exit 1 | |
| fi | |
| done | |
| - name: Update versions in artifacts | |
| run: | | |
| tar xzf "$COMMIT_SHA-$SAGEMAKER_ARTIFACT_PREFIX-src/$SAGEMAKER_ARTIFACT_PREFIX-src.tar.gz" | |
| cd code-editor-src | |
| CURRENT_CE_VERSION=$(jq -r '.codeEditorVersion' product.json) | |
| jq ".codeEditorVersion = \"$CODE_EDITOR_VERSION\" | .sagemakerCodeEditorVersion = \"$SAGEMAKER_VERSION\"" product.json > temp.json && mv temp.json product.json | |
| cd .. | |
| tar -czf "code-editor-sagemaker-src-$CODE_EDITOR_VERSION.tar.gz" code-editor-src/ | |
| rm -rf code-editor-src | |
| tar xzf "$COMMIT_SHA-$SAGEMAKER_ARTIFACT_PREFIX-build/$SAGEMAKER_ARTIFACT_PREFIX-build.tar.gz" | |
| cd vscode-reh-web-linux-x64 | |
| CURRENT_SM_VERSION=$(jq -r '.sagemakerCodeEditorVersion' product.json) | |
| jq ".codeEditorVersion = \"$CODE_EDITOR_VERSION\" | .sagemakerCodeEditorVersion = \"$SAGEMAKER_VERSION\"" product.json > temp.json && mv temp.json product.json | |
| FILES_TO_UPDATE=( | |
| "out/server-main.js" | |
| "out/vs/code/browser/workbench/workbench.js" | |
| "out/vs/platform/terminal/node/ptyHostMain.js" | |
| "out/vs/workbench/api/node/extensionHostProcess.js" | |
| ) | |
| for file in "${FILES_TO_UPDATE[@]}"; do | |
| sed -i "s/codeEditorVersion:\s*\"$CURRENT_CE_VERSION\"/codeEditorVersion:\"$CODE_EDITOR_VERSION\"/g" "$file" | |
| sed -i "s/sagemakerCodeEditorVersion:\s*\"$CURRENT_SM_VERSION\"/sagemakerCodeEditorVersion:\"$SAGEMAKER_VERSION\"/g" "$file" | |
| done | |
| cd .. | |
| tar -czf "code-editor-sagemaker-server-$CODE_EDITOR_VERSION.tar.gz" vscode-reh-web-linux-x64/ | |
| rm -rf vscode-reh-web-linux-x64 | |
| - name: Create GitHub release | |
| run: | | |
| # Check if this is a release candidate | |
| PRERELEASE_FLAG="" | |
| if echo "$CODE_EDITOR_VERSION" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+-rc\.[0-9]+$'; then | |
| PRERELEASE_FLAG="--prerelease" | |
| echo "Detected release candidate version, will mark as prerelease" | |
| fi | |
| # Check if release already exists. Needed when release created via new release in guthub ui | |
| if gh release view "$CODE_EDITOR_VERSION" > /dev/null 2>&1; then | |
| echo "Release for tag $CODE_EDITOR_VERSION already exists, uploading additional assets..." | |
| gh release upload "$CODE_EDITOR_VERSION" ./*.tar.gz --clobber | |
| else | |
| echo "Creating new release for tag $CODE_EDITOR_VERSION..." | |
| gh release create "$CODE_EDITOR_VERSION" ./*.tar.gz \ | |
| --title "Release $CODE_EDITOR_VERSION" \ | |
| --notes "Release $CODE_EDITOR_VERSION | |
| SageMaker Code Editor Version: $SAGEMAKER_VERSION" \ | |
| $PRERELEASE_FLAG | |
| fi | |
| handle-failures: | |
| name: Handle Failures | |
| runs-on: ubuntu-latest | |
| needs: release | |
| environment: release-workflow-env | |
| if: failure() | |
| permissions: | |
| id-token: write # Required for OIDC | |
| env: | |
| REPOSITORY: ${{ github.repository }} | |
| AWS_ROLE_TO_ASSUME: ${{ secrets.AWS_ROLE_TO_ASSUME }} | |
| steps: | |
| - name: Use role credentials for metrics | |
| id: aws-creds | |
| continue-on-error: ${{ env.REPOSITORY != 'aws/code-editor' }} | |
| uses: aws-actions/configure-aws-credentials@v4 | |
| with: | |
| role-to-assume: ${{ env.AWS_ROLE_TO_ASSUME }} | |
| role-duration-seconds: 900 | |
| aws-region: us-east-1 | |
| - name: Report failure | |
| if: steps.aws-creds.outcome == 'success' | |
| run: | | |
| aws cloudwatch put-metric-data \ | |
| --namespace "GitHub/Workflows" \ | |
| --metric-name "ExecutionsFailed" \ | |
| --dimensions "Repository=$REPOSITORY,Workflow=Release" \ | |
| --value 1 |