Skip to content

Create release

Create release #1

Workflow file for this run

name: Create release
on:
workflow_dispatch:
inputs:
version:
description: 'Release version'
required: true
type: string
push:
tags:
- '*'
jobs:
release:
runs-on: ubuntu-latest
environment: release-workflow-env
env:
GH_TOKEN: ${{ github.token }}
COMMIT_SHA: ${{ github.sha }}
REPOSITORY: ${{ github.repository }}
VERSION_NUM: ${{ github.event.inputs.version || github.ref_name }}
steps:
- name: Checkout code
uses: actions/checkout@v4
with:
fetch-depth: 0
- name: Validate tag format
run: |
if ! echo "$VERSION_NUM" | grep -qE '^[0-9]+\.[0-9]+\.[0-9]+$'; then
echo "Tag $VERSION_NUM does not follow semantic version pattern (x.y.z). Skipping release."
exit 78 # neutral exit code
fi
echo "Tag $VERSION_NUM follows valid semantic version pattern"
- name: Check if tag is from release branch
run: |
# Get the branch that contains this tag
BRANCHES=$(git branch -r --contains $COMMIT_SHA | grep -E 'origin/[0-9]+\.[0-9]+' || true)
if [ -z "$BRANCHES" ]; then
echo "Tag $VERSION_NUM is not from a *.* release branch. Skipping release."
exit 78 # neutral exit code
fi
echo "Tag is from a valid release branch: $BRANCHES"
- name: Download sagemaker artifacts by commit ID
run: |
# Find artifact by name using curl
ARTIFACT_ID=$(curl -L \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPOSITORY/actions/artifacts?name=$COMMIT_SHA-code-editor-sagemaker-server-build" \
| jq -r ".artifacts[0].id // empty")
if [ -n "$ARTIFACT_ID" ]; then
curl -L -H "Authorization: Bearer $GH_TOKEN" \
"https://api.github.com/repos/$REPOSITORY/actions/artifacts/$ARTIFACT_ID/zip" \
-o artifact.zip
unzip artifact.zip
else
echo "No artifact found matching pattern: $COMMIT_SHA-code-editor-sagemaker-server-build"
exit 1
fi
- name: Check artifacts exist and rename
run: |
ls -la
TARBALL=$(ls *.tar.gz | head -1)
if [ -z "$TARBALL" ]; then
echo "Error: No build artifacts found for commit $COMMIT_SHA"
exit 1
fi
mv "$TARBALL" "code-editor-sagemaker-${VERSION_NUM}.tar.gz"
echo "Renamed $TARBALL to code-editor-sagemaker-${VERSION_NUM}.tar.gz"
- name: Create GitHub release
run: |
# Create the release
RELEASE_RESPONSE=$(curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
"https://api.github.com/repos/$REPOSITORY/releases" \
-d "{
\"tag_name\": \"$VERSION_NUM\",
\"name\": \"Release $VERSION_NUM\",
\"draft\": false,
\"prerelease\": false
}")
UPLOAD_URL=$(echo "$RELEASE_RESPONSE" | jq -r '.upload_url' | sed 's/{?name,label}//')
RELEASE_ID=$(echo "$RELEASE_RESPONSE" | jq -r '.id')
echo UPLOAD_URL $UPLOAD_URL, RELEASE_ID $RELEASE_ID
# Upload each tar.gz file
for file in *.tar.gz; do
if [ -f "$file" ]; then
echo "Uploading $file..."
curl -L \
-X POST \
-H "Accept: application/vnd.github+json" \
-H "Authorization: Bearer $GH_TOKEN" \
-H "X-GitHub-Api-Version: 2022-11-28" \
-H "Content-Type: application/gzip" \
"${UPLOAD_URL}?name=${file}" \
--data-binary "@$file"
fi
done